public ActionResult Edit(int id)
        {
            Context.Role dbitem = RepoRole.FindByPK(id);
            Role         model  = new Role(dbitem);

            ViewBag.name = model.name;
            return(View("Form", model));
        }
Exemple #2
0
 public void setDb(Context.Role dbitem)
 {
     dbitem.RoleName = name;
     dbitem.RoleMenus.Clear();
     foreach (var item in ListMenu)
     {
         dbitem.RoleMenus.Add(item.setDb(new Context.RoleMenus()));
     }
 }
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.Role dbItem = RepoRole.FindByPK(id);

            RepoRole.delete(dbItem);

            return(Json(response));
        }
Exemple #4
0
        public Role(Context.Role dbitem)
        {
            id   = dbitem.Id;
            name = dbitem.RoleName;

            ListMenu = new List <RoleMenu>();
            foreach (var item in dbitem.RoleMenus)
            {
                ListMenu.Add(new RoleMenu(item));
            }
        }
        public ActionResult Edit(Role model)
        {
            RoleMenu[] result = JsonConvert.DeserializeObject <RoleMenu[]>(model.StrMenu);
            model.ListMenu = result.ToList();
            if (ModelState.IsValid)
            {
                Context.Role dbitem = RepoRole.FindByPK(model.id);
                model.setDb(dbitem);
                RepoRole.save(dbitem);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
        public string Binding(string modul, int role_id)
        {
            Context.Role        role  = RepoRole.FindByPK(role_id);
            List <Context.Menu> items = RepoMenu.FindAll().Where(d => d.Modul == modul && !role.RoleMenus.Select(f => f.IdMenu).Contains(d.Id)).ToList();

            List <RoleMenu> ListModel = new List <RoleMenu>();

            foreach (Context.Menu item in items)
            {
                ListModel.Add(new RoleMenu(item));
            }

            foreach (Context.RoleMenus item in role.RoleMenus.Where(d => RepoMenu.FindAll().Where(f => f.Modul == modul).Select(e => e.Id).ToList().Contains(d.IdMenu.Value)))
            {
                ListModel.Add(new RoleMenu(item));
            }

            return(new JavaScriptSerializer().Serialize(new { total = ListModel.Count(), data = ListModel }));
        }