Example #1
0
        public ResponseViewModel <List <RoleResponseViewModel> > GetAll()
        {
            ResponseViewModel <List <RoleResponseViewModel> > response = new ResponseViewModel <List <RoleResponseViewModel> >();
            List <RoleResponseViewModel> _lstRoleResponse = new List <RoleResponseViewModel>();

            try
            {
                var _lstRole = _roleRepository.GetAll().ToList();


                for (int i = 0; i < _lstRole.Count; i++)
                {
                    RoleResponseViewModel _objRoleResponse = new RoleResponseViewModel()
                    {
                        roleid          = _lstRole[i].RoleId,
                        roledescription = _lstRole[i].RoleDescription,
                        rolename        = _lstRole[i].RoleName,
                        IsDeleted       = _lstRole[i].IsDeleted
                    };

                    _lstRoleResponse.Add(_objRoleResponse);
                }

                if (_lstRoleResponse.Count > 0)
                {
                    response.Status  = true;
                    response.Message = _errorMessageService.GetErrorMessagesData("123");
                    response.Result  = _lstRoleResponse;
                }
                else
                {
                    response.Status  = false;
                    response.Message = _errorMessageService.GetErrorMessagesData("124");
                    response.Result  = _lstRoleResponse;
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    _loggerService.LogError(1, "## [RoleService][GetAll] innerexception :" + ex.InnerException.ToString());

                    if (ex.InnerException.Message != null)
                    {
                        _loggerService.LogError(1, "## [RoleService][GetAll] innerexception message :" + ex.InnerException.Message.ToString());
                    }
                }
                else
                {
                    _loggerService.LogError(1, "## [RoleService][GetAll] exception :" + ex.Message.ToString());
                }

                response.Status     = false;
                response.Message    = _errorMessageService.GetErrorMessagesData("501");
                response.StatusCode = (int)HttpStatusCode.BadRequest;
            }

            return(response);
        }
Example #2
0
        public ResponseViewModel <RoleResponseViewModel> GetById(int roleId)
        {
            ResponseViewModel <RoleResponseViewModel> response = new ResponseViewModel <RoleResponseViewModel>();
            List <Error>          lstError = new List <Error>();
            RoleResponseViewModel objRoleResponseViewModel = new RoleResponseViewModel();

            try
            {
                var findRole = _roleRepository.Find(roleId);
                if (findRole != null)
                {
                    objRoleResponseViewModel.roleid          = findRole.RoleId;
                    objRoleResponseViewModel.rolename        = findRole.RoleName;
                    objRoleResponseViewModel.roledescription = findRole.RoleDescription;
                    objRoleResponseViewModel.IsDeleted       = findRole.IsDeleted;
                }
                else
                {
                    var errorMessage = _errorMessageService.GetErrorMessagesData("125");
                    var objError     = new Error {
                        Code = "125", Message = errorMessage
                    };
                    lstError.Add(objError);
                }

                if (lstError.Count == 0)
                {
                    response.Status     = true;
                    response.Message    = "Role get sucessfully";
                    response.StatusCode = (int)HttpStatusCode.OK;
                    response.Result     = objRoleResponseViewModel;
                }
                else
                {
                    response.Status     = false;
                    response.Errors     = lstError;
                    response.StatusCode = (int)HttpStatusCode.BadRequest;
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    _loggerService.LogError(1, "## [UserService][GetById] innerexception :" + ex.InnerException.ToString());

                    if (ex.InnerException.Message != null)
                    {
                        _loggerService.LogError(1, "## [UserService][GetById] innerexception message :" + ex.InnerException.Message.ToString());
                    }
                }
                else
                {
                    _loggerService.LogError(1, "## [UserService][GetById] exception :" + ex.Message.ToString());
                }

                response.Status     = false;
                response.Message    = _errorMessageService.GetErrorMessagesData("501");
                response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            return(response);
        }