public ActionResult Create(UserRoleVM model) { try { string userRoleId = string.Empty; model.CreatedBy = LogInManager.LoggedInUserId; #region Check User Role Code Available. if (this.CheckUserRoleCodeAvailable(model.Id, model.Code) == false) { return(Json(new { IsSuccess = false, errorMessage = string.Format("Code : {0} already exist.", model.Code) }, JsonRequestBehavior.AllowGet)); } #endregion userRoleId = userRoleRepository.AddUserRole(model); if (!string.IsNullOrWhiteSpace(userRoleId)) { return(Json(new { IsSuccess = true, data = new { UserRoleId = userRoleId } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, errorMessage = "User Role details not saved successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Create"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public async Task <IActionResult> Assign(UserRoleVM userRoleVM) { UserRoleRepository userRoleRepo = new UserRoleRepository(_serviceProvider, _context); if (ModelState.IsValid) { var addUR = await userRoleRepo.AddUserRole(userRoleVM.Email, userRoleVM.Role); } try { return(RedirectToAction("Detail", "UserRole", new { userName = userRoleVM.Email })); } catch { return(View()); } }
public async Task <IActionResult> FinishSignUp() { UserRoleRepository userRoleRepo = new UserRoleRepository(_serviceProvider, _context); var dropUR = await userRoleRepo.RemoveUserRole(User.Identity.Name, "Regular"); var addUR = await userRoleRepo.AddUserRole(User.Identity.Name, "Premium"); // FormsAuthentication.SignOut(); await _signInManager.SignOutAsync(); var user = await _userManager.GetUserAsync(User); await _signInManager.SignInAsync(user, false, null); return(RedirectToAction("Index", "Manage")); }
/// <summary> /// To add the user role details. /// </summary> /// <param name="userrole"></param> /// <param name="accessToken"></param> /// <returns></returns> public bool AddUserRole(UserRole userrole, string accessToken) { try { dynamic session = null; if (!string.IsNullOrEmpty(accessToken)) { session = _sessionManager.GetSessionValues(accessToken); } if (!string.IsNullOrEmpty(session.DatabaseId()) || _isNonPCR) { using (var repository = new UserRoleRepository(session.DatabaseId())) { bool isCheckRoleAndUser = repository.CheckRoleAndUser(userrole.RoleID, userrole.UserID); if (isCheckRoleAndUser) { bool isExistUserRoleCount = repository.ExistUserRole(userrole.UserID, userrole.RoleID); if (isExistUserRoleCount) { userrole.CreatedDate = DateTime.Now; userrole.UpdatedDate = DateTime.Now; repository.AddUserRole(userrole); return(true); } else { return(false); } } } } else { throw new Exception("Unable to get database connection."); } } catch { throw; } return(false); }
public ActionResult UserRole(UserRoleVM userRoleVM) { if (ModelState.IsValid) { userRoleVM.UserID = userRoleVM.UserID.Trim(); if (userRoleVM.ID == 0) { if (_UserRoleRepository.IsUserIDAvailable(userRoleVM.UserID)) { if (!_UserRoleRepository.IsUserRoleAvailable(userRoleVM.ID, userRoleVM.RollID, userRoleVM.UserID)) { var _UserRole = new UserRoles(); _UserRole.ID = userRoleVM.ID; _UserRole.IsActive = true; _UserRole.UserID = userRoleVM.UserID; _UserRole.RollID = userRoleVM.RollID; _UserRole.DefaultRollID = userRoleVM.RollID; _UserRole.Status = 1; _UserRole.ModifiedDateTime = System.DateTime.Now; _UserRoleRepository.AddUserRole(_UserRole); _UserRoleRepository.SaveUserRole(); TempData["msg"] = "<script>alert('Record added succesfully');</script>"; return(RedirectToAction("UserRole", "UserRole", userRoleVM)); } else { TempData["msg"] = "<script>alert('Record is already present.');</script>"; } } else { TempData["msg"] = "<script>alert('User ID is not present in active directory.');</script>"; } } else { if (_UserRoleRepository.IsUserIDAvailable(userRoleVM.UserID)) { if (!_UserRoleRepository.IsUserRoleAvailable(userRoleVM.ID, userRoleVM.RollID, userRoleVM.UserID)) { var _UserRole = new UserRoles(); _UserRole.IsActive = userRoleVM.IsActive; _UserRole.UserID = userRoleVM.UserID; _UserRole.RollID = userRoleVM.RollID; _UserRole.ID = userRoleVM.ID; _UserRole.DefaultRollID = userRoleVM.RollID; _UserRole.Status = 1; _UserRole.ModifiedDateTime = System.DateTime.Now; _UserRoleRepository.UpdateUserRole(_UserRole); _UserRoleRepository.SaveUserRole(); TempData["msg"] = "<script>alert('Record updated succesfully');</script>"; return(RedirectToAction("UserRole", "UserRole", userRoleVM)); } else { TempData["msg"] = "<script>alert('Record is already present.');</script>"; } } else { TempData["msg"] = "<script>alert('User ID is not present in active directory.');</script>"; } } } var userID = @System.Web.HttpContext.Current.User.Identity.Name.Replace("SPRINGER-SBM\\", ""); userRoleVM.Role = _UserRoleRepository.GetRoleByUserID(userID); userRoleVM.userRoles = _UserRoleRepository.GetUserRoleDetails(); userRoleVM.EmployeeName = _manuscriptDBRepositoryReadSide.EmployeeName(userID); return(View(userRoleVM)); }