コード例 #1
0
        public async Task <RSOrderItem> AddOrderItem(int id, [FromBody] int productId)
        {
            RSOrder order = await db.Orders.FindAsync(id);

            if (!order.Active) //Disallow editing closed orders
            {
                return(null);
            }

            RSProduct product = await db.Products.FindAsync(productId);

            if (order != null && product != null)
            {
                RSOrderItem oi = new RSOrderItem(product, order);
                db.OrderItems.Add(oi);
                await db.SaveChangesAsync();

                return(new RSOrderItem()
                {
                    Id = oi.Id,
                    Price = oi.Price,
                    State = oi.State,
                    Product = oi.Product != null ? new RSProduct()
                    {
                        Id = oi.Product.Id,
                        Title = oi.Product.Title
                    } : null
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: OrderDetail.xaml.cs プロジェクト: uxsoft/RestSys
        private async void btnRemoveItem_Click(object sender, RoutedEventArgs e)
        {
            RSOrderItem currentItem = lstOrderItems.SelectedItem as RSOrderItem;
            await Service.SetOrderItemState(currentItem.Id, 2);

            currentItem.State         = 2;
            lstOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2);
        }
コード例 #3
0
ファイル: OrderDetail.xaml.cs プロジェクト: uxsoft/RestSys
        private async void navProductMenu_ProductSelected(RSProduct product)
        {
            RSOrderItem orderItem = await Service.AddOrderItem(order.Id, product.Id);

            if (orderItem != null)
            {
                order.Items.Add(orderItem);
                lstOrderItems.ItemsSource = order.Items.Where(oi => oi.State < 2);
            }
            else
            {
                MessageDialog md = new MessageDialog("Položku nelze přidat.", "Přidání položky");
                await md.ShowAsync();
            }
        }
コード例 #4
0
        public async Task <bool> SetOrderItemState(int id, [FromBody] int state)
        {
            RSOrderItem oi = await db.OrderItems.FindAsync(id);

            if (oi != null)
            {
                if (oi.State < 2)
                {
                    oi.State = state;
                    await db.SaveChangesAsync();

                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
ファイル: OrdersController.cs プロジェクト: uxsoft/RestSys
        public async Task <ActionResult> RemoveProduct(int id, int productId)
        {
            RSOrderItem product = await db.OrderItems.FindAsync(productId);

            RSOrder order = await db.Orders.FindAsync(id);

            if (product != null && order != null)
            {
                if (order.Items.Remove(product))
                {
                    db.OrderItems.Remove(product);
                    await db.SaveChangesAsync();

                    return(Json(true));
                }
            }
            throw new HttpException(400, "Error removing item");
        }
コード例 #6
0
ファイル: OrdersController.cs プロジェクト: uxsoft/RestSys
        public async Task <ActionResult> AddProduct(int id, int productId)
        {
            RSProduct product = await db.Products.FindAsync(productId);

            RSOrder order = await db.Orders.FindAsync(id);

            if (product != null && order != null)
            {
                RSOrderItem orderItem = new RSOrderItem(product, order);

                db.OrderItems.Add(orderItem);
                await db.SaveChangesAsync();

                return(Json(true));
            }
            else
            {
                throw new HttpException(400, "Error inserting OrderItem");
            }
        }