示例#1
0
        public async Task <IActionResult> PutVendor(int id, Vendor vendor)
        {
            if (id != vendor.Id)
            {
                return(BadRequest());
            }

            _context.Entry(vendor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VendorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        private async Task recalculatetotal(int requestId)
        {
            var request = await _context.Request.FindAsync(requestId);

            if (request == null)
            {
                throw new Exception("Cannot find request");
            }
            request.Total = (from r in _context.Requestlines
                             join p in _context.Product
                             on r.ProductId equals p.Id
                             where r.RequestId == requestId
                             select new { linetotal = r.Quantity * r.Product.Price }).Sum(lt => lt.linetotal);
            await _context.SaveChangesAsync();
        }