Esempio n. 1
0
        public ActionResult AccountProfile(AccountProfileModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _auth0Helper.UpdateAuth0User(model);

                    SnuffoSettings.ShowMessage(TempData, "Profile Updated", "Your profile has been updated", AlertMessageType.Success);
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Esempio n. 2
0
        public ActionResult UpdateOrderCheckoutAddress(AccountAddressModel model)
        {
            model.ContactAddress.AddressTypeId = AddressType.Default.Id;
            model.ContactAddress.FirstName     = model.FirstName;
            model.ContactAddress.LastName      = model.LastName;
            model.ContactAddress.Email         = model.EmailAddress;
            model.ContactAddress.Phone         = model.Phone;

            base.SuppressValidation(model.GetPropertyName(x => x.ContactAddress.Phone));
            base.SuppressValidation(model.GetPropertyName(x => x.ContactAddress.AddressTypeId));
            base.SuppressValidation(model.GetPropertyName(x => x.ShippingAddress.AddressTypeId));
            base.SuppressValidation(model.GetPropertyName(x => x.ShippingAddress.Phone));

            if (model.ShippingAddress != null)
            {
                model.ShippingAddress.AddressTypeId = AddressType.ShipAddress.Id;
            }

            if (model.HasSameAddress)
            {
                base.SuppressValidation(model.GetPropertyName(x => x.ShippingAddress));
                model.ShippingAddress = null;
            }

            if (!CurrentUser.IsAuthenticated)
            {
                base.SuppressValidation(model.GetPropertyName(x => x.UserId));
            }
            else
            {
                if (model.HasSameAddress)
                {
                    UvendiaContext.Addresses.DeleteByUseryIdAndAddressType(CurrentUser.UserId, AddressType.ShipAddress);
                }
            }

            if (ModelState.IsValid)
            {
                // Save user data
                if (CurrentUser.IsAuthenticated)
                {
                    _auth0Helper.UpdateAuth0User(model);
                }

                model.ContactAddress.CreatedBy = CurrentUser.UserId;
                var addresses = new List <Address>()
                {
                    model.ContactAddress
                };
                if (model.ShippingAddress != null)
                {
                    model.ShippingAddress.CreatedBy = CurrentUser.UserId;
                    model.ShippingAddress.Phone     = model.ContactAddress.Phone;
                    addresses.Add(model.ShippingAddress);
                }

                UvendiaContext.Addresses.Save(addresses);

                var currentCart = CurrentCart.Create(SnuffoSettings.STORE_NAME);
                var order       = currentCart.GetOrder();

                // Attach address to order
                var invoiceAddress = addresses.Single(a => a.AddressTypeId == AddressType.Default.Id);
                order.InvoiceAddressId = invoiceAddress.Id;
                order.ShipAddressId    = (model.ShippingAddress == null) ? (long?)null : addresses.Single(a => a.AddressTypeId != AddressType.Default.Id).Id;

                // Save the order
                currentCart.SaveOrder(order);

                if (order.HasOrderProductDetails())
                {
                    return(Redirect($"/{CurrentUser.LanguageCode}/cart/checkout-shipping"));
                }
                else
                {
                    return(Redirect($"/{CurrentUser.LanguageCode}/cart/checkout-payment"));
                }
            }

            return(CurrentUmbracoPage());
        }