public async Task ExecuteAsync(int paymentInvoiceId, DeleteChargedPaymentInvoiceDto requestDto) { //Удалить Payment Invoice var paymentInvoiceItem = await _executor.GetHandler <GetPaymentInvoiceByIdQuery>().Process(h => h.ExecuteAsync(paymentInvoiceId)); var user = _executor.GetQuery <GetUserByIdQuery>() .Process(q => q.Execute(NiisAmbientContext.Current.User.Identity.UserId)); var deletionDate = DateTimeOffset.Now; paymentInvoiceItem.IsDeleted = true; paymentInvoiceItem.DeletedDate = deletionDate; paymentInvoiceItem.ReasonOfDeletingChargedPaymentInvoice = requestDto.DeletionReason; paymentInvoiceItem.DateOfDeletingChargedPaymentInvoice = deletionDate; paymentInvoiceItem.EmployeeAndPositonWhoDeleteChargedPaymentInvoice = $"{user.NameRu} {user.Position?.NameRu}"; paymentInvoiceItem.Status = Uow.GetRepository <DicPaymentStatus>() .AsQueryable() .FirstOrDefault(q => q.Code == DicPaymentStatusCodes.Notpaid); paymentInvoiceItem.DateComplete = null; paymentInvoiceItem.WriteOffUser = null; paymentInvoiceItem.WriteOffUserId = null; _executor.GetCommand <UpdatePaymentInvoiceCommand>() .Process(c => c.Execute(paymentInvoiceItem)); //Удалить все Payment Use var paymentUseRequestDto = new DeletePaymentUseRequestDto(); paymentUseRequestDto.DeletionReason = requestDto.DeletionReason; foreach (var pu in paymentInvoiceItem.PaymentUses) { await _executor.GetCommand <DeletePaymentUseCommand>() .Process(c => c.ExecuteAsync(pu.Id, paymentUseRequestDto)); } var ownerType = (Owner.Type)Enum.ToObject(typeof(Owner.Type), requestDto.OwnerType); //експорт в 1С var isExportedTo1C = await _executor.GetHandler <ExportPaymentTo1CHandler>().Process(r => r.ExecuteAsync(ownerType, paymentInvoiceId, PaymentInvoiveChangeFlag.PaymentInvoiceChargedDateIsDeleted, DicPaymentStatusCodes.Charged)); }
public async Task <IActionResult> DeleteChargedPaymentInvoice(int paymentInvoiceId, [FromBody] DeleteChargedPaymentInvoiceDto request) { await Executor.GetHandler <DeleteChargedPaymentInvoiceCommand>().Process(h => h.ExecuteAsync(paymentInvoiceId, request)); return(Ok()); }