public static MembershipRole RoleViewModelToRole(RoleViewModel roleViewModel) { var viewModel = new MembershipRole { RoleName = roleViewModel.RoleName }; return viewModel; }
public static RoleViewModel RoleToRoleViewModel(MembershipRole role) { var viewModel = new RoleViewModel { Id = role.Id, RoleName = role.RoleName }; return viewModel; }
public ActionResult AddRole(RoleViewModel role) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var newRole = ViewModelMapping.RoleViewModelToRole(role); _roleService.CreateRole(newRole); try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception("Error adding a role"); } } // Use temp data as its a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Role Added", MessageType = GenericMessages.success }; return RedirectToAction("ListAllRoles"); }
public ActionResult AddRole() { var role = new RoleViewModel(); return View(role); }
public ActionResult EditRole(RoleViewModel role) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var existingRole = _roleService.GetRole(role.Id); existingRole.RoleName = role.RoleName; try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception("Error editing role"); } } // Use temp data as its a redirect TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = "Role saved", MessageType = GenericMessages.success }; return RedirectToAction("ListAllRoles"); }