コード例 #1
0
        public async Task <IActionResult> PutProductOrders(int id, ProductOrders productOrders)
        {
            if (id != productOrders.ID)
            {
                return(BadRequest());
            }

            _context.Entry(productOrders).State = EntityState.Modified;

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductOrderId,ProductId,OrderId,Quantity")] ProductOrders productOrders)
        {
            if (id != productOrders.ProductOrderId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productOrders);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductOrdersExists(productOrders.ProductOrderId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "OrderId", "OrderId", productOrders.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "Name", productOrders.ProductId);
            return(View(productOrders));
        }
コード例 #3
0
        public async Task <ActionResult <ProductOrders> > PostProductOrders(ProductOrders productOrders)
        {
            _context.ProductOrders.Add(productOrders);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProductOrders", new { id = productOrders.ID }, productOrders));
        }
コード例 #4
0
        public int CorrectPriority(int priority)
        {
            if (priority <= 0)
            {
                return(1);
            }

            int count = ProductOrders.Count();

            return(priority > count ? count : priority);
        }
コード例 #5
0
        public static XtraReport ProductOrders(IEnumerable <OrderItem> sales, IList <State> states, bool sortByOrderDate, DateTime fromDate, DateTime toDate)
        {
            var report = new ProductOrders();

            report.DataSource = sales;
            report.SetStates(states);
            report.Parameters["paramOrderDate"].Value = sortByOrderDate;
            report.Parameters["paramFromDate"].Value  = fromDate;
            report.Parameters["paramToDate"].Value    = toDate;
            return(report);
        }
コード例 #6
0
    static XtraReport CreateProductOrdersReport(long productID)
    {
        var report  = new ProductOrders();
        var product = DataProvider.Products.FirstOrDefault(p => p.Id == productID);

        if (product != null)
        {
            report.DataSource = product.OrderItems;
        }
        report.SetStates(DataProvider.States.ToList());
        return(report);
    }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("ProductOrderId,ProductId,OrderId,Quantity")] ProductOrders productOrders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productOrders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.Orders, "OrderId", "OrderId", productOrders.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "Name", productOrders.ProductId);
            return(View(productOrders));
        }
コード例 #8
0
        // GET: Products
        public ActionResult Index(int?productId)
        {
            var viewModel = new ProductOrders();

            viewModel.Products = db.Products.Include(i => i.Orders);

            if (productId != null)
            {
                ViewBag.productId = productId.Value;
                viewModel.Orders  = viewModel.Products.Where(
                    i => i.productId == productId.Value).Single().Orders;
            }


            return(View(viewModel));
        }
コード例 #9
0
        // GET: Customers
        public ActionResult Index(int?id, int?customerId)
        {
            //var view = db.Customer.Include(c => c.Orders);
            //return View();
            var viewModel = new ProductOrders();

            viewModel.Customers = db.Customer;

            if (customerId != null)
            {
                ViewBag.customerId = customerId.Value;
                viewModel.Orders   = viewModel.Customers.Where(
                    i => i.customerId == customerId.Value).Single().Orders;
            }


            //  .Include(i => i.Orders)
            //  .OrderBy(i => i.lastname);
            //return view(viewModel);
            return(View(viewModel));
        }
コード例 #10
0
 public ActionResult Order(OrderViewModel orderViewModel)
 {
     if (ModelState.IsValid)
     {
         using (ShopDbDataContext db = new ShopDbDataContext())
         {
             Orders newOrder = new Orders
             {
                 UserId      = orderViewModel.UserId,
                 Address     = orderViewModel.Address,
                 Phone       = orderViewModel.Phone,
                 Price       = orderViewModel.Price,
                 DateOfOrder = DateTime.Now
             };
             db.Orders.InsertOnSubmit(newOrder);
             db.SubmitChanges();
             foreach (var product in orderViewModel.ProductsToBuy)
             {
                 ProductOrders newProductOrder = new ProductOrders
                 {
                     OrderId   = newOrder.Id,
                     ProductId = int.Parse(product.Key),
                     Quantity  = int.Parse(product.Value)
                 };
                 db.ProductOrders.InsertOnSubmit(newProductOrder);
             }
             var cartToDelete = db.Carts.Where(c => c.UserId == orderViewModel.UserId);
             db.Carts.DeleteAllOnSubmit(cartToDelete);
             db.SubmitChanges();
         }
         return(View("OrderDone"));
     }
     else
     {
         return(View(orderViewModel));
     }
 }
コード例 #11
0
        public IActionResult addItemToCart(int id)
        {
            //this section should go in the add cart button

            //create a new order for the guest user
            Order newOrder = new Order
            {
                OrderNumber = HttpContext.Session.GetString("guid"),
                // total = Product.Price,
                status = "not processed",
            };

            dbContext.Orders.Add(newOrder);
            dbContext.SaveChanges();

            //search db for the product
            Product ProductFromDB = dbContext.Products.FirstOrDefault(p => p.ProductId == id);
            //search for the order with guid so we  can get the id of order
            Order OrderFromdb = dbContext.Orders.FirstOrDefault(o => o.OrderNumber == HttpContext.Session.GetString("guid"));
            //point product to order


            ProductOrders newProductOrder = new ProductOrders
            {
                OrderId = OrderFromdb.OrderId,
                // total = Product.Price,
                ProductId = ProductFromDB.ProductId,
            };

            dbContext.ProductOrders.Add(newProductOrder);
            dbContext.SaveChanges();


            System.Console.WriteLine("//////////////////////////");
            return(RedirectToAction("DisplayProductPage", "UserPage", new{ id = 1 }));
        }
コード例 #12
0
 public Task <ActionResult <ProductOrders> > GetOrders(ProductOrders productOrders)
 {
     return(null);
 }