public ActionResult DepartmentUserEdit(UserAddOrEditViewModel model, FormCollection collection) { Guid depId = Guid.Empty; if (collection.GetValues("depId") != null) { depId = Guid.Parse(collection.GetValue("depId").AttemptedValue); } RF.Concrete <IUserRepository>().Update(model.Entity); RF.Concrete <IUserRepository>().Context.Commit(); return(RedirectToAction("DepartmentUser", new { depId = depId, currentPageNum = model.CurrentPageNum, pageSize = model.PageSize })); }
public ActionResult DepartmentUserAdd(UserAddOrEditViewModel model, FormCollection collection) { Guid depId = Guid.Empty; if (collection.GetValues("depId") != null) { depId = Guid.Parse(collection.GetValue("depId").AttemptedValue); } if (!ModelState.IsValid) { return(View("DepartmentUserAddOrEdit", model)); } string[] lstRoles = null; if (collection.GetValues("checkboxRole") != null) { string strRoles = collection.GetValue("checkboxRole").AttemptedValue; lstRoles = strRoles.Split(','); } var urepo = RF.Concrete <IUserRepository>(); var drepo = RF.Concrete <IDepartmentRepository>(); var rrepo = RF.Concrete <IRoleRepository>(); using (var scope = new TransactionScope()) { model.Entity.Department = drepo.GetByKey(depId); urepo.Create(model.Entity); urepo.Context.Commit(); rrepo.AddUserToRoles(model.Entity.ID, lstRoles); scope.Complete(); } return(RedirectToAction("DepartmentUser", new { depId = depId, currentPageNum = model.CurrentPageNum, pageSize = model.PageSize })); }