示例#1
0
        public PartialViewResult ProductOrder()
        {
            var model = new ProductOrderModel();

            model.Products = _mapper.Map <List <ProductModel> >(_productRepository.GetProducts());
            return(PartialView("ProductOrder", model));
        }
示例#2
0
 public string UpdateImei(ProductOrderModel data)
 {
     if (Session["login"] is null)
     {
         return(null);
     }
     using (THUONGMAIDIENTUEntities db = new THUONGMAIDIENTUEntities())
     {
         var product = db.PRODUCT_ORDER.Where(x => x.IdOrder == data.IdOrder && x.IdProduct == data.IdProduct).FirstOrDefault();
         if (product is null)
         {
             return("Không tìm thấy đối tượng này");
         }
         try
         {
             var order = db.ORDERs.Where(x => x.IdOrder == data.IdOrder).FirstOrDefault();
             if (order.IdStatus == 5 || order.IdStatus == 4)
             {
                 throw new Exception("Đơn hàng này đã không giao được");
             }
             product.IMEI = data.IMEI;
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             return(ex.Message);
         }
     }
     return("ok");
 }
        public ActionResult AddProduct([Bind(Include = "OrderId,OrderStatus,TimeStamp,Tables,TableIds,ProductIds,ProductString")] OrderViewModel orderViewModel)
        {
            if (ModelState.IsValid)
            {
                OrderModel order = db.Orders.Include("Tables").First(x => x.OrderId == orderViewModel.OrderId);

                if (orderViewModel.ProductString != null)
                {
                    List <string> products = orderViewModel.ProductString.Split(';').ToList();
                    products.Remove(string.Empty);
                    foreach (string product in products)
                    {
                        ProductOrderModel productOrder = new ProductOrderModel
                        {
                            Product            = db.Products.Find(int.Parse(product)),
                            ProductOrderStatus = Status.Preparing,
                        };
                        db.ProductOrders.Add(productOrder);
                        db.SaveChanges();
                        order.Products.Add(productOrder);
                    }
                }
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = order.OrderId }));
            }

            return(View(orderViewModel));
        }
