public ActionResult DeliveryInfo()
        {
            //show member contact info, user can also modify here.
            int customerIdInt = Convert.ToInt32(Session["CustomerID"]);

            // if the client is not a member. and do not want to be a member.
            List <ShoppingCartObjectModel> itemObjList = new List <ShoppingCartObjectModel>();

            itemObjList = TempData["itemList"] as List <ShoppingCartObjectModel>;
            TempData.Keep("itemList");

            // user use broser's previsous page from deilvery page or other situation
            if (TempData["itemList"] == null)
            {
                return(RedirectToAction("", "Customer"));
            }

            DeliveryInfoViewModel viewM = new DeliveryInfoViewModel();

            viewM.itemList = itemObjList;


            // assign unit price of each item
            foreach (ShoppingCartObjectModel item in itemObjList)
            {
                Product queryProduct = (from o in db.Products
                                        where o.ProductID == item.ProductID
                                        select o).SingleOrDefault();
                item.UnitPrice = queryProduct.ProductPrice;
            }


            //calculate totalPrice
            viewM.PriceTotal = 0;
            foreach (ShoppingCartObjectModel item in itemObjList)
            {
                viewM.PriceTotal += item.UnitPrice * item.Quantity;
            }


            // here should check if the member login in,
            // temporary solution: here just use default value of `int` if no assignment,
            //
            if (customerIdInt == 1)
            {
                Customer newCustomer = new Customer();
                viewM.customer = newCustomer;
                return(View(viewM));
            }


            //int customerId = itemObjList[0].CustomerID;
            var query = from o in db.Customers
                        where o.CustomerID == customerIdInt
                        select o;

            viewM.customer = query.SingleOrDefault();

            return(View(viewM));
        }
        public DeliveryInfoViewModel DeliveryInfo(string UserId)
        {
            DeliveryInfoViewModel model = new DeliveryInfoViewModel();

            if (UserId == null)
            {
                return(model);
            }
            eCommerceContext context = new eCommerceContext();
            var UserManager          = new UserManager <eCommerceUser>(new UserStore <eCommerceUser>(context));

            model.User = UserManager.FindById(UserId);
            return(model);
        }
Esempio n. 3
0
        public ActionResult DeliveryInfo()
        {
            DeliveryInfoViewModel model = new DeliveryInfoViewModel();

            if (User.Identity.IsAuthenticated)
            {
                model.User = UserManager.FindById(User.Identity.GetUserId());
            }
            else
            {
                model.User = new eCommerceUser();
            }

            return(PartialView("_DeliveryInfo", model));
        }
Esempio n. 4
0
        public ActionResult DeliveryInfo(DeliveryInfoViewModel deliveryInfoViewModel)
        {
            var deliveryInfo = from DeliveryInfo in db.DeliveryInfo
                               where DeliveryInfo.UserEmail == User.Identity.Name
                               select DeliveryInfo;

            var list = deliveryInfo.ToList();
            DeliveryInfoModel deliveryInfoModel = null;

            if (list.Count() == 0)
            {
                deliveryInfoModel           = new Models.DeliveryInfoModel();
                deliveryInfoModel.UserEmail = User.Identity.Name;
                db.DeliveryInfo.Add(deliveryInfoModel);
                db.SaveChanges();
            }
            else
            {
                deliveryInfoModel = list[0];
            }

            if (!String.IsNullOrWhiteSpace(deliveryInfoViewModel.FirstName))
            {
                deliveryInfoModel.FirstName = deliveryInfoViewModel.FirstName;
            }
            if (!String.IsNullOrWhiteSpace(deliveryInfoViewModel.LastName))
            {
                deliveryInfoModel.LastName = deliveryInfoViewModel.LastName;
            }
            if (!String.IsNullOrWhiteSpace(deliveryInfoViewModel.Address))
            {
                deliveryInfoModel.Address = deliveryInfoViewModel.Address;
            }
            if (!String.IsNullOrWhiteSpace(deliveryInfoViewModel.Floor))
            {
                deliveryInfoModel.Floor = deliveryInfoViewModel.Floor;
            }
            if (!String.IsNullOrWhiteSpace(deliveryInfoViewModel.PhoneNumber))
            {
                deliveryInfoModel.PhoneNumber = deliveryInfoViewModel.PhoneNumber;
            }

            db.SaveChanges();
            return(View());
        }
Esempio n. 5
0
        public DeliveryInfoViewModel GetDeliveryInfoViewModel()
        {
            var deliveryInfo = from DeliveryInfo in db.DeliveryInfo
                               where DeliveryInfo.UserEmail == User.Identity.Name
                               select DeliveryInfo;

            DeliveryInfoViewModel deliveryInfoViewModel = new DeliveryInfoViewModel();

            if (deliveryInfo.ToList().Count() > 0)
            {
                DeliveryInfoModel deliveryInfoModel = deliveryInfo.ToList()[0];
                deliveryInfoViewModel.FirstName   = deliveryInfoModel.FirstName;
                deliveryInfoViewModel.LastName    = deliveryInfoModel.LastName;
                deliveryInfoViewModel.Address     = deliveryInfoModel.Address;
                deliveryInfoViewModel.Floor       = deliveryInfoModel.Floor;
                deliveryInfoViewModel.PhoneNumber = deliveryInfoModel.PhoneNumber;
            }

            return(deliveryInfoViewModel);
        }
