protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); ApplicationRole.Init(); ApplicationUser.Init(); }
public RoleViewModel InsertRole(RoleViewModel model) { var current = context.Roles.Include("Actions").Where(t => t.Id == model.Id).FirstOrDefault(); if (current == null) { current = new ApplicationRole(); current.Init(); current.Name = model.Name; current.Actions = context.ActionAuthorization.ToList().Where(t => model.SelectedActions.Any(a => a == t.Id)).ToList(); context.Roles.Add(current); } else { current.Name = model.Name; var todelete = current.Actions?.ToList(); todelete.ForEach(t => current.Actions.Remove(t)); current.Actions = context.ActionAuthorization.ToList().Where(t => model.SelectedActions.Any(a => a == t.Id)).ToList(); } context.SaveChanges(); model.Id = current.Id; model.Actions = current.Actions; try { var roles = context.Roles.Include("Actions").Where(t => t.IsActive == true && t.IsDeleted != true && t.IsDraft == false).ToList(); HttpContext.Current.Cache["roles"] = roles; } catch (Exception exc) { ErrorLog(exc); } return(model); }