Ejemplo n.º 1
0
        public IActionResult Checkout(Order order)
        {
            var createOrder = new CreateOrder(context, cart);

            if (cart.CartItems == null)
            {
                ModelState.AddModelError("", "Товары не добавлены");
            }

            if (ModelState.IsValid)
            {
                createOrder.Create(order);
                cart.Clear();
                return(RedirectToAction("Complite", order));
            }
            return(View(order));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Prefix = "Item")] CreateOrder model)
        {
            #region 检验输入的会员是否正确
            if (!string.IsNullOrWhiteSpace(Request.Form["txtSearch"]))
            {
                string searchtext = Request.Form["txtSearch"];

                if (searchtext.IndexOf("-->") > 0)
                {
                    var text    = Request.Form["txtSearch"].Split("-->".ToArray());
                    var account = AccountService.GetByName(text[text.Length - 1]);
                    var user    = MenbershipService.QueryUsers <AccountUser>(new UserRequest()
                    {
                        DisplayNameWith = text[0]
                    });
                    if (account == null && user.Count() < 1)
                    {
                        model.AddMsg("系统没有找到会员信息,请重新输入!");
                        model.Read();
                        model.Ready();
                        return(View(new EcardModelItem <CreateOrder>(model, model)));
                    }
                    else
                    {
                        if (account == null)
                        {
                            if (user.Count() > 1)
                            {
                                model.AddMsg("根据" + text[0] + "查到不止一个会员,系统无法确定订单所属会员。");
                                model.Read();
                                model.Ready();
                                return(View(new EcardModelItem <CreateOrder>(model, model)));
                            }
                            else
                            {
                                model.AccountId = AccountService.QueryByOwnerId(user.First()).First().AccountId;
                            }
                        }
                        else
                        {
                            model.AccountId = account.AccountId;
                        }
                    }
                }
                else
                {
                    var account = AccountService.GetByName(searchtext);
                    var user    = MenbershipService.QueryUsers <AccountUser>(new UserRequest()
                    {
                        DisplayNameWith = searchtext
                    });
                    if (account == null && user.Count() < 1)
                    {
                        model.AddMsg("系统没有找到会员信息,请重新输入!");
                        model.Read();
                        model.Ready();
                        return(View(new EcardModelItem <CreateOrder>(model, model)));
                    }
                    else
                    {
                        if (account == null)
                        {
                            if (user.Count() > 1)
                            {
                                model.AddMsg("根据" + searchtext + "查到不止一个会员,系统无法确定订单所属会员。");
                                model.Read();
                                model.Ready();
                                return(View(new EcardModelItem <CreateOrder>(model, model)));
                            }
                            else
                            {
                                model.AccountId = AccountService.QueryByOwnerId(user.First()).First().AccountId;
                            }
                        }
                        else
                        {
                            model.AccountId = account.AccountId;
                        }
                    }
                }
            }
            else
            {
                model.AddMsg("系统没有找到会员信息,请重新输入!");
                model.Read();
                model.Ready();
                return(View(new EcardModelItem <CreateOrder>(model, model)));
            }
            #endregion

            var ss  = model.Detial.Count;
            int num = 0;
            List <OrderDetial1> detials = new List <OrderDetial1>();
            for (int i = 0; i < ss; i++)
            {
                OrderDetial1 detial = new OrderDetial1();
                if (Request.Form["Item.Detial[" + i.ToString() + "].Checked"].ToLower().IndexOf("true") > -1)
                {
                    num++;
                    detial.GoodId = int.Parse(Request.Form["Item.Detial[" + i.ToString() + "].Id"]);
                    detial.Amount = int.Parse(Request.Form["Item.Detial[" + i.ToString() + "].Amount"]);
                    detial.price  = decimal.Parse(Request.Form["Item.Detial[" + i.ToString() + "].Price"]);
                    if ((detial.price * detial.Amount) <= 0)
                    {
                        model.AddMsg("没有正确的输入数量或单价");
                        model.Read();
                        model.Ready();
                        return(View(new EcardModelItem <CreateOrder>(model, model)));
                    }
                    detials.Add(detial);
                }
            }
            if (num > 0)
            {
                model.Detials = detials;
                IMessageProvider msg = null;
                if (ModelState.IsValid)
                {
                    this.ModelState.Clear();

                    msg   = model.Create();
                    model = _unityContainer.Resolve <CreateOrder>();
                }
                model.Read();
                model.Ready();
                return(View(new EcardModelItem <CreateOrder>(model, msg)));
            }
            else
            {
                // new Exception("没有选择商品");
                model.AddMsg("没有选择商品");
                model.Read();
                model.Ready(); return(View(new EcardModelItem <CreateOrder>(model, model)));
            }
        }