Esempio n. 6
0
        public void AddUpdateDeliveryInfo(DeliveryInfoViewModel item)
        {
            var entity = _dbContext.DeliveryInfo.Find(item.Id) ?? new DeliveryInfoEntity();

            entity.ProductId         = item.Product;
            entity.SellerId          = item.Seller;
            entity.StartDeliveryDate = item.StartDeliveryDate.Value;
            entity.EndDeliveryDate   = item.EndDeliveryDate.Value;

            if (entity.Id != 0)
            {
                _dbContext.DeliveryInfo.Update(entity);
            }
            else
            {
                _dbContext.DeliveryInfo.Add(entity);
            }

            _dbContext.SaveChanges();
        }
Esempio n. 7
0
        public ActionResult Checkout()
        {
            CheckoutViewModel             checkoutViewModel             = new CheckoutViewModel();
            DeliveryInfoViewModelRequired deliveryInfoViewModelRequired = new DeliveryInfoViewModelRequired();

            DeliveryInfoViewModel deliveryInfoModel = GetDeliveryInfoViewModel();

            deliveryInfoViewModelRequired.UserEmail    = User.Identity.Name;
            deliveryInfoViewModelRequired.FirstName    = deliveryInfoModel.FirstName;
            deliveryInfoViewModelRequired.LastName     = deliveryInfoModel.LastName;
            deliveryInfoViewModelRequired.DeliverEmail = deliveryInfoModel.DeliverEmail;
            deliveryInfoViewModelRequired.Address      = deliveryInfoModel.Address;
            deliveryInfoViewModelRequired.Floor        = deliveryInfoModel.Floor;
            deliveryInfoViewModelRequired.PhoneNumber  = deliveryInfoModel.PhoneNumber;

            checkoutViewModel.DeliveryInfoViewModelRequired = deliveryInfoViewModelRequired;
            checkoutViewModel.CourtItems = GetCourtItemList();


            return(View(checkoutViewModel));
        }
