public ActionResult AddUserRole(UserAppRoleView user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (!ModelState.IsValid) { var viewModel = this.userService.GetUpdatedUserRoleView(user, string.Empty); return(this.View("AddUserRole", viewModel)); } var returnUrl = this.userService.ProcessUserAppRole(user); if (!string.IsNullOrEmpty(returnUrl)) { var viewModel = this.userService.GetUpdatedUserRoleView(user, returnUrl); return(this.View("AddUserRole", viewModel)); } returnUrl = string.Format("{0} Added", user.Username); return(RedirectToAction("Administration", "User", new { message = returnUrl })); }
/// <summary> /// Creates the user role view. /// </summary> /// <param name="appRoleCollection">The application role collection.</param> /// <param name="userDetail">The user detail.</param> /// <param name="loggedInUsername">The logged in username.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">appRoleCollection</exception> public IUserAppRoleView CreateUserRoleView(IList <IAppRole> appRoleCollection, IUserDetail userDetail, string loggedInUsername) { if (appRoleCollection == null) { throw new ArgumentNullException(nameof(appRoleCollection)); } var appRoleDropDown = GetDropDownList.AppRoleListItems(appRoleCollection, -1); var returnView = new UserAppRoleView { AppRoleCollection = appRoleDropDown, Username = userDetail.Username, UserId = userDetail.UserId, CreateByUsername = loggedInUsername }; return(returnView); }
/// <summary> /// Gets the delete user application role view. /// </summary> /// <param name="userAppRole">The user application role.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">userAppRole</exception> public IUserAppRoleView GetDeleteUserAppRoleView(IUserAppRole userAppRole, int userId) { if (userAppRole == null) { throw new ArgumentNullException(nameof(userAppRole)); } var result = new UserAppRoleView { AppRoleId = userAppRole.AppRoleId, Username = userAppRole.Username, CreateByUsername = userAppRole.CreateByUsername, DateCreated = userAppRole.DateCreated, AppRoleName = userAppRole.RoleName, UserAppRoleId = userAppRole.UserAppRoleId, UserId = userId }; return(result); }
/// <summary> /// Gets the edit user application role view. /// </summary> /// <param name="userAppRole">The user application role.</param> /// <param name="roleCollection">The role collection.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// userAppRole /// or /// roleCollection /// </exception> public IUserAppRoleView GetEditUserAppRoleView(IUserAppRole userAppRole, IList <IAppRole> roleCollection) { var appRoleName = string.Empty; if (userAppRole == null) { throw new ArgumentNullException(nameof(userAppRole)); } if (roleCollection == null) { throw new ArgumentNullException(nameof(roleCollection)); } var appRoleDropDown = GetDropDownList.AppRoleListItems(roleCollection, userAppRole.AppRoleId); foreach (var item in roleCollection) { if (item.AppRoleId == userAppRole.AppRoleId) { appRoleName = item.Action; } } var result = new UserAppRoleView { AppRoleId = userAppRole.AppRoleId, Username = userAppRole.Username, CreateByUsername = userAppRole.CreateByUsername, DateCreated = userAppRole.DateCreated, AppRoleCollection = appRoleDropDown, AppRoleName = appRoleName }; return(result); }