public async Task <bool> Revert(int rentContractId) { RentContract = await Tenant.RentContracts .WhereId(rentContractId) .IncludeStore() .IncludeRentedProducts() .IncludeRentIncomes() .SingleOrDefaultAsync(); if (RentContract == null || !RentContract.Confirmed) { return(false); } ProductConsumption = new ProductConsumption(Tenant, RentContract); await ProductConsumption.Revert(); ProductReplenishment = new ProductReplenishment(Tenant, RentContract); if (!await ProductReplenishment.Revert()) { return(false); } Billing = new RentBilling(Tenant, RentContract); Billing.Revert(); RentContract.ConfirmationDate = null; RentContract.DateOfReturn = null; await Tenant.SaveChangesAsync(); return(true); }
public async Task <bool> Revert(int purchaseOrderId) { PurchaseOrder = await Tenant.PurchaseOrders .WhereId(purchaseOrderId) .IncludeStore() .IncludePurchasedProducts() .IncludePurchaseExpenses() .SingleOrDefaultAsync(); if (PurchaseOrder == null || !PurchaseOrder.Confirmed) { return(false); } ProductReplenishment = new ProductReplenishment(Tenant, PurchaseOrder); if (!await ProductReplenishment.Revert()) { return(false); } PurchaseCost = new PurchaseCost(Tenant, PurchaseOrder); PurchaseCost.Revert(); PurchaseOrder.ConfirmationDate = null; await Tenant.SaveChangesAsync(); return(true); }
public async Task <bool> ProcessReturn(int rentContractId, DateTime dateOfReturn, IEnumerable <RentedProduct> returnedProducts) { RentContract = await Tenant.RentContracts .WhereId(rentContractId) .IncludeStore() .IncludeRentedProducts() .SingleOrDefaultAsync(); if (RentContract == null || !RentContract.Confirmed) { return(false); } if (HasInvalidDateOfReturn = dateOfReturn < RentContract.StartDate) { return(false); } if (!SetQuantitiesFor(returnedProducts)) { return(false); } ProductReplenishment = new ProductReplenishment(Tenant, RentContract); if (!await ProductReplenishment.Revert()) { return(false); } if (!await ProductReplenishment.Confirm()) { return(false); } RentContract.DateOfReturn = dateOfReturn; await Tenant.SaveChangesAsync(); return(true); }