Ejemplo n.º 1
0
        public JsonResult AddressDelete(DeletePartyInputModelItem model)
        {
            try
            {
                Assert.ArgumentNotNull(model, "model");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var addresses = new List <CommerceParty>();
                var response  = this.AccountManager.RemovePartiesFromCurrentUser(this.CurrentStorefront, this.CurrentVisitorContext, model.ExternalId);
                var result    = new AddressListItemJsonResult(response.ServiceProviderResult);
                if (response.ServiceProviderResult.Success)
                {
                    addresses = this.AllAddresses(result);
                }

                result.Initialize(addresses, null);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("AddressDelete", this, e);
                return(Json(new BaseJsonResult("AddressDelete", e), JsonRequestBehavior.AllowGet));
            }
        }
        private void GetUserInfo(CheckoutDataBaseJsonResult result)
        {
            var isUserAuthenticated = Sitecore.Context.User.IsAuthenticated;

            result.IsUserAuthenticated = isUserAuthenticated;
            result.UserEmail           = isUserAuthenticated && !Context.User.Profile.IsAdministrator ? this.AccountManager.ResolveCommerceUser().Result.Email : string.Empty;
            if (!isUserAuthenticated)
            {
                return;
            }

            var addresses = new List <CommerceParty>();
            var response  = this.AccountManager.GetCurrentCustomerParties(this.CurrentStorefront, this.CurrentVisitorContext);

            if (response.ServiceProviderResult.Success && response.Result != null)
            {
                addresses = response.Result.ToList();
            }

            var addressesResult = new AddressListItemJsonResult();

            addressesResult.Initialize(addresses, null);
            result.UserAddresses = addressesResult;
            result.SetErrors(response.ServiceProviderResult);
        }
        public AddressListItemJsonResult GetAddressList()
        {
            var result    = new AddressListItemJsonResult();
            var addresses = this.AllAddresses(result);
            var countries = this.GetAvailableCountries(result);

            result.Initialize(addresses, countries);

            return(result);
        }
        public AddressListItemJsonResult DeleteAddresses(DeletePartyInputModelItem model)
        {
            var addresses = new List <CommerceParty>();
            var response  = this.AccountManager.RemovePartiesFromCurrentUser(this.CurrentStorefront, this.CurrentVisitorContext, model.ExternalId);
            var result    = new AddressListItemJsonResult(response.ServiceProviderResult);

            if (response.ServiceProviderResult.Success)
            {
                addresses = this.AllAddresses(result);
            }

            result.Initialize(addresses, null);

            return(result);
        }
Ejemplo n.º 5
0
 public JsonResult AddressList()
 {
     try
     {
         var result    = new AddressListItemJsonResult();
         var addresses = this.AllAddresses(result);
         var countries = this.GetAvailableCountries(result);
         result.Initialize(addresses, countries);
         return(Json(result, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         CommerceLog.Current.Error("AddressList", this, e);
         return(Json(new BaseJsonResult("AddressList", e), JsonRequestBehavior.AllowGet));
     }
 }
        public AddressListItemJsonResult ModifyAddress(PartyInputModelItem model)
        {
            var addresses    = new List <CommerceParty>();
            var userResponse = this.AccountManager.GetUser(Context.User.Name);
            var result       = new AddressListItemJsonResult(userResponse.ServiceProviderResult);

            if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
            {
                var commerceUser = userResponse.Result;
                var customer     = new CommerceCustomer {
                    ExternalId = commerceUser.ExternalId
                };
                var party = new CommerceParty
                {
                    ExternalId    = model.ExternalId,
                    Name          = model.Name,
                    Address1      = model.Address1,
                    City          = model.City,
                    Country       = model.Country,
                    State         = model.State,
                    ZipPostalCode = model.ZipPostalCode,
                    PartyId       = model.PartyId,
                    IsPrimary     = model.IsPrimary
                };

                if (string.IsNullOrEmpty(party.ExternalId))
                {
                    // Verify we have not reached the maximum number of addresses supported.
                    var numberOfAddresses = this.AllAddresses(result).Count;

                    if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses)
                    {
                        var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MaxAddressLimitReached);
                        result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses));
                        result.Success = false;
                    }
                    else
                    {
                        party.ExternalId = Guid.NewGuid().ToString("B");

                        var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> {
                            party
                        });
                        result.SetErrors(response.ServiceProviderResult);
                        if (response.ServiceProviderResult.Success)
                        {
                            addresses = this.AllAddresses(result);
                        }

                        result.Initialize(addresses, null);
                    }
                }
                else
                {
                    var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> {
                        party
                    });
                    result.SetErrors(response.ServiceProviderResult);

                    if (response.ServiceProviderResult.Success)
                    {
                        addresses = this.AllAddresses(result);
                    }

                    result.Initialize(addresses, null);
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public JsonResult AddressModify(PartyInputModelItem model)
        {
            try
            {
                Assert.ArgumentNotNull(model, "model");

                var validationResult = new BaseJsonResult();
                this.ValidateModel(validationResult);
                if (validationResult.HasErrors)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                var addresses    = new List <CommerceParty>();
                var userResponse = this.AccountManager.GetUser(Context.User.Name);
                var result       = new AddressListItemJsonResult(userResponse.ServiceProviderResult);
                if (userResponse.ServiceProviderResult.Success && userResponse.Result != null)
                {
                    var commerceUser = userResponse.Result;
                    var customer     = new CommerceCustomer {
                        ExternalId = commerceUser.ExternalId
                    };
                    var party = new CommerceParty
                    {
                        ExternalId    = model.ExternalId,
                        Name          = model.Name,
                        Address1      = model.Address1,
                        City          = model.City,
                        Country       = model.Country,
                        State         = model.State,
                        ZipPostalCode = model.ZipPostalCode,
                        PartyId       = model.PartyId,
                        IsPrimary     = model.IsPrimary
                    };

                    if (string.IsNullOrEmpty(party.ExternalId))
                    {
                        // Verify we have not reached the maximum number of addresses supported.
                        int numberOfAddresses = this.AllAddresses(result).Count;
                        if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses)
                        {
                            var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MaxAddressLimitReached);
                            result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses));
                            result.Success = false;
                        }
                        else
                        {
                            var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List <CommerceParty> {
                                party
                            });
                            result.SetErrors(response.ServiceProviderResult);
                            if (response.ServiceProviderResult.Success)
                            {
                                addresses = this.AllAddresses(result);
                            }

                            result.Initialize(addresses, null);
                        }
                    }
                    else
                    {
                        var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List <CommerceParty> {
                            party
                        });
                        result.SetErrors(response.ServiceProviderResult);
                        if (response.ServiceProviderResult.Success)
                        {
                            addresses = this.AllAddresses(result);
                        }

                        result.Initialize(addresses, null);
                    }
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                CommerceLog.Current.Error("AddressModify", this, e);
                return(Json(new BaseJsonResult("AddressModify", e), JsonRequestBehavior.AllowGet));
            }
        }