コード例 #1
0
        public ActionResult New(bool?isSameAsSender, string type)
        {
            List <string> pickupTypes = new List <string>();

            pickupTypes.Add("Immediate");
            pickupTypes.Add("Prearranged");

            ViewBag.IsSameAsSender = isSameAsSender;
            ViewBag.Type           = type;

            var viewModel = new NewPickupViewModel();

            return(View(viewModel));
        }
コード例 #2
0
        //  [ValidateAntiForgeryToken]
        public ActionResult Create(string submit, NewPickupViewModel pickupView)   //model binding
        {
            DateTime endDate = DateTime.Now.AddDays(5);

            if (pickupView.Pickup.Date > endDate || pickupView.Pickup.Date < DateTime.Today)
            {
                return(RedirectToAction("Create", "Pickups", new { waybillId = pickupView.WaybillId, validDate = "false" }));
            }


            /* Add saved address functionality */
            var shipment = (from s in db.Shipments
                            where s.WaybillId == pickupView.WaybillId
                            select s).First();
            var shippingAccount = (from s in db.ShippingAccounts
                                   where s.UserName == User.Identity.Name
                                   select s).First();

            shipment.Pickup.Date = pickupView.Pickup.Date;

            if (pickupView.PickupLocationNickname != null)
            {
                shipment.Pickup.Location = pickupView.PickupLocationNickname;
            }
            else
            {
                shipment.Pickup.Location = pickupView.Pickup.Location;
            }

            shipment.Pickup.Type = pickupView.Pickup.Type;

            /* need to add pickup */
            //  db.Pickups.Add(pickupView.Pickup);
            try
            {
                shipment.Status = "confirmed";
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }
            return(RedirectToAction("Index", "Shipments"));
        }
コード例 #3
0
        // GET: Pickups/Create
        public ActionResult Create(int?waybillId, string pickupType, string location, string validDate, NewPickupViewModel pickupView = null)
        {
            if (waybillId == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            pickupView = new NewPickupViewModel();

            pickupView.Pickup = new Pickup
            {
                Date = DateTime.Now,
                Type = pickupType
            };
            ViewBag.WaybillId = waybillId;

            if (validDate == "false")
            {
                ViewBag.msg = "You can prearranged your pickup up to 5 days, please try another date";
                return(View(pickupView));
            }


            /* bind shipment */
            var shipment = db.Shipments.FirstOrDefault(s => s.WaybillId == waybillId);

            if (shipment == null)//protect the database access
            {
                return(View(pickupView));
            }

            var buildingInfo         = shipment.ShippingAccount.BuildingInformation;
            var streetInfo           = shipment.ShippingAccount.StreetInformation;
            var cityInfo             = shipment.ShippingAccount.City;
            var provinceCode         = shipment.ShippingAccount.ProvinceCode;
            var postalCode           = shipment.ShippingAccount.PostalCode;
            var senderMailingAddress = streetInfo + ", " + cityInfo + ", " + provinceCode + ", " + postalCode;

            if (buildingInfo != null)
            {
                senderMailingAddress = buildingInfo + ", " + senderMailingAddress;
            }

            /* bind savedAddress */
            var savedAddressNicknames = (from s in db.SavedAddresses
                                         where s.ShippingAccountId == shipment.ShippingAccountId && s.Type == "pickup"
                                         select s.NickName);

            if (savedAddressNicknames != null)
            {
                ViewBag.pickupLocations = savedAddressNicknames.Distinct().ToList();
            }

            if (location != null)
            {
                ViewBag.Location = location; //Same, Diff
                if (location == "Same")
                {
                    pickupView.Pickup.Location = senderMailingAddress;
                }
            }
            return(View(pickupView));
        }