コード例 #1
0
        public ActionResult EnterShippingAddress(ShippingAddressViewModel vm, FormCollection form)
        {
            // grab the form's dropdown lists selected value.
            var country = Int32.Parse(form["shippingCountry"]);
            var province = Int32.Parse(form["shippingProvince"]);
            var state = Int32.Parse(form["shippingState"]);

            int countryId = country;
            int shippingProvinceOrState = countryId == 1 ? province : state;

            var shippingAddress = new Address()
            {
                Street1 = vm.ShippingAddress.Street1,
                Street2 = vm.ShippingAddress.Street1,
                City = vm.ShippingAddress.City,
                ProvinceStateId = shippingProvinceOrState,
                PostalZipCode = vm.ShippingAddress.PostalZipCode,
                CountryId = country
            };

            // get the member details so we can attach the address ...
            var member = UoW.Members.GetAll().FirstOrDefault(m => m.DisplayName == User.Identity.Name);

            if (ModelState.IsValid)
            {
                try
                {
                    member.MemberDetails.FirstName = vm.FirstName;
                    member.MemberDetails.LastName = vm.LastName;
                    member.MemberDetails.ShippingAddress = shippingAddress;
                    member.MemberDetails.ShippingAddress.State = State.Added;
                    member.MemberDetails.State = State.Modified;
                    UoW.MemberDetails.Update(member.MemberDetails);
                    UoW.SaveChanges();
                }
                catch (Exception e)
                {
                    TempData["message"] = "Error: " + e.InnerException;
                }
            }

            return RedirectToAction("AddressAndPayment","Checkout");
        }
コード例 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult EnterShippingAddress()
        {
            var member = UoW.MemberDetails.GetAll().FirstOrDefault(m => m.DisplayName == User.Identity.Name);

            var model = new ShippingAddressViewModel()
            {
                MemberDetailsId = member.UserId,
                ShippingAddress = new Address()
            };

            var list = GetDropDownItems();
            ViewBag.shippingCountry = list[2];
            ViewBag.shippingProvince = list[3];
            ViewBag.shippingState = list[4];

            return View(model);
        }