示例#4
0
        public ActionResult GetDataOrderBox()
        {
            var cart = (List <CartModel>)Session[CartSession.CartSesstion];
            ProductOrderModel order = new ProductOrderModel();

            if (cart != null && cart.Count != 0)
            {
                foreach (var item in cart)
                {
                    order.Provisional += item.SOLUONG * item.SANPHAM.GIABAN;
                }
                if (order.Provisional > 300000)
                {
                    order.DeliveryCharges = 0;
                    order.Total          += order.Provisional;
                }
                else
                {
                    order.DeliveryCharges = 30000;
                    order.Total           = order.Provisional + 30000;
                }
            }
            else
            {
                order.Provisional     = 0;
                order.DeliveryCharges = 0;
                order.Total           = 0;
            }
            return(Json(order, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        public ActionResult History()
        {
            int userId = int.Parse(Session["User_ID"].ToString());
            IEnumerable <ProductDTO> products = this.orderService.GetAllProducts();
            IEnumerable <OrderDTO>   orders   = this.orderService.GetAllOrders().Where(e => e.userId == userId);

            List <ProductOrderModel> productOrderModels = (from pr in products
                                                           from o in orders
                                                           where pr.productId == o.productId && o.payed == true
                                                           select new ProductOrderModel(pr.productId, o.userId, pr.title, pr.price, pr.category, pr.commentsEnabled, o.quantity, o.payed, o.quantity * pr.price)).ToList();

            List <ProductOrderModel> uniqueOrders = new List <ProductOrderModel>();

            for (int i = 0; i < productOrderModels.Count; i++)
            {
                bool found = false;
                for (int k = 0; k < uniqueOrders.Count; k++)
                {
                    if (productOrderModels[i].title == uniqueOrders[k].title)
                    {
                        int new_quant = uniqueOrders[k].quantity + productOrderModels[i].quantity;
                        uniqueOrders[k] = new ProductOrderModel(uniqueOrders[k].productId, uniqueOrders[k].userId, uniqueOrders[k].title, uniqueOrders[k].price, uniqueOrders[k].category, uniqueOrders[k].commentsEnabled, new_quant, uniqueOrders[k].payed, uniqueOrders[k].price * new_quant);
                        found           = true;
                    }
                }
                if (found == false)
                {
                    uniqueOrders.Add(productOrderModels[i]);
                }
            }
            IEnumerable <ProductOrderModel> viewModels = uniqueOrders;

            return(View(viewModels));
        }
示例#6
0
        public ActionResult DeleteConfirmed(int id)
        {
            ProductOrderModel productOrderModel = db.ProductOrders.Find(id);

            db.ProductOrders.Remove(productOrderModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#7
0
 public ActionResult Edit([Bind(Include = "ProductOrderId,ProductOrderStatus")] ProductOrderModel productOrderModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productOrderModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productOrderModel));
 }
示例#8
0
        public ActionResult Create([Bind(Include = "ProductOrderId,ProductOrderStatus")] ProductOrderModel productOrderModel)
        {
            if (ModelState.IsValid)
            {
                db.ProductOrders.Add(productOrderModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productOrderModel));
        }
        public IActionResult Order(int?id)
        {
            if (!id.HasValue)
            {
                ViewBag.BadRequestMessage = "Product Id is Null";
                return(View("BadRequest"));
            }
            ProductOrderModel productOrderModel = _orderService.GetProductOrderModel(id.Value);

            return(View(productOrderModel));
        }
        public static int CreateProductOrder(int id, int productid, int orderid)
        {
            db = new Database();
            ProductOrderModel data = new ProductOrderModel()
            {
                ProductId = productid,
                OrderId   = orderid,
            };

            return(ProductOrderDao.Insert(db, data));
        }
        public void CreateOrder(ProductOrderModel productOrderModel)
        {
            using (UnitOfWork unitOfWork = _unitOfWorkFactory.Create())
            {
                Product product = unitOfWork.Products.GetById(productOrderModel.ProductId);
                Order   order   = Mapper.Map <Order>(productOrderModel);
                order.Data   = DateTime.Now;
                order.Amount = product.Price * order.Count;

                unitOfWork.Orders.Create(order);
            }
        }
        private static Collection <ProductOrderModel> Read(SqlDataReader reader)
        {
            Collection <ProductOrderModel> orders = new Collection <ProductOrderModel>();

            while (reader.Read())
            {
                int i = -1;
                ProductOrderModel order = new ProductOrderModel();
                order.ProductId = reader.GetInt32(++i);
                order.OrderId   = reader.GetInt32(++i);
                orders.Add(order);
            }
            return(orders);
        }
        public static int Insert(Database db, ProductOrderModel orders)
        {
            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            PrepareCommand(command, orders);

            int ret = db.ExecuteNonQuery(command);

            db.Close();

            return(ret);
        }
示例#14
0
        // GET: ProductOrderModel/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductOrderModel productOrderModel = db.ProductOrders.Find(id);

            if (productOrderModel == null)
            {
                return(HttpNotFound());
            }
            return(View(productOrderModel));
        }
示例#15
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductOrderModel = await _context.ProductOrderModel.FirstOrDefaultAsync(m => m.OrderProductId == id);

            if (ProductOrderModel == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#16
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProductOrderModel = await _context.ProductOrderModel.FindAsync(id);

            if (ProductOrderModel != null)
            {
                _context.ProductOrderModel.Remove(ProductOrderModel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#17
0
        public ActionResult DishDone(int id)
        {
            ProductOrderModel productOrder = db.ProductOrders.Include("Product").First(x => x.ProductOrderId == id);
            FoodType          foodType     = productOrder.Product.ProductType;

            productOrder.ProductOrderStatus = Status.Done;
            db.Entry(productOrder).State    = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            if ((int)foodType > 2)
            {
                return(RedirectToAction("Kitchen"));
            }
            else
            {
                return(RedirectToAction("Bar"));
            }
        }
示例#18
0
        static void addToStore(ProductModel product, int Quantity)
        {
            ProductOrderModel orderModel = new ProductOrderModel
            {
                ID              = Guid.NewGuid().ToString(),
                Name            = product.Name,
                Quantity        = Quantity,
                Price           = product.UnitPrice,
                DiscountType    = DiscountType.None,
                DiscountPercent = 0.0m
            };

            if (product.Discount != null)
            {
                if (orderModel.Quantity >= product.Discount.MinQuantity && product.Discount.DiscountType != DiscountType.None)
                {
                    orderModel.DiscountPercent = product.Discount.DiscountInPercent;
                    orderModel.DiscountType    = product.Discount.DiscountType;
                }
            }
            Cart.Add(orderModel);
        }
示例#19
0
        public async Task CreateOrder()
        {
            try
            {
                OrderCreatedModel order = new OrderCreatedModel()
                {
                    TotalValue   = CheckoutItems.TotalValue,
                    OrderDate    = DateTime.Now,
                    IdStateOrder = 1,
                    IdClient     = CheckoutItems.IdClient,
                    Products     = new List <ProductOrderModel>()
                };
                foreach (var item in CheckoutItems.Products)
                {
                    ProductOrderModel P = new ProductOrderModel
                    {
                        IdProduct      = item.IdProduct,
                        QuantityBought = item.QuantitySelected
                    };
                    order.Products.Add(P);
                }
                APIResponse response = await PostOrder.ExecuteStrategy(order);

                if (response.IsSuccess)
                {
                    var savedList = new List <Tuple <long, int> >();
                    Settings.listProductsCart = savedList;
                    await NavigationService.PopPage();

                    await NavigationService.PopPage();

                    await NavigationService.PopPage();
                }
            }
            catch (Exception e)
            {
            }
        }
 public IActionResult OrderAnother(ProductOrderModel order)
 {
     _orderService.CreateOrder(order);
     return(RedirectToAction("Index"));
 }
示例#21
0
 public int Post([FromBody] ProductOrderModel model)
 {
     return(ProductOrderProcessor.CreateProductOrder(model.Id, model.ProductId, model.OrderId));
 }
 private static void PrepareCommand(SqlCommand command, ProductOrderModel product)
 {
     command.Parameters.AddWithValue("@ProductId", product.ProductId);
     command.Parameters.AddWithValue("@OrderId", product.OrderId);
 }