public ActionResult EditRol(Models.RolModel rolModel, string[] roles) { if (ModelState.IsValid) { JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities(); var rolInfQuery = (from p in _dbContext.AspNetRoles where p.Name == rolModel.nameGroup select p).FirstOrDefault(); rolInfQuery.Description = rolModel.GroupDescription; var operationByRol = (from p in _dbContext.AspNetRoles from d in _dbContext.T_Operations where p.Name == rolModel.nameGroup select p).FirstOrDefault(); operationByRol.T_Operations.Clear(); if (roles != null) { foreach (string permisson in roles) { int operationID = Convert.ToInt32(permisson); var queryOperationsId = (from p in _dbContext.T_Operations where p.biOperationsId == operationID select p).First(); rolInfQuery.T_Operations.Add(queryOperationsId); _dbContext.SaveChanges(); } } _dbContext.SaveChanges(); TempData["Message"] = "Changes Saved"; return(RedirectToAction("RolesIndex", "Maintenance")); } rolModel.nameGroup = rolModel.nameGroup; rolModel.OperationsList = Helper.Helper.GetOperations(rolModel.nameGroup); return(View(rolModel)); }
public ActionResult CreateRol(Models.RolModel model, string[] roles) { ApplicationDbContext context = new ApplicationDbContext(); JneCommSitesDataLayer.JneCommSitesDataBaseEntities _dbContext = new JneCommSitesDataLayer.JneCommSitesDataBaseEntities(); JneCommSitesDataLayer.T_Operations selectedOperations = new JneCommSitesDataLayer.T_Operations(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = model.nameGroup; roleManager.Create(role); var rolInformation = (from p in _dbContext.AspNetRoles where p.Name == model.nameGroup select p).First(); rolInformation.Description = model.GroupDescription; if (roles != null) { foreach (string permisson in roles) { int operationID = Convert.ToInt32(permisson); var queryOperationsId = (from p in _dbContext.T_Operations where p.biOperationsId == operationID select p).First(); rolInformation.T_Operations.Add(queryOperationsId); _dbContext.SaveChanges(); } } _dbContext.SaveChanges(); TempData["Message"] = "Has successfully create the role"; return(RedirectToAction("RolesIndex", "Maintenance")); ModelState.AddModelError("", "Please check for errors and try again."); return(View(model)); }