public async Task <Result> AddLoanStatus(LoanStatusDto loanStatusToAdd)
        {
            var entity = new LoanStatus
            {
                LoanStatusName = loanStatusToAdd.LoanStatusName
            };

            await _context.LoanStatuses.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(Result.Success("Loan status was created successfully"));
        }
        public async Task <SelectItemVm> GetAllAsSelect(LoanStatusDto loanStatusDto)
        {
            var vm = new SelectItemVm
            {
                SelectItems = await _context.LoanStatuses
                              .Where(x => !x.Deleted && x.LoanStatusName != "Pending" && x.LoanStatusName != "Canceled")
                              .Select(x => new SelectItemDto {
                    Label = x.LoanStatusName, Value = x.Id.ToString()
                })
                              .ToListAsync()
            };

            return(vm);
        }
        public async Task <IActionResult> AddLoanStatus([FromBody] LoanStatusDto loanStatusToAdd)
        {
            if (loanStatusToAdd.LoanStatusName == null)
            {
                return(BadRequest("The loan status name is mandatory!"));
            }
            var result = await _loanStatusService.AddLoanStatus(loanStatusToAdd);

            if (!result.Succeeded)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
        public async Task <Result> DeleteLoanStatus(LoanStatusDto loanStatusToDelete)
        {
            var entity = await _context.LoanStatuses
                         .FirstOrDefaultAsync(x => x.Id == loanStatusToDelete.Id && !x.Deleted);

            if (entity == null)
            {
                return(Result.Failure(new List <string> {
                    "No valid loan status found"
                }));
            }

            entity.Deleted = true;

            await _context.SaveChangesAsync();

            return(Result.Success("Loan status was deleted"));
        }