public IActionResult Post([FromBody] OrderItemViewModel model)
        {
            //add it to the db
            try
            {
                if (ModelState.IsValid)
                {
                    var newOrderItem = _mapper.Map <OrderItemViewModel, OrderItem>(model);

                    _repository.AddEntity(newOrderItem);
                    if (_repository.SaveAll())
                    {
                        return(Created($"/api/orders/{newOrderItem.Id}", _mapper.Map <OrderItem, OrderItemViewModel>(newOrderItem)));
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to save a new order: {ex}");
            }
            return(BadRequest("Failed to save new order"));
        }
예제 #2
0
 public IActionResult Create(Order model)
 {
     db.AddEntity(model);
     return(View());
 }