示例#1
0
        public ActionResult DoOrder(Order model, bool isProduct = false, string returnUrl = "", int numberDesign = 0)
        {
            if (ModelState.IsValid)
            {

                if (CurrentUser != null) model.CreateBy = CurrentUser.Id;
                model.CreateDate = DateTime.Now;

                var product = db.Product.FirstOrDefault(m => m.Id == model.ProductId);
                if (isProduct)
                {
                    model.Price = product.Price;
                }
                else
                {
                    // Công thêm phần config
                    decimal priceAddDesign;
                    try
                    {
                        priceAddDesign = Convert.ToDecimal(new ConfigController().GetByCode(Constant.CODE_PRICE_DESIGN));
                    }
                    catch (Exception)
                    {

                        priceAddDesign = 0;
                    }
                    numberDesign = Regex.Matches(model.JsonDesign, Constant.PARAMETER_DESIGN).Count - 2;

                    // Cộng thêm 1 phần trong config
                    model.Price = (product.Price + priceAddDesign * numberDesign) * model.Quantity;
                }
                db.Order.Add(model);
                db.SaveChanges();

                SessionUtilities.Set(Constant.SESSION_ORDER_SUCCESS, "Order thành công");
                return RedirectToAction("OrderSuccess");
            }
            ModelState.AddModelError("*", "Có lỗi xảy ra. Mời bạn kiểm tra lại thông tin đầu vào!");

            ViewBag.ReturnUrl = returnUrl;
            ViewBag.messFacebook = new ConfigController().GetByCode(Constant.CODE_MESS_FACEBOOK);
            return View(model);
        }
示例#2
0
        public ActionResult Order(int productId, string recreation_design = "", string returnUrl = "", bool isProduct = false)
        {
            var product = db.Product.FirstOrDefault(m => m.Id == productId);
            if (product == null) return RedirectToAction("Index");

            int numberDesign = 0;
            ViewBag.messFacebook = new ConfigController().GetByCode(Constant.CODE_MESS_FACEBOOK);
            ViewBag.Product = product;

            var order = new Order
            {
                DateLine = DateTime.Now.AddDays(1),
                NumberDesign = numberDesign,
                IsProduct = isProduct
            };
            if (isProduct)
            {
                order.ProductId = productId;
                order.Price = product.Price;
                return View(order);
            }
            else
            {
                decimal priceAddDesign;
                try
                {
                    priceAddDesign = Convert.ToDecimal(new ConfigController().GetByCode(Constant.CODE_PRICE_DESIGN));
                }
                catch (Exception)
                {

                    priceAddDesign = 0;
                }
                numberDesign = Regex.Matches(recreation_design, Constant.PARAMETER_DESIGN).Count - 2;
                // Cộng thêm 1 phần trong config
                order.Price = product.Price + priceAddDesign * numberDesign;
                order.JsonDesign = recreation_design;
            }
            return View(order);
        }