public ActionResult Edit([Bind(Include = "Id,ParentId,Name,ActionName,ControllerName,Title,RolesName,Status")]EditMenuViewModel menusE) { if (ModelState.IsValid) { string roleName = string.Empty; if (menusE.RolesName != null) { string sep = string.Empty; foreach (var rn in menusE.RolesName) { roleName += sep + rn; sep = ","; } } Menus menus = new Menus() { Id = menusE.Id, ParentId = menusE.ParentId, Name = menusE.Name, ActionName = menusE.ActionName, ControllerName = menusE.ControllerName, Title = menusE.Title, RoleName = roleName, Status = menusE.Status.Substring(0, 1) }; db.Entry(menus).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(menusE); }
private List<Menus> createDefMenus() { List<Menus> def = new List<Menus>(); //Crea menu para la administración de la cuenta Menus menu = new Menus { Id = 1000, ParentId = 0, Name = "Configurar Cuenta", Title = "Menú de configuración la cuenta", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1001, ParentId = 1000, Name = "Cambiar contraseña", ActionName = "ChangePassword", ControllerName = "Manage", Title = "Cambia la contraseña del usuario", Status = "A" }; def.Add(menu); //Crea el menu para la administración de Aplicación menu = new Menus { Id = 1100, ParentId = 0, Name = "Administrar Aplicación", Title = "Menús para la administración de la aplicación", RoleName = "ADMINISTRADOR N1,ADMINISTRADOR N2,ADMINISTRADOR N3", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1101, ParentId = 1100, Name = "Registrar Usuario", ActionName = "Register", ControllerName = "Account", Title = "Registra a un nuevo usuario", RoleName = "ADMINISTRADOR N1,ADMINISTRADOR N2,ADMINISTRADOR N3", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1102, ParentId = 1100, Name = "Usuarios", ActionName = "Index", ControllerName = "Users", Title = "Administra a los usuarios", RoleName = "ADMINISTRADOR N1,ADMINISTRADOR N2,ADMINISTRADOR N3", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1103, ParentId = 1100, Name = "Usuarios-Roles", ActionName = "Index", ControllerName = "UserRoles", Title = "Administra las relaciones de los usuarios y roles", RoleName = "ADMINISTRADOR N1,ADMINISTRADOR N2", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1104, ParentId = 1100, Name = "Roles", ActionName = "Index", ControllerName = "Roles", Title = "Administra los roles para los usuarios", RoleName = "ADMINISTRADOR N1", Status = "A" }; def.Add(menu); menu = new Menus { Id = 1105, ParentId = 1100, Name = "Menús", ActionName = "Index", ControllerName = "Menus", Title = "Administra los menús", RoleName = "ADMINISTRADOR N1", Status = "A" }; def.Add(menu); return def; }
public ActionResult Create([Bind(Include = "Id,ParentId,Name,ActionName,ControllerName,Title,RolesName,Status")] CreateMenuViewModel menusC) { if (ModelState.IsValid) { string roleName = string.Empty; if (menusC.RolesName != null) { string sep = string.Empty; foreach (var rn in menusC.RolesName) { roleName += sep + rn; sep = ","; } } Menus menus = new Menus() { ParentId = menusC.ParentId, Name = menusC.Name, ActionName = menusC.ActionName, ControllerName = menusC.ControllerName, Title = menusC.Title, RoleName = roleName, Status = menusC.Status.Substring(0,1) }; db.Menus.Add(menus); db.SaveChanges(); return RedirectToAction("Index"); } return View(menusC); }