public SettingRegRespObj AddkPIndex(RegKPIndexObj regObj) { var response = new SettingRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage() } }; try { if (regObj.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(regObj, 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(regObj.AdminUserId, regObj.SysPathCode, HelperMethods.getSeniorAccountant(), ref response.Status.Message)) { return(response); } if (IskPIndexDuplicate(regObj.Name, 1, ref response)) { return(response); } if (regObj.MinRating > regObj.MaxRating) { response.Status.Message.FriendlyMessage = "Minimum Rating cannot be higher than Maximum Rating"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } if (regObj.MinRating == regObj.MaxRating) { response.Status.Message.FriendlyMessage = "Minimum/Maximum Rating cannot be equal to each other"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } var kPIndex = new KPIndex { Name = regObj.Name, Indicator = regObj.Indicator, MinRating = regObj.MinRating, MaxRating = regObj.MaxRating, Status = (ItemStatus)regObj.Status }; var added = _repository.Add(kPIndex); _uoWork.SaveChanges(); if (added.KPIndexId < 1) { response.Status.Message.FriendlyMessage = "Error Occurred! Unable to complete your request. Please try again later"; response.Status.Message.TechnicalMessage = "Unable to save to database"; return(response); } resetCache(); response.Status.IsSuccessful = true; response.SettingId = added.KPIndexId; } 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); } return(response); }