Exemplo n.º 1
0
        public ActionResult ChooseAdress(AdressSelectViewModel Adress)
        {
            var             cart      = ShoppingCart.GetCart(this.HttpContext);
            List <CartItem> listItems = cart.GetCartItems();

            string s          = System.Web.HttpContext.Current.User.Identity.Name;
            int    idCustomer = webstoreDB.customer.Single(c => c.email == s).idCustomer;

            List <Adress> listAdress = new List <Adress>();

            listAdress = webstoreDB.adress.Where(a => a.Customer_idCustomer == idCustomer).ToList();
            int idAdress = listAdress.ElementAt(Adress.SelectedItemId - 1).idAdress;

            double custDiscount = (double)webstoreDB.customer.Single(c => c.email == s).customerdiscont.discountPercent;
            double price        = (double)cart.GetTotal((decimal)custDiscount);
            int    idPurchase;

            if ((idPurchase = CreatePurchase(listItems, idAdress, idCustomer, price)) != 0)
            {
                return(RedirectToAction("Complete", new { id = idPurchase }));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        //
        // GET: /Checkout/AddressAndPayment

        public ActionResult ChooseAdress()
        {
            string         s            = System.Web.HttpContext.Current.User.Identity.Name;
            MembershipUser user         = Membership.GetUser(s);
            Customer       webstoreUser = webstoreDB.customer.Single(c => c.email == user.UserName);
            List <Adress>  listAdress   = new List <Adress>();

            listAdress = webstoreDB.adress.Where(a => a.Customer_idCustomer == webstoreUser.idCustomer).ToList();
            var model = new AdressSelectViewModel
            {
                Items = listAdress.Select(u => new SelectListItem
                {
                    Value = u.idAdress.ToString(),
                    Text  = u.city + ", " + u.apartment
                })
            };

            model.SelectedItemId = 1;
            return(View(model));
        }