Esempio n. 1
0
        public async Task <IHttpActionResult> GetGoodsReceipt(Guid id)
        {
            var goodsReceipt = await _db.GoodsReceipts
                               .FirstOrDefaultAsync(g => g.GoodsReceiptGuid == id && g.GoodsReceiptDeleted == false);

            var goodsReceiptItems = await _db.GoodsReceiptItems
                                    .Include(o => o.GoodsReceiptItemSupplyItem)
                                    .Include(s => s.GoodsReceiptItemSupplyItem.SupplyItemStockItem)
                                    .Include(p => p.GoodsReceiptItemSupplyItem.SupplyItemStockItem.StockItemProduct)
                                    .Where(dn => dn.GoodsReceiptItemGoodsReceipt.GoodsReceiptGuid == id)
                                    .ToListAsync();

            var goodsReceiptViewModel = new GoodsReceiptDetailsViewModel
            {
                GoodsReceipt      = goodsReceipt,
                GoodsReceiptItems = goodsReceiptItems
            };

            if (goodsReceiptItems == null)
            {
                return(NotFound());
            }

            return(Ok(goodsReceiptViewModel));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PutGoodsReceipt(GoodsReceiptDetailsViewModel goodsReceiptDetailsVm, Guid id)
        {
            if (!ModelState.IsValid)
            {
                foreach (var v in ModelState.Values)
                {
                    foreach (var e in v.Errors)
                    {
                        if (e.Exception != null)
                        {
                            return
                                (BadRequest(
                                     "Something went wrong. Please check your form fields for disallowed or missing values."));
                        }
                    }
                }

                return(BadRequest(ModelState));
            }

            if (id != goodsReceiptDetailsVm.GoodsReceipt.GoodsReceiptGuid)
            {
                return(BadRequest());
            }


            foreach (var d in goodsReceiptDetailsVm.GoodsReceiptItems)
            {
                var deliveryItem =
                    await _db.GoodsReceiptItems.FirstOrDefaultAsync(
                        g => g.GoodsReceiptItemGuid == d.GoodsReceiptItemGuid);

                deliveryItem.GoodsReceiptItemQuantity = d.GoodsReceiptItemQuantity;
                _db.Entry(deliveryItem).State         = EntityState.Modified;
            }

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GoodsReceiptExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }