Ejemplo n.º 1
0
        public ActionResult OrderInfo(OrderInfoModel orderInfo)
        {
            IList <Inpinke_User_Address> addressList = DBAddressBLL.GetUserAddress(UserSession.CurrentUser.ID);

            if (addressList != null && addressList.Count() > 0)
            {
                ViewBag.UserAddress = addressList;
            }
            Inpinke_User_Address address = new Inpinke_User_Address();

            if (orderInfo.AddressID > 0)
            {
                address = addressList.Where(e => e.ID == orderInfo.AddressID).FirstOrDefault();
                if (address == null)
                {
                    ViewBag.Msg = "不存在该收货人信息,请重新填写";
                    return(View());
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.Msg = "输入信息有误,麻烦再检查一下";
                    return(View());
                }
                address = new Inpinke_User_Address()
                {
                    Address  = orderInfo.Address,
                    AreaID   = orderInfo.AreaID,
                    ProvID   = orderInfo.ProvID,
                    CityID   = orderInfo.CityID,
                    Mobile   = orderInfo.Mobile,
                    UserID   = UserSession.CurrentUser.ID,
                    UserName = orderInfo.Consignee
                };
                BaseResponse br = DBAddressBLL.AddUserAddress(address);
                if (!br.IsSuccess)
                {
                    ViewBag.Msg = br.Message;
                    return(View());
                }
            }
            IList <Inpinke_Cart> cartList = DBCartBLL.GetUserCart(UserSession.CurrentUser.ID);
            decimal       orderPrice      = DBCartBLL.GetCartTotalPrices(UserSession.CurrentUser.ID);
            Inpinke_Order order           = new Inpinke_Order()
            {
                OrderCode = DBOrderBLL.GetOrderCode(cartList[0].Inpinke_Product.ProductType),
                AddressID = address.ID,

                RecUserName = address.UserName,
                RecMobile   = address.Mobile,
                RecProvID   = address.ProvID,
                RecCityID   = address.CityID,
                RecAreaID   = address.AreaID,
                RecAddress  = address.Address,
                RecAreaName = address.AreaName,
                RecCityName = address.CityName,
                RecProvName = address.ProvName,

                UserID     = UserSession.CurrentUser.ID,
                OrgPrice   = orderPrice,
                TotalPrice = orderPrice,
                UserRemark = orderInfo.Remark
            };

            BaseResponse br1 = DBOrderBLL.AddOrder(order);

            if (!br1.IsSuccess)
            {
                ViewBag.Msg = br1.Message;
                return(View());
            }
            return(RedirectToAction("Pay", new { orderid = order.ID }));
        }