public async Task <PurchaseEntity> SavePurchase(PurchaseEntity purchase) { var orderFromDb = await Query.Where(e => e.Id == purchase.Id).FirstOrDefaultAsync(); if (orderFromDb == null) { return((await SaveEntity(purchase.ToPurchase(null))).ToPurchaseEntity()); } else { return((await SaveEntity(purchase.ToPurchase(orderFromDb))).ToPurchaseEntity()); } }
public async Task <PurchaseEntity> SavePuchase(PurchaseEntity entity) { var _products = entity.ProductList; var _purchase = entity.ToPurchase(); List <ProductEntity> productItems = new List <ProductEntity>(); productItems.AddRange(_products); _purchase.ProductList.Clear(); var removedItem = await _pa.RemoveItemsById(_purchase.Id); var tmp = await SaveEntity(_purchase); for (int i = 0; i <= productItems.Count - 1; i++) { productItems[i].PurchaseId = tmp.Id; var res = (await _pa.SaveProduct(productItems[i])); } var _purchaseById = await GetPurchase(tmp.Id); return(_purchaseById); }