Friday, 17 March 2017

How to pass email id as default parameter in routing

When you try to run http://localhost:2911/api/sample/sampleusename.com

this will not work just because We are passing .com in the parameter so we have to allow runAllManagedModulesForAllRequests="true" in web.config under System.WebServer - > Modules

Please see the image below.


Now it will work Happy Coding :)

Wednesday, 25 January 2017

Print 2D array in spiral C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DrawSpiral
{
    class Program
    {
        int[,] matrix; // Define 2d Array
        int arraySize; // Size of Array ex. 5 (5 coulmns and 5 rows)
        int currentNumber; // will use this to set value from 1 to number of digits required.

        static void Main(string[] args)
        {
            Console.WriteLine("Enter Array Size :");
            int arraysize = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("****************************************");
            Program s = new Program(arraysize);
            s.SetMatrixValues(arraysize, arraysize);
            Console.ReadLine();
        }

        public Program(int sizeOfArray)
        {
            this.arraySize = sizeOfArray;
            matrix = new int[sizeOfArray, sizeOfArray];
            currentNumber = 1;
        }

        /// <summary>
        /// It will set the matrix values starting from 1.
        /// </summary>
        /// <param name="row">Number of Rows in Array (ex. Size is 5 rows are 5 in array)</param>
        /// <param name="column">Number of Columns in Array (ex. Size is 5 columns are 5 in array)</param>
        public void SetMatrixValues(int row, int column)
        {
            int top = 0;
            int bottom = row - 1;
            int left = 0;
            int right = column - 1;
            int direction = 0;


            while (top <= bottom && left <= right)
            {
                if (direction == 0)
                {
                    for (int i = top; i <= right; i++)
                    {
                        matrix[top, i] = currentNumber;
                        currentNumber++;
                    }

                    top++;
                    direction = 1;
                }

                if (direction == 1)
                {
                    for (int i = top; i <= bottom; i++)
                    {
                        matrix[i, right] = currentNumber;
                        currentNumber++;
                    }

                    right--;
                    direction = 2;
                }

                if (direction == 2)
                {
                    for (int i = right; i >= left; i--)
                    {
                        matrix[bottom, i] = currentNumber;
                        currentNumber++;
                    }

                    bottom--;
                    direction = 3;
                }

                if (direction == 3)
                {
                    for (int i = bottom; i >= top; i--)
                    {
                        matrix[i, left] = currentNumber;
                        currentNumber++;
                    }

                    left++;
                }

                direction = (direction + 1) % 4;
            }

            DrawSpiral();
        }


        private void DrawSpiral()
        {
            for (int i = 0; i < arraySize; i++)
            {
                for (int j = 0; j < arraySize; j++)
                {
                    Console.Write(matrix[i, j]);
                    Console.Write("   ");
                }

                Console.WriteLine();
            }
        }
    }
}



Friday, 31 October 2014

Delete multiple rows using checkbox in with jquery mvc

$('#DeleteAllButtonId').click(function () {
    if ($('.chkNumber:checked').length) {
        var chkIds = "";
        $('.chkNumber:checkbox:checked').each(function () {
            chkIds += $(this).val()+",";
        });
        chkIds = chkIds.slice(0, -1).toString();
        var confirmvalue = confirm("Are you sure you want to delete selected ?");
            if (confirmvalue) {
                $.ajax({
                    url: "/Admin/DeleteMultipleBanner",
                    type: "GET",
                    data: { 'sDeleteId': chkIds },
                    success: function (data) {
                            window.location = '/Admin/Banner';
                        },
                     error: function (xhr, status, error) {
                             alert('Server Error');
                        }
                    });
                }
            }
    else {
        alert('Please Select at lease one Checkbox!');
    }                                 
});

[HttpGet]
public void DeleteMultipleBanner(string sDeleteId)
{
   
    List<int> listDeleteId = sDeleteId.Split(',').Select(int.Parse).ToList();
    // In listDeleteId you will get list of integer
    // your table name and delete query
    db.BannerMasters.Where(x => listDeleteId.Contains(x.BannerId)).ToList().ForEach(item =>     db.BannerMasters.Remove(item));
    db.SaveChanges();
}

Wednesday, 17 September 2014

Checkbox with Header in Gridview using jquery

<script type="text/ecmascript">
        $(document).ready(function () {
            $("#<%=grdBanner.ClientID%> input[id*='chkChild']:checkbox").click(function () {
                //Get number of checkboxes in list either checked or not checked
                var totalCheckboxes = $("#<%=grdBanner.ClientID%> input[id*='chkChild']:checkbox").size();
                //Get number of checked checkboxes in list
                var checkedCheckboxes = $("#<%=grdBanner.ClientID%> input[id*='chkChild']:checkbox:checked").size();
                //Check / Uncheck top checkbox if all the checked boxes in list are checked
                $("#<%=grdBanner.ClientID%> input[id*='chkAll']:checkbox").attr('checked', totalCheckboxes == checkedCheckboxes);
            });
            $("#<%=grdBanner.ClientID%> input[id*='chkAll']:checkbox").click(function () {
                //Check/uncheck all checkboxes in list according to main checkbox
                $("#<%=grdBanner.ClientID%> input[id*='chkChild']:checkbox").attr('checked', $(this).is(':checked'));
            });
        });
    </script>

<asp:TemplateField>
                            <HeaderTemplate>
                                <asp:CheckBox runat="server" ID="chkAll" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox runat="server" ID="chkChild" />
                            </ItemTemplate>
                        </asp:TemplateField>

Thursday, 11 September 2014

Ajax Post With Multipler Param

$('#send_btn').click(function () {
    $.ajax({
            type: "POST",
            url: "Home.aspx/InsertEnquiry",
            contentType: "application/json; charset=utf-8",
            data: "{'sName':'" + $("#<%=txtName.ClientID%>").val(); + "','sMessage':'" + $("#<%=txtName.ClientID%>").val(); + "'}",
            dataType: "json",
            success: function (data) {
                    alert(data.d);
                },
                error: function (xhr, status, error) {
                    alert("Error");
                }
            });
    });

Tuesday, 2 September 2014

Check String is Palindrom or Not

Console.Write("Enter String : ");
            string strGiven = Console.ReadLine();
            int length = strGiven.Length;

            string strTemp = string.Empty;
            for (int i = length - 1; i >= 0; i--)
            {
                strTemp += strGiven[i].ToString();
            }
            if (strTemp == strGiven)
            {
                Console.Write("Enterd {0} string is Palindrom",strGiven);
            }
            else
            {
                Console.Write("Entered {0} string is NOT Palindrom", strGiven);
            }
            Console.ReadLine();

Interview Patterns