예제 #1
0
        public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] ProductDTO product)
        {
            product.OrderDetail = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <Product>(product)).State = EntityState.Modified;

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutEmployee([FromRoute] int id, [FromBody] EmployeeDTO employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <Employee>(employee)).State = EntityState.Modified;

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

            return(NoContent());
        }
        public async Task <IActionResult> PutOrderStatus([FromRoute] int id, [FromBody] OrderStatusDTO orderStatus)
        {
            orderStatus.CustomerOrder = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderStatus.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <OrderStatus>(orderStatus)).State = EntityState.Modified;

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

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> PostOrderDetail([FromBody] List <OrderDetailDTO> orderDetail)
        {
            foreach (var item in orderDetail)
            {
                item.CustomerOrder = null;
                item.Product       = null;
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var od = Mapper.Map <IEnumerable <OrderDetail> >(orderDetail);

            _context.OrderDetail.AddRange(od);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOrderDetail", new { id = od.First().CustomerOrderId }, orderDetail));
        }
        public async Task <IActionResult> PutCustomerOrder([FromRoute] int id, [FromBody] CustomerOrderDTO customerOrder)
        {
            customerOrder.OrderDetail = null;
            customerOrder.OrderStatus = null;
            customerOrder.Customer    = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customerOrder.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Mapper.Map <CustomerOrder>(customerOrder)).State = EntityState.Modified;

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

            return(NoContent());
        }