public ActionResult Index(CheckoutShippingViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.quote = GetQuote();

                Mapper.CreateMap <CheckoutShippingViewModel, Address>();

                if (model.quote.Address == null)
                {
                    AddressService.CreateAddress(model.quote.QuoteID, Mapper.Map <Address>(model));
                }
                else
                {
                    Address UpdatedAddress = Mapper.Map <Address>(model);
                    UpdatedAddress.AddressID = model.quote.Address.AddressID;
                    AddressService.UpdateAddress(UpdatedAddress);
                }

                Quote quote = GetQuote();
                quote.ShippingCharge = quote.CalculateShipping();
                QuoteService.UpdateQuote(quote);

                string URL = PayPal.ConfirmSale(GetQuote());

                return(Redirect(URL));
            }

            return(Index());
        }
        public ActionResult Index()
        {
            CheckoutShippingViewModel model = new CheckoutShippingViewModel();

            Cart cart = GetOrSetCart();

            if (cart.Items == null || cart.Items.Length == 0)
            {
                return(RedirectToAction("Index", "Cart"));
            }

            model.quote = QuoteService.CreateQuote(cart);

            model.quote.Address = new Address();

            model.Countries = CountryCodeService.GetCountries().Select(x => new SelectListItem()
            {
                Value    = x.Code,
                Text     = x.Name,
                Selected = x.Code == model.quote.Address.Country
            });

            HttpCookie newQuoteCookie = new HttpCookie("QuoteKey");

            newQuoteCookie.Value   = model.quote.QuoteKey.ToString();
            newQuoteCookie.Expires = DateTime.Now.AddDays(1);
            ControllerContext.HttpContext.Response.Cookies.Set(newQuoteCookie);

            return(View(model));
        }
        public async Task <IActionResult> Shipping(Guid?orderId)
        {
            if (orderId == null)
            {
                return(NotFound());
            }
            var userRequest = await _userManager.GetCurrentUserAsync();

            if (!userRequest.IsSuccess)
            {
                return(NotFound());
            }
            var orderRequest = await _orderProductService.GetOrderByIdAsync(orderId);

            if (!orderRequest.IsSuccess)
            {
                return(NotFound());
            }

            var wasInvoicedRequest = await _orderProductService.ItWasInTheStateAsync(orderId, OrderState.Invoiced);

            if (wasInvoicedRequest.IsSuccess && wasInvoicedRequest.Result)
            {
                return(NotFound());
            }
            var addressesRequest = await _userAddressService.GetUserAddressesAsync(userRequest.Result.Id);

            var model = new CheckoutShippingViewModel
            {
                Order     = orderRequest.Result,
                Addresses = addressesRequest.Result?.ToList() ?? new List <Address>()
            };

            return(View(model));
        }
