public ActionResult UserPermission(Permissionviewmodel vm, string Search, string Save)
        {
            List <string>           result      = new List <string>();
            PermissionMaster        _master     = new PermissionMaster();
            List <ModulePermission> p           = new List <ModulePermission>();
            Permissionviewmodel     searchmodel = new Permissionviewmodel();

            Guid CompanyId = new Guid();

            if (Request.Cookies["CompanyId"] != null)
            {
                CompanyId = new Guid(Commonhelper.GetCookie("CompanyId"));
            }
            if (vm.PermissionMaster != null)
            {
                _master.Id          = Guid.NewGuid().ToString();
                _master.CompanyId   = CompanyId.ToString();
                _master.UserId      = vm.PermissionMaster.UserId;
                _master.CreatedBy   = User.Identity.GetUserId();
                _master.DateCreated = DateTime.Now;
                _master.Workstation = Commonhelper.GetStation();
            }
            if (vm.Menumaster.Count() > 0)
            {
                foreach (var item in vm.Menumaster)
                {
                    foreach (var child in item._SubMenumaster)
                    {
                        if (child.IsAdd == true || child.IsEdit == true || child.Isview == true || child.Isdelete == true)
                        {
                            ModulePermission mp = new ModulePermission();
                            mp.Id           = Guid.NewGuid().ToString();
                            mp.MenuId       = item.MenuId;
                            mp.SubMenuId    = child.SubMenumasterId;
                            mp.IsAdd        = child.IsAdd;
                            mp.IsEdit       = child.IsEdit;
                            mp.Isview       = child.Isview;
                            mp.Isdelete     = child.Isdelete;
                            mp.DisplayOrder = child.order;
                            mp.Displayclass = child.Displayclass;
                            mp.DisplayName  = child.DisplayName;
                            _master._ModulePermission.Add(mp);
                        }
                    }
                }
                try
                {
                    Commonhelper.SavePermission(_master);
                    return(Content("<script language='javascript' type='text/javascript'>alert('permission saved successfully!');</script>"));
                }
                catch (Exception ex)
                {
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));



            ///return View();
        }
        public ActionResult EditPermission(Guid Id)
        {
            PermissionMaster    _Permission = new PermissionMaster();
            Permissionviewmodel vm          = new Permissionviewmodel();

            vm        = Commonhelper.GetpermissionById(Id);
            vm.UserId = Id.ToString();
            return(View(vm));
        }
        public async Task <ActionResult> DeleteConfirmed(Guid id)
        {
            PermissionMaster permissionMaster = await db.PermissionMasters.FindAsync(id);

            db.PermissionMasters.Remove(permissionMaster);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,CreatedBy,CreatedDate,LastUpdatedDate,LastUpdatedBy,StatusCodeId")] PermissionMaster permissionMaster)
        {
            if (ModelState.IsValid)
            {
                db.Entry(permissionMaster).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            // ViewBag.StatusCodeId = new SelectList(db.StatusCodeMasters, "Id", "StatusCodes", permissionMaster.StatusCodeId);
            return(View(permissionMaster));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,CreatedBy,CreatedDate,LastUpdatedDate,LastUpdatedBy,StatusCodeId")] PermissionMaster permissionMaster)
        {
            if (ModelState.IsValid)
            {
                permissionMaster.Id = Guid.NewGuid();
                db.PermissionMasters.Add(permissionMaster);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            //ViewBag.StatusCodeId = new SelectList(db.StatusCodeMasters, "Id", "StatusCodes", permissionMaster.StatusCodeId);
            return(View(permissionMaster));
        }
        // GET: PermissionMasters/Details/5
        public async Task <ActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PermissionMaster permissionMaster = await db.PermissionMasters.FindAsync(id);

            if (permissionMaster == null)
            {
                return(HttpNotFound());
            }
            return(View(permissionMaster));
        }
        // GET: PermissionMasters/Edit/5
        public async Task <ActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PermissionMaster permissionMaster = await db.PermissionMasters.FindAsync(id);

            if (permissionMaster == null)
            {
                return(HttpNotFound());
            }
            // ViewBag.StatusCodeId = new SelectList(db.StatusCodeMasters, "Id", "StatusCodes", permissionMaster.StatusCodeId);
            return(View(permissionMaster));
        }
        public ActionResult Updatepermission(Permissionviewmodel vm)
        {
            List <string>           result  = new List <string>();
            PermissionMaster        _master = new PermissionMaster();
            List <ModulePermission> p       = new List <ModulePermission>();
            Guid CompanyId = new Guid();

            if (Request.Cookies["CompanyId"] != null)
            {
                CompanyId = new Guid(Commonhelper.GetCookie("CompanyId"));
            }
            Permissionviewmodel searchmodel = new Permissionviewmodel();

            if (vm.PermissionMaster != null)
            {
                _master.Id           = vm.Id;
                _master.CompanyId    = CompanyId.ToString();
                _master.UserId       = vm.UserId;
                _master.ModifiedBy   = User.Identity.GetUserId();
                _master.Datemodified = DateTime.Now;
                _master.Workstation  = Commonhelper.GetStation();
            }
            if (vm.Menumaster.Count() > 0)
            {
                foreach (var item in vm.Menumaster)
                {
                    foreach (var child in item._SubMenumaster)
                    {
                        if (child.IsAdd == true || child.IsEdit == true || child.Isview == true || child.Isdelete == true)
                        {
                            ModulePermission mp = new ModulePermission();
                            mp.Id           = Guid.NewGuid().ToString();
                            mp.MenuId       = item.MenuId;
                            mp.SubMenuId    = child.SubMenumasterId;
                            mp.IsAdd        = child.IsAdd;
                            mp.IsEdit       = child.IsEdit;
                            mp.Isview       = child.Isview;
                            mp.Isdelete     = child.Isdelete;
                            mp.DisplayOrder = Commonhelper.GetSubmenuOrder(mp.SubMenuId);
                            mp.Displayclass = child.Displayclass;
                            mp.DisplayName  = child.DisplayName;
                            _master._ModulePermission.Add(mp);
                        }
                    }
                }
                try
                {
                    Commonhelper.UpdatePermission(_master);
                    return(RedirectToAction("RegisteredAccounts"));
                    ////return Content("<script language='javascript' type='text/javascript'>alert('permission update successfully!');</script>");
                }
                catch (Exception ex)
                {
                }
            }
            //List<Permission> permissions = new List<Permission>();
            //List<ModulePermission> _MPermission = new List<ModulePermission>();
            //try
            //{
            //    if(pm!=null)
            //    {
            //        pm.Datemodified = DateTime.Now;
            //        pm.ModifiedBy = User.Identity.GetUserId();
            //        if (pm._Permission.Count() > 0)
            //        {
            //            foreach(var item in pm._Permission)
            //            {
            //                Permission p = new Permission();
            //                p.DisplayOrder = item.DisplayOrder;
            //                p.Id = Guid.NewGuid();
            //                p.Isactive = item.Isactive;
            //                p.MenuId = item.MenuId;
            //                p.PermissionMasterId = pm.Id;
            //                p.Displayclass = item.Displayclass;
            //                p.DisplayName = item.DisplayName;
            //                permissions.Add(p);

            //            }
            //            pm._Permission.Clear();
            //            pm._Permission = permissions;
            //            foreach(var child in pm._ModulePermission)
            //            {
            //                ModulePermission mp = new ModulePermission();
            //                mp.Id = Guid.NewGuid();
            //                mp.PermissionMasterId = pm.Id;
            //                mp.MenuId = child.MenuId;
            //                mp.SubMenuId = child.SubMenuId;
            //                mp.IsAdd = child.IsAdd;
            //                mp.IsEdit = child.IsEdit;
            //                mp.Isview = child.Isview;
            //                mp.Isdelete = child.Isdelete;
            //                mp.DisplayOrder = child.DisplayOrder;
            //                mp.Displayclass = child.Displayclass;
            //                mp.DisplayName = child.DisplayName;
            //                _MPermission.Add(mp);
            //            }
            //            pm._ModulePermission.Clear();
            //            pm._ModulePermission.AddRange(_MPermission);
            //            try
            //            {
            //                Commonhelper.SavePermission(_master);
            //                /// Commonhelper.UpdatePermission(pm);
            //            }
            //            catch(Exception ex)
            //            {
            //                result.Add("Internal server Issue try again.");
            //            }
            //        }

            //    }
            //    return Content("<script language='javascript' type='text/javascript'>alert('permission update successfully!');</script>");
            //    //result.Add("permission update successfully.");
            //    //ModelState.Clear();
            //    //return Json(new { url = Url.Action("UserLevelPermission") });

            //}
            //catch(Exception ex)
            //{
            //    result.Add("Internal server Issue try again.");

            //}


            return(Json(result));
        }