public static DepartmentRespObj LoadDepartments(DepartmentSearchObj regObj, string username) { var response = new DepartmentRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage(), }, }; try { var apiResponse = new APIHelper(APIEndpoints.LOAD_DEPARTMENT_ENDPOINT, username, Method.POST).ProcessAPI <DepartmentSearchObj, DepartmentRespObj>(regObj, out var msg); if (msg.Code == 0 && string.IsNullOrEmpty(msg.TechMessage) && string.IsNullOrEmpty(msg.Message)) { return(apiResponse); } response.Status.Message.FriendlyMessage = msg.Message; response.Status.Message.TechnicalMessage = msg.TechMessage; return(response); } catch (Exception ex) { UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; return(response); } }
public DepartmentRespObj LoadDepartments(CommonSettingSearchObj searchObj) { var response = new DepartmentRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { if (searchObj.Equals(null)) { response.Status.Message.FriendlyMessage = "Error Occurred! Unable to proceed with your request"; response.Status.Message.TechnicalMessage = "Registration Object is empty / invalid"; return(response); } if (!EntityValidatorHelper.Validate(searchObj, out var valResults)) { var errorDetail = new StringBuilder(); if (!valResults.IsNullOrEmpty()) { errorDetail.AppendLine("Following error occurred:"); valResults.ForEachx(m => errorDetail.AppendLine(m.ErrorMessage)); } else { errorDetail.AppendLine( "Validation error occurred! Please check all supplied parameters and try again"); } response.Status.Message.FriendlyMessage = errorDetail.ToString(); response.Status.Message.TechnicalMessage = errorDetail.ToString(); response.Status.IsSuccessful = false; return(response); } //if (!HelperMethods.IsUserValid(searchObj.AdminUserId, searchObj.SysPathCode, HelperMethods.getAllRoles(), ref response.Status.Message)) //{ // return response; //} var thisDepartments = GetDepartments(); if (!thisDepartments.Any()) { response.Status.Message.FriendlyMessage = "No Department Information found!"; response.Status.Message.TechnicalMessage = "No Department Information found!"; return(response); } if (searchObj.Status > -1) { thisDepartments = thisDepartments.FindAll(p => p.Status == (ItemStatus)searchObj.Status); } var departmentItems = new List <DepartmentObj>(); thisDepartments.ForEachx(m => { departmentItems.Add(new DepartmentObj { DepartmentId = m.DepartmentId, Name = m.Name, Status = (int)m.Status, StatusLabel = m.Status.ToString().Replace("_", " ") }); }); response.Status.IsSuccessful = true; response.Departments = departmentItems; return(response); } catch (DbEntityValidationException ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); response.Status.Message.FriendlyMessage = "Error Occurred! Please try again later"; response.Status.Message.TechnicalMessage = "Error: " + ex.GetBaseException().Message; response.Status.IsSuccessful = false; return(response); } }