Beispiel #4
0
        public CheckoutShippingViewModel GetSubscriptionCheckoutInfo(string subscrToken)
        {
            using (ManBoxEntities ent = new ManBoxEntities())
            {
                Subscription completeSub = null;
                var          viewModel   = new CheckoutShippingViewModel();
                var          sub         = ent.Subscriptions.FirstOrDefault(s => s.Token == subscrToken);

                if (sub == null)
                {
                    throw new Exception("Subscription not found from checkout");
                }

                viewModel.IsSubscriptionValid = CheckSubscriptionValidity(sub);
                var user = sub.User;

                if (user != null)
                {
                    completeSub         = user.Subscriptions.FirstOrDefault(s => s.Address != null);
                    viewModel.Email     = user.Email;
                    viewModel.FirstName = user.FirstName;
                    viewModel.LastName  = user.LastName;
                    viewModel.Phone     = user.Phone;
                }

                if (completeSub != null)
                {
                    viewModel.City       = completeSub.Address.City;
                    viewModel.CountryId  = completeSub.Address.CountryId;
                    viewModel.PostalCode = completeSub.Address.PostalCode;
                    viewModel.Province   = completeSub.Address.Province;
                    viewModel.Street     = completeSub.Address.Street;
                }

                var paymentInfo = GetPaymentInfo(sub, ent);
                viewModel.TotalInt            = paymentInfo.TotalInt;
                viewModel.Token               = subscrToken;
                viewModel.IsSubscriptionValid = CheckSubscriptionValidity(sub);

                if (sub.Gift != null)
                {
                    viewModel.GuestName = sub.Gift.GuestName;
                    viewModel.GiftMsg   = sub.Gift.GiftMessage;
                }

                return(viewModel);
            }
        }
        public async Task <IActionResult> Shipping([Required] CheckoutShippingViewModel model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            if (model.Order != null)
            {
                var addressUpdateRequest = await _orderProductService.SetOrderBillingAddressAndShipmentAsync(model.Order?.Id, model.ShipmentAddress, model.BillingAddressId);

                if (addressUpdateRequest.IsSuccess)
                {
                    return(RedirectToAction("Payment", new { OrderId = model.Order.Id }));
                }
                ModelState.AppendResultModelErrors(addressUpdateRequest.Errors);
            }

            var userRequest = await _userManager.GetCurrentUserAsync();

            if (!userRequest.IsSuccess)
            {
                return(NotFound());
            }
            var orderRequest = await _orderProductService.GetOrderByIdAsync(model.Order?.Id);

            if (!orderRequest.IsSuccess)
            {
                return(NotFound());
            }
            if (orderRequest.Result.OrderState != OrderState.New)
            {
                return(NotFound());
            }
            var addressesRequest = await _userAddressService.GetUserAddressesAsync(userRequest.Result.Id);

            model.Order     = orderRequest.Result;
            model.Addresses = addressesRequest.Result;
            return(View(model));
        }
Beispiel #6
0
        public PaymentParametersViewModel SaveShippingInfo(CheckoutShippingViewModel shippingInfo, string subscrToken)
        {
            using (ManBoxEntities ent = new ManBoxEntities())
            {
                var          user = ent.Users.SingleOrDefault(u => u.Email == shippingInfo.Email);
                Subscription sub  = ent.Subscriptions.FirstOrDefault(s => s.Token == subscrToken);

                if (user == null)
                {
                    sub.User = new User()
                    {
                        CountryId       = shippingInfo.CountryId,
                        CreatedDatetime = DateTime.Now,
                        Email           = shippingInfo.Email.ToLower(),
                        FirstName       = shippingInfo.FirstName,
                        IsOptin         = true,
                        LastName        = shippingInfo.LastName,
                        Password        = shippingInfo.Password,
                        SignInTypeCV    = CodeValues.SignInType.EmailPass,
                        Phone           = shippingInfo.Phone,
                        LanguageId      = IdHelper.CurrentUser.LanguageId
                    };
                }
                //else if (user.Subscriptions.Any(s => s.SubscriptionStateCV == CodeValues.SubscriptionState.Subscribed))
                //{
                //    return new PaymentParametersViewModel() { AlreadyMember = true };
                //}
                else
                {
                    sub.User = user; // user was already in database but was not subscribed yet
                }

                var address = new ManBox.Model.Address()
                {
                    City       = shippingInfo.City,
                    FirstName  = shippingInfo.FirstName,
                    LastName   = shippingInfo.LastName,
                    PostalCode = shippingInfo.PostalCode,
                    Street     = shippingInfo.Street,
                    Province   = shippingInfo.Province,
                    CountryId  = shippingInfo.CountryId
                };

                var shippingAddress = new ManBox.Model.Address()
                {
                    City       = shippingInfo.City,
                    FirstName  = string.IsNullOrEmpty(shippingInfo.ShippingFirstName) ? shippingInfo.FirstName : shippingInfo.ShippingFirstName,
                    LastName   = string.IsNullOrEmpty(shippingInfo.ShippingLastName) ? shippingInfo.LastName : shippingInfo.ShippingLastName,
                    PostalCode = shippingInfo.PostalCode,
                    Street     = shippingInfo.Street,
                    Province   = shippingInfo.Province,
                    CountryId  = shippingInfo.CountryId
                };

                sub.Address             = address;
                sub.ShippingAddress     = shippingAddress;
                sub.SubscriptionStateCV = CodeValues.SubscriptionState.Checkout;

                ent.SaveChanges();

                return(GetPaymentInfo(sub, ent));
            }
        }