public async Task <IActionResult> UpdateFeeRefundAsync([FromBody] UpdateFeeRefundManagementAc updateFeeRefund) { var user = await _userManager.FindByNameAsync(User.Identity.Name); return(Ok(await _feeRefundManagementRepository.UpdateFeeRefundAsync(updateFeeRefund, user))); }
/// <summary> /// Method to update fee refund - SS /// </summary> /// <param name="updateFeeRefund">fee refund</param> /// <param name="loggedInUser">logged in user</param> /// <returns>response</returns> public async Task <FeeRefundManagementResponse> UpdateFeeRefundAsync(UpdateFeeRefundManagementAc updateFeeRefund, ApplicationUser loggedInUser) { var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true); if (!await _iMSDbContext.UserInstituteMappings.AnyAsync(x => x.InstituteId == instituteId && x.UserId == updateFeeRefund.IssuedById)) { return new FeeRefundManagementResponse() { HasError = true, Message = "Issued-by user not found", ErrorType = FeeRefundManagementErrorType.IssuedById } } ; else { if (string.IsNullOrEmpty(updateFeeRefund.RefundNumber.Trim())) { return new FeeRefundManagementResponse() { HasError = true, Message = "Refund number can't be empty", ErrorType = FeeRefundManagementErrorType.RefundNumber } } ; else if (string.IsNullOrEmpty(updateFeeRefund.ChallanNumber.Trim())) { return new FeeRefundManagementResponse() { HasError = true, Message = "Challan number can't be empty", ErrorType = FeeRefundManagementErrorType.ChallanNumber } } ; else if (string.IsNullOrEmpty(updateFeeRefund.ChequeNumber.Trim())) { return new FeeRefundManagementResponse() { HasError = true, Message = "Cheque number can't be empty", ErrorType = FeeRefundManagementErrorType.ChequeNumber } } ; else if (string.IsNullOrEmpty(updateFeeRefund.BankName.Trim())) { return new FeeRefundManagementResponse() { HasError = true, Message = "Bank name can't be empty", ErrorType = FeeRefundManagementErrorType.BankName } } ; else if (double.IsNaN(updateFeeRefund.Amount)) { return new FeeRefundManagementResponse() { HasError = true, Message = "Amount number can't be empty and should be number", ErrorType = FeeRefundManagementErrorType.Amount } } ; else { var refund = await _iMSDbContext.FeeRefunds.FirstOrDefaultAsync(x => x.Id == updateFeeRefund.Id); if (refund == null) { return new FeeRefundManagementResponse() { HasError = true, Message = "Refund not found", ErrorType = FeeRefundManagementErrorType.Id } } ; else { refund.Amount = updateFeeRefund.Amount; refund.BankName = updateFeeRefund.BankName; refund.ChallanNumber = updateFeeRefund.ChallanNumber; refund.ChequeDate = updateFeeRefund.ChequeDate; refund.ChequeNumber = updateFeeRefund.ChequeNumber; refund.IssuedById = updateFeeRefund.IssuedById; refund.RefundDate = updateFeeRefund.RefundDate; refund.Remark = updateFeeRefund.Remark; refund.UpdatedById = loggedInUser.Id; refund.UpdatedOn = DateTime.UtcNow; _iMSDbContext.FeeRefunds.Update(refund); await _iMSDbContext.SaveChangesAsync(); return(new FeeRefundManagementResponse() { HasError = false, Message = "Fee refund detail added successfully" }); } } } }