public ActionResult AvailabilityCheck(Member member, Cart cart, Guid productGuid, HireDatesViewModel hireDates, HireAvailabilityViewModel hireAvailability, bool postcodeChecked = false)
        {
            Product product = this._queryDispatcher.Dispatch<Product, GetProductByGuidQuery>(new GetProductByGuidQuery(productGuid));

            if (!hireAvailability.IsValidPostcode)
            {
                if (string.IsNullOrEmpty(hireAvailability.Postcode))
                {
                    return this.PartialView("PostcodeCheck", new PostcodeCheckViewModel(product));
                }

                return this.PartialView("HireUnavailable");
            }

            if (hireDates.PartyDate.HasValue)
            {
                int availableInventory = this._queryDispatcher.Dispatch<int, GetInventoryCountCanAddToCartQuery>(new GetInventoryCountCanAddToCartQuery(member.Guid, productGuid, hireDates.PartyDate.Value));
                bool inCart = cart.Items.Any(o => o.Product.Guid == productGuid);

                return this.PartialView("AddToCart", new HireAddProductToCartViewModel(product, availableInventory, inCart, hireDates.PartyDate.Value));
            }

            ViewBag.PostcodeChecked = postcodeChecked;

            return this.PartialView("AvailabilityCheck", new HireProductViewModel(product, hireDates));
        }
        public ActionResult AddToCartForm(Member member, Cart cart, Guid productGuid)
        {
            int availableInventory = this._queryDispatcher.Dispatch<int, GetInventoryCountCanAddToCartQuery>(new GetInventoryCountCanAddToCartQuery(member.Guid, productGuid));
            bool inCart = cart.Items.Any(o => o.Product.Guid == productGuid);
            Product product = this._queryDispatcher.Dispatch<Product, GetProductByGuidQuery>(new GetProductByGuidQuery(productGuid));

            AddProductToCartViewModel viewModel = new AddProductToCartViewModel(product, availableInventory, inCart);

            return this.PartialView("AddToCart", viewModel);
        }
        public ActionResult Login(LoginViewModel login, Cart cart, Order order)
        {
            if (this.ModelState.IsValid)
            {
                LoginResult result = this._loginProvider.Login(this.Request.GetOwinContext().Authentication, login.Email, login.Password, login.RememberMe);

                if(result.Successful)
                {
                    if(cart != null && cart.MemberId != result.Member.Guid)
                    {
                        // convert cart
                        this._commandDispatcher.Dispatch(new ChangeCartsMemberGuidCommand(cart, result.Member.Guid));
                    }

                    if (order != null && cart.MemberId != result.Member.Guid)
                    {
                        // convert order
                        this._commandDispatcher.Dispatch(new ChangeOrdersMemberGuidCommand(order, result.Member.Guid));
                    }

                    if (string.IsNullOrEmpty(login.ReturnUrl))
                    {
                        return this.RedirectToRoute(Routes.Home);
                    }
                    else
                    {
                        return this.Redirect(login.ReturnUrl);
                    }
                }
                else
                {
                    this.ModelState.AddModelError("Email", "Invalid username or email. Please try again");
                }
            }

            return this.Login(login.ReturnUrl);
        }
 public SaveCartMessage(Cart cart)
 {
     this.Cart = cart;
 }
        public ActionResult ChangePartyDate(HireDatesViewModel partyDate, Cart cart)
        {
            // get unavailable products
            // submit command handler
            if (partyDate.PartyDate.HasValue)
            {
                IList<CartItem> cartItems = this._queryDispatcher.Dispatch<IList<CartItem>, GetUnavailableCartItemsQuery>(new GetUnavailableCartItemsQuery(cart, partyDate.PartyDate.Value));

                if (cartItems.Any())
                {
                    foreach (CartItem cartItem in cartItems)
                    {
                        this._commandDispatcher.Dispatch(new RemoveCartItemCommand(cart.MemberId, cartItem.Id));
                    }

                    IList<PurchasableItemViewModel> viewModel = cartItems.Select(o => new PurchasableItemViewModel(o.Product)).ToList();

                    return this.View("ProductsRemoved", viewModel);
                }
            }

            return this.Redirect(this.Request.UrlReferrer.ToString());
        }
 public CartViewModel(Cart cart, bool isOpen)
 {
     this.Items = cart.Items.Select(o => new CartItemViewModel(o)).OrderBy(o => o.IsHire).ToList();
     this.Total = cart.Total.ToString("C2");
     this.IsOpen = isOpen;
 }
        public ActionResult Index(Member member, Order order, Cart cart, HireDatesViewModel hireDates)
        {
            if (this.HttpContext.User.Identity.IsAuthenticated)
            {
                Guid orderGuid = Guid.NewGuid();
                if (order == null)
                {
                    this._commandDispatcher.Dispatch(new AddCartItemsToOrderCommand(orderGuid, member, cart, hireDates.PartyDate));
                }
                else
                {
                    orderGuid = order.Guid;
                }

                return this.RedirectToRoute(Routes.Checkout.CustomisedInvitations, new { orderGuid = orderGuid });
            }

            return this.LoginRegister(null);
        }
        public ActionResult Guest(Member member, Order order, Cart cart, HireDatesViewModel hireDates)
        {
            this._commandDispatcher.Dispatch(new RegisterGuestCommand(member.Guid));

            Guid orderGuid = Guid.NewGuid();
            if (order == null)
            {
                this._commandDispatcher.Dispatch(new AddCartItemsToOrderCommand(orderGuid, member, cart, hireDates.PartyDate));
            }
            else
            {
                orderGuid = order.Guid;
            }

            return this.RedirectToRoute(Routes.Checkout.CustomisedInvitations, new { orderGuid = orderGuid });
        }
        public ActionResult Register(RegisterViewModel register, Member existingMemberRecord, Cart cart)
        {
            if(this.ModelState.IsValid)
            {
                RegisterCommand command = new RegisterCommand(existingMemberRecord.Guid, register.RegisterEmail, register.Password);
                this._commandDispatcher.Dispatch(command);

                Member member = this._queryDispatcher.Dispatch<Member, GetMemberByEmailQuery>(new GetMemberByEmailQuery(register.RegisterEmail));

                // TODO: Update carts memberId
                var result = this._loginProvider.Login(this.Request.GetOwinContext().Authentication, register.RegisterEmail, register.Password, false);

                if (result.Successful)
                {
                    if (cart != null && cart.MemberId != result.Member.Guid)
                    {
                        // convert cart
                        this._commandDispatcher.Dispatch(new ChangeCartsMemberGuidCommand(cart, result.Member.Guid));
                    }

                    if (string.IsNullOrEmpty(register.ReturnUrl))
                    {
                        return this.RedirectToRoute(Routes.Home);
                    }
                    else
                    {
                        return this.Redirect(register.ReturnUrl);
                    }
                }

            }

            return this.Register(register.ReturnUrl);
        }
 public ProductAddedToCart(Cart cart, Product product)
 {
     this.Cart = cart;
     this.Product = product;
 }