예제 #1
0
        //public async Task<bool> AddUpdateLoanStagingAsync(credit_loanstaging model)
        //{
        //    try
        //    {
        //        if (model.LoanStagingId > 0)
        //        {
        //            var itemToUpdate = await _dataContext.credit_loanstaging.FindAsync(model.LoanStagingId);
        //            _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
        //        }
        //        else
        //            await _dataContext.credit_loanstaging.AddAsync(model);
        //        return await _dataContext.SaveChangesAsync() > 0;
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}

        public async Task AddOrUpdateLoanStagingAsync(LoanStagingObj loanStagingViewModel)
        {
            if (loanStagingViewModel.LoanStagingId > 0)
            {
                var loanstaging = await _dataContext.credit_loanstaging.FirstOrDefaultAsync(x => x.LoanStagingId == loanStagingViewModel.LoanStagingId);

                loanstaging.LoanStagingId   = loanStagingViewModel.LoanStagingId;
                loanstaging.ProbationPeriod = loanStagingViewModel.ProbationPeriod;
                loanstaging.From            = loanStagingViewModel.From;
                loanstaging.To        = loanStagingViewModel.To;
                loanstaging.Active    = true;
                loanstaging.Deleted   = false;
                loanstaging.UpdatedBy = loanStagingViewModel.UpdatedBy;
                loanstaging.UpdatedOn = DateTime.Now;
            }
            else
            {
                var newLoanStaging = new credit_loanstaging
                {
                    LoanStagingId   = loanStagingViewModel.LoanStagingId,
                    ProbationPeriod = loanStagingViewModel.ProbationPeriod,
                    From            = loanStagingViewModel.From,
                    To        = loanStagingViewModel.To,
                    Active    = true,
                    Deleted   = false,
                    CreatedBy = loanStagingViewModel.CreatedBy,
                    CreatedOn = DateTime.Now,
                    UpdatedBy = loanStagingViewModel.CreatedBy,
                    UpdatedOn = DateTime.Now,
                };
                _dataContext.credit_loanstaging.Add(newLoanStaging);
            }

            await _dataContext.SaveChangesAsync();
        }
예제 #2
0
        public async Task <ActionResult <LoanStagingRegRespObj> > AddUpDateAccountType([FromBody] LoanStagingObj model)
        {
            try
            {
                LoanStagingObj item = null;
                if (model.LoanStagingId > 0)
                {
                    item = await _repo.GetLoanStagingByIdAsync(model.LoanStagingId);

                    if (item == null)
                    {
                        return new LoanStagingRegRespObj
                               {
                                   Status = new APIResponseStatus {
                                       IsSuccessful = false, Message = new APIResponseMessage {
                                           FriendlyMessage = "Item does not Exist"
                                       }
                                   }
                               }
                    }
                    ;
                }
                var user = await _identityServer.UserDataAsync();

                var createdBy = user.UserName;

                model.CreatedBy = createdBy;
                model.UpdatedBy = createdBy;

                await _repo.AddOrUpdateLoanStagingAsync(model);

                return(new LoanStagingRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = true, Message = new APIResponseMessage {
                            FriendlyMessage = "Successful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                return(new LoanStagingRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }