public async Task <ServiceResponse <Payment> > UpdatePayment(UpdatePaymentDto updatePayment) { ServiceResponse <Payment> serviceResponse = new ServiceResponse <Payment>(); try { var updatedPayment = _context.Payments.First(p => p.Id == updatePayment.Id); if (updatePayment.isTerminated) { updatedPayment.PaymentTermination = DateTime.Now; updatedPayment.StartDate = DateTime.Now; _context.SaveChanges(); serviceResponse.Data = updatedPayment; } else { serviceResponse.Data = null; } } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; } return(serviceResponse); }
public async Task UpdatePayment(UpdatePaymentDto input) { long sellerId = (await GetCurrentSeller()).Id; await SellerManager.UpdatePayment( sellerId, input.Payload, input.SellerPaymentOption ); }
public async Task <IActionResult> UpdatePayment(UpdatePaymentDto updatePayment) { ServiceResponse <Payment> response = await _paymentService.UpdatePayment(updatePayment); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public async Task <bool> UpdateOrderPaymentAsync(UpdatePaymentDto paymentDto) { using var uow = _unitOfWorkManager.Begin(); var invoice = new Invoice { InvoiceDate = DateTime.Now, OrderId = paymentDto.OrderId, PaidAmount = paymentDto.PaidAmount }; var order = _repository.Get(paymentDto.OrderId); await _repository.EnsureCollectionLoadedAsync(order, o => o.OrderDetails); var dueAmount = order.OrderDetails.Sum(s => s.SubTotal) - (order.AdvancePaid.HasValue ? order.AdvancePaid.Value : 0); if (dueAmount < paymentDto.PaidAmount) { throw new Exception("amount exceed"); } else if (paymentDto.PaidAmount == dueAmount) { order.PaymentStatus = PaymentStatus.Paid; } else { order.PaymentStatus = PaymentStatus.PartialPaid; } order.OrderStatus = OrderStatus.Delivered; await _repository.UpdateAsync(order); await _invoiceRepository.InsertAsync(invoice); await uow.CompleteAsync(); return(true); }
public IActionResult Put(int id, [FromBody] UpdatePaymentDto model) => _mapper.Map <PaymentUpdateModel>(model) .Map(x => _commandRepo.Update(id, x)) .Map(x => AllOk(new { updated = x })) .Reduce(_ => NotFound(), error => error is RecordNotFound) .Reduce(_ => InternalServerError(), x => _logger.LogError(x.ToString()));