public ActionResult Add(AddSecurityGroupViewModel model) { if (!ModelState.IsValid) { return(View(model)); } //Check security group exist if (this.securityGroupService.IsSecurityGroupExist(model.Name)) { this.ModelState.AddModelError("", Resources.Translation.AdminArea.Admin.ThereAreSecGroup); return(View(model)); } //Check if the name is same of the base group if (model.Name == BaseAdmin.BaseGroup) { ModelState.AddModelError("", Resources.Translation.AdminArea.Admin.YouCantAddSameName); return(View(model)); } //Add a security group to database var scGroup = this.securityGroupService.Add( new SecurityGroup { Name = model.Name }); //Add right to a new security group var idS = model.SelectedRights.Where(x => x.IsSelected).Select(x => x.Right.Id).ToList(); this.securityGroupService.AddRights(scGroup.Id, idS); return(RedirectToAction("GetAll")); }
public ActionResult Add() { var rights = this.rightService.GetAll().ToList(). ConvertAll(x => new SelectedRightViewModel { Right = new RightViewModel { Name = Rights.ResourceManager.GetString("r" + x.Code.ToString()), Id = x.Id }, IsSelected = false }); var viewModel = new AddSecurityGroupViewModel(); viewModel.SelectedRights = rights; return(View(viewModel)); }