Exemplo n.º 1
0
 public ActionResult Address()
 {
     if (Cart.Products.Count == 0)
     {
         return(RedirectToAction("Checkout", "Cart", new { noProducts = true }));
     }
     Models.CartViewModels.AddressPage add = BuildAddressPage();
     return(View(add));
 }
Exemplo n.º 2
0
        public ActionResult Address(Models.CartViewModels.AddressPage model)
        {
            if (model.AddressToUse != -1)
            {
                Cart.AddressID = model.AddressToUse;
                Cart.Save();
                if (Session["CartID"] == null)
                {
                    Session["CartID"] = Cart.CartID;
                }
                return(RedirectToAction("Pay", "Cart"));
            }
            else
            {
                TryUpdateModel(model.CartAddress);
                if (ModelState.IsValid)
                {
                    Cart.UseNewAddress(new Address {
                        City            = model.CartAddress.City,
                        Line1           = model.CartAddress.Line1,
                        Line2           = model.CartAddress.Line2,
                        StateOrProvince = model.CartAddress.StateOrProvince,
                        ZipCode         = model.CartAddress.ZipCode,
                        County          = model.CartAddress.County,
                        FullName        = model.CartAddress.FullName
                    });
                    if (model.SaveAddress)
                    {
                        DataModels.AccountAddress aa = new DataModels.AccountAddress {
                            UserID      = User.Identity.GetUserId(),
                            AddressID   = Cart.AddressID.Value,
                            AddressType = "Mailing"
                        };
                        SmartNerdDataContext _context = new SmartNerdDataContext();
                        _context.AccountAddresses.InsertOnSubmit(aa);
                        _context.SubmitChanges();
                    }
                    Cart.Save();
                    if (Session["CartID"] == null)
                    {
                        Session["CartID"] = Cart.CartID;
                    }
                    return(RedirectToAction("Pay", "Cart"));
                }
            }

            Models.CartViewModels.AddressPage add = BuildAddressPage();
            add.CartAddress = model.CartAddress;
            return(View(add));
        }
Exemplo n.º 3
0
        private Models.CartViewModels.AddressPage BuildAddressPage()
        {
            SmartNerdDataContext _context = new SmartNerdDataContext();

            Models.CartViewModels.AddressPage add = new Models.CartViewModels.AddressPage {
                BillingAddresses = new List <Models.Address>(),
                MailingAddresses = new List <Models.Address>(),
            };
            if (User.Identity.GetUserId() != null)
            {
                add = new Models.CartViewModels.AddressPage();
                List <Models.AccountAddress> addresses = (from aa in _context.AccountAddresses
                                                          join a in _context.Addresses on aa.AddressID equals a.AddressID
                                                          where aa.UserID == User.Identity.GetUserId()
                                                          select new AccountAddress {
                    AddressID = a.AddressID,
                    FullName = a.FullName,
                    City = a.City,
                    County = a.County,
                    Line1 = a.Line1,
                    Line2 = a.Line2,
                    StateOrProvince = a.StateOrProvince,
                    ZipCode = a.ZipCode,
                    AddressType = aa.AddressType,
                    AccountID = new Guid(aa.UserID)
                }).ToList();
                add.BillingAddresses = addresses.Where(m => m.AddressType == "Billing").Select(m => (Models.Address)m).ToList();
                add.MailingAddresses = addresses.Where(m => m.AddressType == "Mailing").Select(m => (Models.Address)m).ToList();
            }
            Models.Address addressInList = add.MailingAddresses.FirstOrDefault(a => a.AddressID == Cart.AddressID);
            if (Cart.AddressID != null && addressInList == null)
            {
                add.CartAddress = (from a in _context.Addresses
                                   where a.AddressID == Cart.AddressID
                                   select new Models.Address {
                    FullName = a.FullName,
                    City = a.City,
                    County = a.County,
                    Line1 = a.Line1,
                    Line2 = a.Line2,
                    StateOrProvince = a.StateOrProvince,
                    ZipCode = a.ZipCode
                }).FirstOrDefault();
            }
            return(add);
        }
Exemplo n.º 4
0
        private Models.CartViewModels.AddressPage BuildAddressPage()
        {
            SmartNerdDataContext _context = new SmartNerdDataContext();

            Models.CartViewModels.AddressPage add = new Models.CartViewModels.AddressPage {
                BillingAddresses = new List<Models.Address>(),
                MailingAddresses = new List<Models.Address>(),
            };
            if(User.Identity.GetUserId() != null) {
                add = new Models.CartViewModels.AddressPage();
                List<Models.AccountAddress> addresses = (from aa in _context.AccountAddresses
                                                         join a in _context.Addresses on aa.AddressID equals a.AddressID
                                                         where aa.UserID == User.Identity.GetUserId()
                                                         select new AccountAddress {
                                                             AddressID = a.AddressID,
                                                             FullName = a.FullName,
                                                             City = a.City,
                                                             County = a.County,
                                                             Line1 = a.Line1,
                                                             Line2 = a.Line2,
                                                             StateOrProvince = a.StateOrProvince,
                                                             ZipCode = a.ZipCode,
                                                             AddressType = aa.AddressType,
                                                             AccountID = new Guid(aa.UserID)
                                                         }).ToList();
                add.BillingAddresses = addresses.Where(m => m.AddressType == "Billing").Select(m => (Models.Address)m).ToList();
                add.MailingAddresses = addresses.Where(m => m.AddressType == "Mailing").Select(m => (Models.Address)m).ToList();
            }
            Models.Address addressInList = add.MailingAddresses.FirstOrDefault(a => a.AddressID == Cart.AddressID);
            if(Cart.AddressID != null && addressInList == null) {
                add.CartAddress = (from a in _context.Addresses
                                   where a.AddressID == Cart.AddressID
                                   select new Models.Address {
                                       FullName = a.FullName,
                                       City = a.City,
                                       County = a.County,
                                       Line1 = a.Line1,
                                       Line2 = a.Line2,
                                       StateOrProvince = a.StateOrProvince,
                                       ZipCode = a.ZipCode
                                   }).FirstOrDefault();
            }
            return add;
        }