public async Task <ActionResult <ExposureRespObj> > AddUpdateCreditCategory([FromBody] ExposureObj model) { try { var identity = await _serverRequest.UserDataAsync(); var user = identity.UserName; model.CreatedBy = user; var isDone = await _exposure.AddUpdateExposureParameter(model); return(new ExposureRespObj { Status = new APIResponseStatus { IsSuccessful = isDone ? true : false, Message = new APIResponseMessage { FriendlyMessage = isDone ? "successful" : "Unsuccessful" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new ExposureRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }
public async Task <bool> AddUpdateExposureParameter(ExposureObj entity) { try { if (entity == null) { return(false); } if (entity.ExposureParameterId > 0) { var exposureExist = _dataContext.credit_exposureparament.Find(entity.ExposureParameterId); if (exposureExist != null) { exposureExist.CustomerTypeId = entity.CustomerTypeId; exposureExist.Description = entity.Description; exposureExist.Percentage = entity.Percentage; exposureExist.ShareHolderAmount = entity.ShareHolderAmount; exposureExist.Amount = (entity.Percentage / 100) * entity.ShareHolderAmount; exposureExist.Active = true; exposureExist.Deleted = false; exposureExist.UpdatedBy = entity.CreatedBy; exposureExist.UpdatedOn = DateTime.Now; } } else { var exposure = new credit_exposureparament { ExposureParameterId = entity.ExposureParameterId, CustomerTypeId = entity.CustomerTypeId, Description = entity.Description, Percentage = entity.Percentage, ShareHolderAmount = entity.ShareHolderAmount, Amount = (entity.Percentage / 100) * entity.ShareHolderAmount, Active = true, Deleted = false, CreatedBy = entity.CreatedBy, CreatedOn = DateTime.Now, }; _dataContext.credit_exposureparament.Add(exposure); } var response = await _dataContext.SaveChangesAsync() > 0; return(response); } catch (Exception ex) { throw ex; } }