public ActionResult Delete(Guid id) { try { string userRoleId = string.Empty; #region Check User Role Mapping Exist var userRoleMapping = userRepository.GetUserRoleByUserId(null, id); if (userRoleMapping != null && userRoleMapping.Count > 0) { return(Json(new { IsSuccess = false, errorMessage = "You can not delete this user role because there are one or more users assigned with this user role." }, JsonRequestBehavior.AllowGet)); } #endregion userRoleId = userRoleRepository.DeleteUserRole(id, LogInManager.LoggedInUserId); 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 deleted successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Delete"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
/// <summary> /// To delete the user role details by id. /// </summary> /// <param name="userrole"></param> /// <param name="accessToken"></param> /// <returns></returns> public string DeleteUserRole(int id, string accessToken) { string msg = string.Empty; 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())) { var userRole = repository.GetUserRoleIDDetails(id); if (userRole != null) { repository.DeleteUserRole(userRole); msg = "UserRole has been deleted successfully."; } else { msg = "Content not found by Id =" + id; } } } else { throw new Exception("Unable to get database connection."); } } catch { throw; } return(msg); }