コード例 #1
0
 public static MembershipRole RoleViewModelToRole(RoleViewModel roleViewModel)
 {
     var viewModel = new MembershipRole
     {
         RoleName = roleViewModel.RoleName
     };
     return viewModel;
 }
コード例 #2
0
 public static RoleViewModel RoleToRoleViewModel(MembershipRole role)
 {
     var viewModel = new RoleViewModel
     {
         Id = role.Id,
         RoleName = role.RoleName
     };
     return viewModel;
 }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: kangjh0815/test
        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");
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: kangjh0815/test
        public ActionResult AddRole()
        {
            var role = new RoleViewModel();

            return View(role);
        }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: kangjh0815/test
        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");
        }