Beispiel #1
0
        public IActionResult PostOrder(OrderDTO orderDTO)
        {
            try
            {
                var buyer   = uEngine.GetUser(this.User.FindFirst(ClaimTypes.Email).Value);
                var product = pEngine.GetProduct(orderDTO.ProductId);

                if (product.Quantity == 0)
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, product));
                }
                else if (orderDTO.Quantity > product.Quantity)
                {
                    return(Conflict(product));
                }
                else
                {
                    var order = engine.PlaceOrder(buyer, orderDTO);
                    return(CreatedAtAction("GetOrder", new { id = order.Id }, order));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
 public IActionResult GetProduct(Guid id)
 {
     try
     {
         var product = engine.GetProduct(id);
         if (product != null)
         {
             return(Ok(product));
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }