Exemplo n.º 1
0
        public void Add(OrderDetailRegisterModel model)
        {
            _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} started");
            var product = _repositories.Products.GetSingle(u => u.ProductId == model.ProductId);

            if (product == null)
            {
                throw new LogicException("Wrong productId");
            }
            var order = _repositories.Orders.GetSingle(u => u.OrderId == model.OrderId);

            if (order == null)
            {
                throw new LogicException("Wrong OrderId");
            }
            _repositories.OrderDetails.Add(new OrderDetail
            {
                Discount  = model.Discount,
                OrderId   = model.OrderId,
                ProductId = model.ProductId,
                Quantity  = model.Quantity,
                UnitPrice = model.UnitPrice
            });
            _repositories.SaveChanges();
            _logger.LogInformation($"{MethodBase.GetCurrentMethod().Name} finished");
        }
Exemplo n.º 2
0
 public IActionResult Post(OrderDetailRegisterModel model)
 {
     if (ModelState.IsValid)
     {
         _orderDetailOperations.Add(model);
     }
     else
     {
         return(BadRequest("Not all parameters have filled"));
     }
     return(Created("", model));
 }