public async Task <bool> Process(int purchaseOrderId) { PurchaseOrder = await Tenant.PurchaseOrders .WhereId(purchaseOrderId) .IncludeStore() .IncludePurchasePayments() .IncludePurchasedProducts() .SingleOrDefaultAsync(); if (PurchaseOrder == null || PurchaseOrder.Confirmed || PurchaseOrderIsPending()) { return(false); } ProductReplenishment = new ProductReplenishment(Tenant, PurchaseOrder); if (!await ProductReplenishment.Confirm()) { return(false); } PurchaseCost = new PurchaseCost(Tenant, PurchaseOrder); PurchaseCost.Confirm(); PurchaseOrder.ConfirmationDate = DateTime.UtcNow; 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); }