Пример #1
0
        public async Task <IActionResult> PostSaleOrder([FromBody] SaleOrderEditDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var saleOrder = SaleOrder.Create(dto.CustomerID);

            saleOrder.UpdateItems(dto.Items);
            _context.SaleOrders.Add(saleOrder);
            await _context.SaveChangesAsync();

            return(this.AlpsActionOk());
        }
Пример #2
0
        public async Task <IActionResult> PutSaleOrder([FromRoute] Guid id, [FromBody] SaleOrderEditDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dto.ID)
            {
                return(BadRequest());
            }
            var saleOrder = _context.SaleOrders.Include(p => p.Items).FirstOrDefault(p => p.ID == id);

            if (saleOrder == null)
            {
                return(BadRequest());
            }

            _context.Entry(saleOrder).CurrentValues.SetValues(dto);
            saleOrder.UpdateItems(dto.Items);

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

            return(NoContent());
        }