Thursday 15 March 2018

MVC asp.net Multi Level Menu Bind


Model:


public class M_MenuModel
    {
        #region Variable
        public Int32   MMID { get; set; }
        public string MM_Name { get; set; }
        public string MM_Url { get; set; }
        public Int32 MM_Parent { get; set; }     
        public string MM_Icon { get; set; }       
        #endregion
    }

Controller :

 public ActionResult UserMenuShow()
        {
            ViewBag.Menu = BuildMenu();
            return View();
        }


 private IList<M_MenuModel> BuildMenu()
        {
IList<M_MenuModel> mmList = new List<M_MenuModel>(){
             
                // Parent
                new M_MenuModel(){ MMID = 1, MM_Name = "Home", MM_Parent = 0, MM_Url = "1"} ,
                new M_MenuModel(){ MMID = 2, MM_Name = "Admin", MM_Parent = 0, MM_Url = "1"} ,
                new M_MenuModel(){ MMID = 3, MM_Name = "Accounting", MM_Parent = 0, MM_Url = "1"} ,

                // Children

                new M_MenuModel() { MMID=21, MM_Name = "Create User", MM_Parent = 2, MM_Url="1", MM_Icon="" },
                new M_MenuModel() { MMID=22, MM_Name = "Create Group", MM_Parent = 2, MM_Url="2" },
                new M_MenuModel() { MMID=23, MM_Name = "Create Account", MM_Parent = 2, MM_Url="3"},

                new M_MenuModel() { MMID=31, MM_Name = "Manage Account", MM_Parent = 3, MM_Url="1" },
                new M_MenuModel() { MMID=32, MM_Name = "GL Accounts", MM_Parent = 3, MM_Url="2" },


                new M_MenuModel() { MMID=321, MM_Name = "Salary Accounts", MM_Parent = 32, MM_Url="1" },
                new M_MenuModel() { MMID=322,MM_Name = "Savings Accounts", MM_Parent = 32, MM_Url="2" },

            };

            return mmList;
}


View:



@{
    List<ProjectName.Areas.Admin.Models.M_MenuModel> menuList = ViewBag.Menu;
}


@foreach (var mp in menuList.Where(p => p.MM_Parent == 0))
                {

                    <li>

                        @if (menuList.Count(p => p.MM_Parent == mp.MMID) > 0)
                        {
                            <a href="#@mp.MM_Name" data-toggle="collapse" class="collapsed">@mp.MM_Name <i class="icon-submenu lnr lnr-chevron-left"></i></a>
                            @:<div ID="@mp.MM_Name" class="collapse">
                                @:<ul class="nav">
        }
                        @if (menuList.Count(p => p.MM_Parent == mp.MMID) == 0)
                        {
                            
                            @:<a href="@mp.MM_Url"> @Html.Raw(@mp.MM_Icon) @mp.MM_Name </a>
                        }

                            @RenderMenuItem(menuList, mp)

                        @if(menuList.Count(p => p.MM_Parent == mp.MMID) > 0)
                        {



                    @:</ul>
                        
                    @:</div>
                                            }

                    </li>
                }

@helper RenderMenuItem(List<Manav_Ashraya_V1.Areas.Admin.Models.M_MenuModel> menuList, Manav_Ashraya_V1.Areas.Admin.Models.M_MenuModel mi)
{
foreach (var cp in menuList.Where(p => p.MM_Parent == mi.MMID))
{


        @:<li>








    if (menuList.Count(p => p.MM_Parent == cp.MMID) > 0)
    {

            <a href="#@cp.MM_Name.Replace(' ','_')" data-toggle="collapse" class="collapsed">@cp.MM_Name <i class="icon-submenu lnr lnr-chevron-left"></i></a>

            @:<div ID="@cp.MM_Name.Replace(' ','_')" class="collapse">
                @:<ul class="nav">
        }
        if (menuList.Count(p => p.MM_Parent == cp.MMID) == 0)
        {
            @:<a href="@cp.MM_Url">@cp.MM_Name</a>


        }

        @RenderMenuItem(menuList, cp)
    if (menuList.Count(p => p.MM_Parent == cp.MMID) > 0)
    {
     @:   </ul>

    @:</div>
    }
    else
    {


         
        @:</li>
    }
}
}

Friday 9 March 2018

Update a table using JOIN in SQL Server

  1. UPDATE t1  
  2. SET t1.TID = t2.DOID  
  3. FROM dbo.Table1 AS t1  
  4. INNER JOIN dbo.Table2 AS t2  
  5. ON t1.CommonField = t2.[Common Field] 

Saturday 3 March 2018

Populate (Bind) DropDownList using AngularJS AJAX and JSON

Angular JS 

var AnguarModule = angular.module('CMS', []);
AnguarModule.controller('DashBoard', function ($scope, $http, ApiCall) {
  var result = ApiCall.GetApiCall("MasterDetails", "ASYears").success(function (data) {
        $scope.ASYearsDetails = data;
        $scope.ASYearsD = $scope.ASYearsDetails[0];
    });
});

AngularService

AnguarModule.service('ApiCall', ['$http', function ($http) {
    var result;

    // This is used for calling get methods from web api
    this.GetApiCall = function (controllerName, methodName) {
        result = $http.get(controllerName + '/' + methodName).success(function (data, status) {
            result = (data);

        }).error(function () {
            alert("Something went wrong");
        });
        return result;
    }; 
 

} ]);



HTML: 

 <div class="content" ng-app="CMS">

<div class="col-lg-4  col-md-6" ng-controller="DashBoard">

<select ng-model="ASYearsD" ng-options="items.ASYears for items in ASYearsDetails"
                ng-change="ShowUnfiled()" ng-init="ASYearsD = data[1].AsYr" id="ASYearsD">
                <option value="">-- Select --</option>
            </select>
</div>
</div>


JSON :


[{"AsYr":"2017","ASYears":"2016-17","Selected":"1"},{"AsYr":"2016","ASYears":"2015-16","Selected":"0"},{"AsYr":"2015","ASYears":"2014-15","Selected":"0"},{"AsYr":"2014","ASYears":"2013-14","Selected":"0"},{"AsYr":"2013","ASYears":"2012-13","Selected":"0"},{"AsYr":"2012","ASYears":"2011-12","Selected":"0"},{"AsYr":"2011","ASYears":"2010-11","Selected":"0"},{"AsYr":"2010","ASYears":"2009-10","Selected":"0"},{"AsYr":"2009","ASYears":"2008-09","Selected":"0"},{"AsYr":"2008","ASYears":"2007-08","Selected":"0"},{"AsYr":"2007","ASYears":"2006-07","Selected":"0"}]