Exemplo n.º 1
0
        public async Task <IActionResult> PutOrderItem(long id, OrderItemDTO orderItemDTO)
        {
            if (id != orderItemDTO.Id)
            {
                return(BadRequest());
            }

            var orderItem = await _context.OrderItems.FindAsync(id);

            if (orderItem == null)
            {
                return(NotFound());
            }
            orderItem.CustomerId   = orderItemDTO.CustomerId;
            orderItem.CustomerName = orderItemDTO.CustomerName;
            orderItem.IsComplete   = orderItemDTO.IsComplete;

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostDOrder(OrderItemDTO dto)
        {
            var status = await _context.OrderStatus.FirstOrDefaultAsync(s => s.Description == "NEW");

            _context.Entry(status).State = EntityState.Detached;

            var newOrder = new DOrder()
            {
                OpenDate      = DateTime.Now,
                CustomerId    = dto.IdCustomer,
                OrderStatusId = status.Id,
            };

            _context.Order.Add(newOrder);


            try
            {
                await _context.SaveChangesAsync();

                var idOrder = newOrder.Id;

                foreach (DOrderItem item in dto.Items)
                {
                    item.OrderId = idOrder;
                    _context.OrderItem.Add(item);
                    await _context.SaveChangesAsync();
                }
                return(Ok(new { idOrder }));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public bool Post([FromBody] Order NewOrder)
        {
            bool    Success;
            int     OrderID;
            decimal GST;
            decimal HST;
            decimal PST;
            decimal SubTotal;
            decimal Total;

            OrderDataController     OrderDataController      = new OrderDataController();
            OrderItemDataController OrderItemsDataController = new OrderItemDataController();
            List <OrderItemDTO>     OrderItems = new List <OrderItemDTO>();

            foreach (var OrderItem in NewOrder.OrderItems)
            {
            }

            OrderDTO NewOrderDTO = new OrderDTO
            {
                CustomerID      = NewOrder.CustomerID,
                StatusID        = NewOrder.StatusID,
                ShippingID      = NewOrder.ShippingID,
                ShippingAddress = NewOrder.ShippingAddress,
                ShippingPrice   = NewOrder.ShippingPrice,
                SaleDate        = DateTime.Now,
                City            = NewOrder.City,
                PostalCode      = NewOrder.PostalCode,
                Province        = NewOrder.Province,
                PST             = NewOrder.PST,
                HST             = NewOrder.HST,
                GST             = NewOrder.GST,
                SubTotal        = NewOrder.SubTotal,
                Total           = NewOrder.Total
            };

            OrderID = OrderDataController.AddNewOrder(NewOrderDTO);

            foreach (var OrderItem in NewOrder.OrderItems)
            {
                OrderItemDTO NewOrderItem = new OrderItemDTO
                {
                    OrderID        = OrderID,
                    OrderItemPrice = OrderItem.OrderItemPrice,
                    OrderQuantity  = OrderItem.OrderQuantity,
                    InventoryID    = OrderItem.InventoryID
                };
                OrderItems.Add(NewOrderItem);
            }

            Success = true;
            return(Success);
        }