public bool AddUpdateLoanCustomerFSCaption(LoanCustomerFSCaptionObj entity) { try { if (entity == null) { return(false); } credit_loancustomerfscaption fsCaption = null; if (entity.FSCaptionId > 0) { fsCaption = _dataContext.credit_loancustomerfscaption.Find(entity.FSCaptionId); if (fsCaption != null) { fsCaption.FSCaptionName = entity.FSCaptionName; fsCaption.FSCaptionGroupId = entity.FSCaptionGroupId; fsCaption.Active = true; fsCaption.Deleted = false; fsCaption.UpdatedBy = entity.CreatedBy; fsCaption.UpdatedOn = DateTime.Now; } } else { fsCaption = new credit_loancustomerfscaption { FSCaptionName = entity.FSCaptionName, FSCaptionGroupId = entity.FSCaptionGroupId, Active = true, Deleted = false, CreatedBy = entity.CreatedBy, CreatedOn = DateTime.Now, }; _dataContext.credit_loancustomerfscaption.Add(fsCaption); } var response = _dataContext.SaveChanges() > 0; return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult <LoanCustomerFSCaptionGroupRespObj> > AddUpdateLoanCustomerFSCaption([FromBody] LoanCustomerFSCaptionObj model) { try { var identity = await _identityServer.UserDataAsync(); var user = identity.UserName; model.CreatedBy = user; model.UpdatedBy = user; if (model.FSCaptionGroupId == 0) { if (_repo.ValidateFSCaption(model.FSCaptionName)) { return(new LoanCustomerFSCaptionGroupRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = $"Record with Caption {model.FSCaptionName} already exist" } } }); } } var response = _repo.AddUpdateLoanCustomerFSCaption(model); if (response) { return(new LoanCustomerFSCaptionGroupRespObj { Status = new APIResponseStatus { IsSuccessful = true, Message = new APIResponseMessage { FriendlyMessage = $"Record saved successfully." } } }); } return(new LoanCustomerFSCaptionGroupRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Record not saved" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new LoanCustomerFSCaptionGroupRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }