public IActionResult Get(int roleid) { try { ResponseViewModel <List <PermissionResponseViewModel> > response = _permissionService.GetAllPermissionByRole(roleid); if (response.Status) { return(Ok(new ApiOkResponse((int)HttpStatusCode.OK, true, response.Message, response.Result))); } else { return(Ok(new ApiBadResponse(response.StatusCode, response.Status, response.Message, "", response.Errors))); } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [PermissionController][GetPermission] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [PermissionController][GetPermission] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [PermissionController][GetPermission] exception :" + ex.Message.ToString()); } var Message = _errorMessageService.GetErrorMessagesData("501"); return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiInternalServerErrorResponse((int)HttpStatusCode.InternalServerError, false, Message, ""))); } }
public ResponseViewModel <List <PermissionResponseViewModel> > GetAllPermissionByRole(int roleid) { ResponseViewModel <List <PermissionResponseViewModel> > response = new ResponseViewModel <List <PermissionResponseViewModel> >(); List <PermissionResponseViewModel> _lstPermissionResponse = new List <PermissionResponseViewModel>(); try { var _lstPermission = _permissionRepository.GetAllPermissionByRole(roleid).ToList(); for (int i = 0; i < _lstPermission.Count; i++) { PermissionResponseViewModel _objPermissionResponse = new PermissionResponseViewModel() { Module = _lstPermission[i].Module, PermissionCode = _lstPermission[i].PermissionCode, PermissionName = _lstPermission[i].PermissionName, Result = _lstPermission[i].Result, RoleId = _lstPermission[i].RoleId }; _lstPermissionResponse.Add(_objPermissionResponse); } if (_lstPermissionResponse.Count > 0) { response.Status = true; response.Message = _errorMessageService.GetErrorMessagesData("133"); response.Result = _lstPermissionResponse; } else { response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("132"); response.Result = _lstPermissionResponse; } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [MenuService][GetAllPermissionByRole] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [MenuService][GetAllPermissionByRole] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [MenuService][GetAllPermissionByRole] exception :" + ex.Message.ToString()); } response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("501"); response.StatusCode = (int)HttpStatusCode.BadRequest; } return(response); }
public ResponseViewModel <UserLoginResponseViewModel> Authenticate(UserLoginRequestViewModel inputModel) { ResponseViewModel <UserLoginResponseViewModel> response = new ResponseViewModel <UserLoginResponseViewModel>(); List <Error> _lstError = new List <Error>(); UserLoginResponseViewModel _objUserLoginResponseViewModel = new UserLoginResponseViewModel(); try { var finduser = _userRepository.FindByEmail(inputModel.email); if (finduser != null) { if (!_securityHelper.VerifyPasswordHash(inputModel.password, finduser.PasswordHash, finduser.PasswordSalt)) { var errorMessage = _errorMessageService.GetErrorMessagesData("115"); var objError = new Error { Code = "115", Message = errorMessage }; _lstError.Add(objError); } else { string accessToken = _securityHelper.GetAccessToken(inputModel.email); _objUserLoginResponseViewModel.email = finduser.Email; _objUserLoginResponseViewModel.firstname = finduser.FirstName; _objUserLoginResponseViewModel.lastname = finduser.LastName; _objUserLoginResponseViewModel.userid = finduser.UserId; _objUserLoginResponseViewModel.token = accessToken; } } else { var errorMessage = _errorMessageService.GetErrorMessagesData("115"); var objError = new Error { Code = "115", Message = errorMessage }; _lstError.Add(objError); } if (_lstError.Count == 0) { response.Status = true; response.Message = "User authenticated sucessfully"; response.StatusCode = (int)HttpStatusCode.OK; response.Result = _objUserLoginResponseViewModel; } else { response.Status = false; response.Errors = _lstError; response.StatusCode = (int)HttpStatusCode.BadRequest; } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [UserService][Authenticate] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [UserService][Authenticate] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [UserService][Authenticate] exception :" + ex.Message.ToString()); } response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("501"); response.StatusCode = (int)HttpStatusCode.BadRequest; } return(response); }
public ResponseViewModel <List <MenuResponseViewModel> > GetAll(int roleid) { ResponseViewModel <List <MenuResponseViewModel> > response = new ResponseViewModel <List <MenuResponseViewModel> >(); List <MenuResponseViewModel> _lstMenuResponse = new List <MenuResponseViewModel>(); try { var _lstMenu = _menuRepository.GetAllMenuWithPermission(roleid).ToList(); for (int i = 0; i < _lstMenu.Count; i++) { MenuResponseViewModel _objMenuResponse = new MenuResponseViewModel() { menuid = _lstMenu[i].MenuId, icon = _lstMenu[i].Icon, menucode = _lstMenu[i].MenuCode, menuname = _lstMenu[i].MenuName, parentmenuid = _lstMenu[i].ParentMenuId, sequence = _lstMenu[i].Sequence, result = _lstMenu[i].Result, roleId = _lstMenu[i].RoleId }; _lstMenuResponse.Add(_objMenuResponse); } if (_lstMenuResponse.Count > 0) { response.Status = true; response.Message = _errorMessageService.GetErrorMessagesData("133"); response.Result = _lstMenuResponse; } else { response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("132"); response.Result = _lstMenuResponse; } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [MenuService][GetAll] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [MenuService][GetAll] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [MenuService][GetAll] exception :" + ex.Message.ToString()); } response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("501"); response.StatusCode = (int)HttpStatusCode.BadRequest; } return(response); }
public ResponseViewModel <RoleCreateResponseViewModel> CreateRole(RoleCreateRequestViewModel inputModel) { ResponseViewModel <RoleCreateResponseViewModel> response = new ResponseViewModel <RoleCreateResponseViewModel>(); List <Error> lstError = new List <Error>(); RoleCreateResponseViewModel objRoleCreateResponseViewModel = new RoleCreateResponseViewModel(); try { _loggerService.LogInformation(1, "## [RoleService][CreateRole]- Start calling CreateRole method."); var findRole = _roleRepository.FindByName(inputModel.rolename); if (findRole == null) { Roles objRoles = new Roles() { RoleName = inputModel.rolename, RoleDescription = inputModel.roledescription, IsDeleted = false, CreatedBy = inputModel.createdby, UpdatedBy = inputModel.createdby, CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow }; _loggerService.LogInformation(1, "## [UserService][CreateRole]- CreateRole Model is RoleName : " + objRoles.RoleName); var roleId = _roleRepository.Add(objRoles); if (roleId > 0) { objRoleCreateResponseViewModel.roleid = roleId; objRoleCreateResponseViewModel.rolename = objRoles.RoleName; objRoleCreateResponseViewModel.roledescription = objRoles.RoleDescription; _loggerService.LogInformation(1, "## [UserService][CreateRole]- Role created sucessfully : " + objRoleCreateResponseViewModel.rolename); } else { _loggerService.LogInformation(1, "## [UserService][CreateRole]- Role not created : " + objRoleCreateResponseViewModel.rolename); var errorMessage = _errorMessageService.GetErrorMessagesData("122"); var objError = new Error { Code = "122", Message = errorMessage }; lstError.Add(objError); } } else { _loggerService.LogInformation(1, "## [UserService]-[CreateRole]- Role already exists "); var errorMessage = _errorMessageService.GetErrorMessagesData("121"); var objError = new Error { Code = "121", Message = errorMessage }; lstError.Add(objError); } if (lstError.Count == 0) { response.Status = true; response.Message = "Role created sucessfully"; response.StatusCode = (int)HttpStatusCode.OK; response.Result = objRoleCreateResponseViewModel; } else { response.Status = false; response.Errors = lstError; response.StatusCode = (int)HttpStatusCode.BadRequest; } } catch (Exception ex) { if (ex.InnerException != null) { _loggerService.LogError(1, "## [RoleService][CreateRole] innerexception :" + ex.InnerException.ToString()); if (ex.InnerException.Message != null) { _loggerService.LogError(1, "## [RoleService][CreateRole] innerexception message :" + ex.InnerException.Message.ToString()); } } else { _loggerService.LogError(1, "## [RoleService][CreateRole] exception :" + ex.Message.ToString()); } response.Status = false; response.Message = _errorMessageService.GetErrorMessagesData("501"); response.StatusCode = (int)HttpStatusCode.BadRequest; } return(response); }