public JsonResult GetModuleOption()
        {
            var options = new List <Option2>
            {
                new Option2
                {
                    DisplayText = "Chọn module",
                    Value       = ""
                }
            };

            List <Admin_Permission> groups = Admin_Permission.Query("Where Status=1").ToList();

            if (groups.Any())
            {
                options.AddRange(groups.Select(c => c.Code).Distinct().Select(c => new Option2
                {
                    DisplayText = Convert.ToString(c),
                    Value       = Convert.ToString(c)
                }).ToList());
            }

            return(Json(new
            {
                Result = 1,
                Records = options,
                Total = options.Count
            }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Delete_Permission(Admin_Permission obj)
        {
            List <Admin_Permission> Acc = Admin_Permission.Query("Where Id=@0", obj.Id).ToList();

            try
            {
                if (Acc.Count > 0)
                {
                    Acc.FirstOrDefault().Status = obj.Status;
                    Acc.FirstOrDefault().Save();
                }
            }
            catch
            {
                return(Json(0));
            }
            return(Json(new { Result = 1, Records = Acc }));
        }
        public JsonResult Update_Permission(Admin_Permission obj)
        {
            List <Admin_Permission> Acc = Admin_Permission.Query("Where Id=@0", obj.Id).ToList();

            try
            {
                if (Acc.Any())
                {
                    Acc.FirstOrDefault().Name         = obj.Name;
                    Acc.FirstOrDefault().Code         = obj.Code;
                    Acc.FirstOrDefault().Description  = obj.Description;
                    Acc.SingleOrDefault().UpdatedDate = DateTime.Now;
                    Acc.FirstOrDefault().Save();
                }
            }
            catch (Exception ex)
            {
                return(Json(0));
            }
            return(Json(new { Result = 1, Records = Acc }));
        }
        public JsonResult Get_Permission_List(DataModel obj)
        {
            string order        = string.Empty;
            int    totalRecords = int.MinValue;

            if (obj._od != null)
            {
                order = " Order By " + obj._od.FirstOrDefault().Key + " " + obj._od.FirstOrDefault().Value;
            }

            List <Admin_Permission>        AccList_source = new List <Admin_Permission>();
            List <Admin_Permission_Config> AccList        = new List <Admin_Permission_Config>();
            string msg = string.Empty;

            try
            {
                if (obj._c != null)
                {
                    string querystring = "";
                    foreach (var k in obj._c)
                    {
                        switch (k.Key)
                        {
                        case "Name":
                            querystring += k.Value.ToString();
                            break;

                        default:
                            querystring += k.Key + "=" + k.Value.ToString();
                            break;
                        }
                        if (!k.Equals(obj._c.Last()))
                        {
                            querystring += " AND ";
                        }
                    }
                    AccList_source = Admin_Permission.Query("Where Status=1 AND " + querystring + order + "").ToList();
                }
                else
                {
                    AccList_source = Admin_Permission.Query("Where  Status=1 " + order + "").ToList();
                }

                // Map du lieu sang Model khac
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <Admin_Permission, Admin_Permission_Config>();
                });
                IMapper mapper = config.CreateMapper();
                AccList = mapper.Map <List <Admin_Permission>, List <Admin_Permission_Config> >(AccList_source);

                int pSize = obj._lm;
                totalRecords = AccList.Count();
                if (totalRecords > 1)
                {
                    AccList = AccList.Skip(obj._os).Take(pSize).ToList();
                }
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
            }

            return(Json(new { Result = 1, TotalRecordCount = totalRecords, Records = AccList, Message = msg }, JsonRequestBehavior.AllowGet));
        }