Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        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);
        }