コード例 #1
0
 private static List <OrderItem> OrderItems(SaveOrderResource model)
 {
     return(model.OrderItems.Select(item => OrderItem.Add(item.ProductId,
                                                          item.SparePartId, item.Quantity, item.CompanyId,
                                                          item.ReturnDefective, item.LeftInBag))
            .ToList());
 }
コード例 #2
0
        public async Task <IActionResult> UpdateOrder(int id, [FromBody] SaveOrderResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var orderFromDb = await FindOrderById(id);

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

            orderFromDb.Modify(model.OrderDate, model.EngineerId, OrderItems(model));
            await _unitOfWork.CompleteAsync();

            return(Ok(_mapper.Map <Order, SaveOrderResource>(orderFromDb)));
        }
コード例 #3
0
        public async Task <IActionResult> CreateOrder([FromBody] SaveOrderResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var engineer = await _engineerRepository.GetAsync(model.EngineerId, UserId);

            if (engineer == null)
            {
                throw new ArgumentNullException();
            }

            var newOrder = new Order(model.OrderDate, model.EngineerId, UserId, OrderItems(model));

            _orderRepository.Add(newOrder);
            await _unitOfWork.CompleteAsync();

            return(StatusCode(201));
        }