Esempio n. 8
0
        //
        // GET: /BMapRoutePlanning/
        public ActionResult Index(long orderId)
        {
            Order order = _orderService.GetOrderByOrderId(orderId);

            if (order.OrderStatus == OrderStatusEnumType.FINISHED.ToString())
            {
                return(Content("<script>alert('订单已派送结束');location.href='/Order/OrderDetail?orderId=" + orderId + "'</script>"));
            }

            Address address = _addressService.GetAddress(order.AddressId);

            // Current area second level delivery station
            DeliveryStation deliveryStation = _deliveryStationService.GetDeliveryStations(address.AreaId, 2).FirstOrDefault();

            // Get Third level delivery station to destination in current area
            Dictionary <double, DeliveryStation> distanceMap = new Dictionary <double, DeliveryStation>();

            if (deliveryStation.DeliveryStations.Count == 0)
            {
                return(Content("<script>alert('当前地址下无子级派送点');location.href='/Order/OrderDetail?orderId=" + orderId + "'</script>"));
            }
            else
            {
                foreach (var obj in deliveryStation.DeliveryStations)
                {
                    double key = MathHelper.GetDistance(obj.Longitude, obj.Latitude, address.Longitude, address.Latitude);
                    if (!distanceMap.ContainsKey(key))
                    {
                        distanceMap.Add(key, obj);
                    }
                }
            }

            // Order by distance
            var tempMap = distanceMap.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

            List <DeliveryStation> stationList = new List <DeliveryStation>();
            int index = 1;

            foreach (var o in tempMap.Keys)
            {
                if ((index == tempMap.Keys.Count && tempMap.Keys.Count <= 15) || index == 16)
                {
                    break;
                }
                stationList.Add(tempMap[o]);
                index++;
            }

            // Request BMap WebAPI and receive Json call back data
            String origins = "&origins=";

            for (var i = 0; i < stationList.Count; i++)
            {
                if (i == 0)
                {
                    origins += stationList[i].Latitude + "," + stationList[i].Longitude;
                }
                else
                {
                    origins += "|" + stationList[i].Latitude + "," + stationList[i].Longitude;
                }
            }

            String destinations = "&destinations=" + address.Latitude + "," + address.Longitude;

            String ak = "&ak=" + Constants.BMAP_AK;

            BMapDataModel bMapDataModel = JsonHelper.
                                          DeserializeJsonToObject <BMapDataModel>(WebAPIHelper.Get(Constants.BMAP_DRIVING_BASE_URL + Constants.BMAP_OUTPUT_TYPE + origins + destinations + ak));

            // Get min index of delivery station
            int minDistanceIndex = bMapDataModel.Result.FindIndex(x => x.Distance.Value == bMapDataModel.Result.Min(y => y.Distance.Value));

            // init originPoint
            OriginPointViewModel startUpPoint = new OriginPointViewModel(Constants.START_POINT_NAME, Constants.START_POINT_ADDRESS, Constants.START_POINT_LONGITUDE, Constants.START_POINT_LATITUDE);

            OriginPointViewModel firstPoint = new OriginPointViewModel(deliveryStation.ParentDeliveryStation.Name, deliveryStation.ParentDeliveryStation.Address, deliveryStation.ParentDeliveryStation.Longitude, deliveryStation.ParentDeliveryStation.Latitude);

            OriginPointViewModel secondPoint = new OriginPointViewModel(deliveryStation.Name, deliveryStation.Address, deliveryStation.Longitude, deliveryStation.Latitude);

            OriginPointViewModel thirdPoint = new OriginPointViewModel(stationList[minDistanceIndex].Name, stationList[minDistanceIndex].Address, stationList[minDistanceIndex].Longitude, stationList[minDistanceIndex].Latitude);

            OriginPointViewModel endPoint = new OriginPointViewModel(address.DeliveryAddress, address.DeliveryAddress, address.Longitude, address.Latitude);

            List <DeliveryInfoViewModel> deliveryinfos = new List <DeliveryInfoViewModel>();

            List <DeliveryInfo> initDeliveryInfos = _deliveryInfoService.GetDeliveryInfo(orderId);

            foreach (var item in initDeliveryInfos)
            {
                DeliveryInfoViewModel temp = new DeliveryInfoViewModel(item.Description, item.UpdateTime);
                deliveryinfos.Add(temp);
            }

            BMapViewModel bMapViewModel = new BMapViewModel()
            {
                DeliveryInfos = deliveryinfos,
                OriginPoints  = new List <OriginPointViewModel>()
                {
                    startUpPoint,
                    firstPoint,
                    secondPoint,
                    thirdPoint,
                    endPoint
                },
                Order = order
            };

            return(View(bMapViewModel));
        }
        public ActionResult DeliveryInfo(DeliveryInfoViewModel divm)
        {
            // check the list passed
            List <ShoppingCartObjectModel> itemObjList = new List <ShoppingCartObjectModel>();

            itemObjList = TempData["itemList"] as List <ShoppingCartObjectModel>;
            TempData.Keep("itemList");

            int customerIdInt = Convert.ToInt32(Session["CustomerID"]);

            if (Request.Form["okOrCancel"] == "ok")
            {
                // update Customers
                // 1 is non-member.
                //if (itemObjList[0].CustomerID != 1) {
                if (customerIdInt != 1)
                {
                    //int myInt = Convert.ToInt32(Session["CustomerID"]);

                    var customerDatabase = db.Customers
                                           .Where(x => x.CustomerID == customerIdInt)
                                           .FirstOrDefault();
                    customerDatabase.CustomerAddress     = divm.customer.CustomerAddress;
                    customerDatabase.CustomerEmail       = divm.customer.CustomerEmail;
                    customerDatabase.CustomerMobilePhone = divm.customer.CustomerMobilePhone;
                    customerDatabase.CustomerName        = divm.customer.CustomerName;
                }
                else
                {
                    divm.customer.CustomerRole = 2;
                    db.Customers.Add(divm.customer);
                }


                // create Order
                Order newOrder = new Order();

                newOrder.CustomerID       = customerIdInt;
                newOrder.OrderDateTime    = DateTime.Now.ToString("yyyyMMdd HH:mm");
                newOrder.OrderShipAddress = divm.customer.CustomerAddress;
                db.Orders.Add(newOrder);

                // create OrderDetails
                foreach (ShoppingCartObjectModel item in itemObjList)
                {
                    OrderDetail newOrderDetail = new OrderDetail();
                    newOrderDetail.OrderID   = newOrder.OrderID;
                    newOrderDetail.ProductID = item.ProductID;
                    newOrderDetail.Quantity  = item.Quantity;
                    newOrderDetail.Discount  = item.Discount;
                    newOrderDetail.UnitPrice = item.UnitPrice;
                    db.OrderDetails.Add(newOrderDetail);
                }


                db.SaveChanges();

                // decrease quanty in table Products
                for (int i = 0; i < itemObjList.Count(); i++)
                {
                    int itemId          = itemObjList[i].ProductID;
                    int itemQuantity    = itemObjList[i].Quantity;
                    var productDatabase = db.Products
                                          .Where(x => x.ProductID == itemId)
                                          .FirstOrDefault();
                    productDatabase.ProductQuantity = productDatabase.ProductQuantity - itemQuantity;
                }

                db.SaveChanges();

                return(RedirectToAction("OrderSuccess"));
            }



            return(RedirectToAction("ShoppingCart"));
        }