private AddressRecapViewModel GetAddressRecapViewModel(Customer.Address address) { if (address != null) { return(new AddressRecapViewModel { City = address.City, Company = address.Company, CountryName = address.CountryName, DigiCode = address.DigiCode, Email = address.Email, FaxNumber = address.FaxNumber, FirstName = address.FirstName, Floor = address.Floor, LastName = address.LastName, Line1 = address.Line1, Line2 = address.Line2, Line3 = address.Line3, MiddleName = address.MiddleName, MobileNumber = address.MobileNumber, Name = address.Name, PhoneNumber = address.PhoneNumber, RegionName = address.RegionName, ZipCode = address.ZipCode, ShippingAddressIsTheSame = address.AddressId == this.BillingAddressId && !this.ShippingAddressIsDifferent }); } return(null); }
private ActionResult BuildCustomerAddressRecap(Nullable <Guid> addressId) { Customer.Address address = null; if (addressId.HasValue) { this._webStoreServices.UsingClient( c => address = c.CustomerClient.GetAddresses(this._webStoreServices.CurrentUserName, this._webStoreServices.CurrentCultureId).FirstOrDefault(a => a.AddressId == addressId) ); } return(this.BuildAddressRecapShapeResult(this.GetAddressRecapViewModel(address))); }
public ActionResult SaveAddress(AddressViewModel viewModel) { if (this.ModelState.IsValid) { Boolean success = true; this._webStoreServices.UsingClient( c => { if (viewModel.RegionId.HasValue || (!viewModel.RegionId.HasValue && !c.StoreClient.GetRegions(viewModel.CountryId.Value, this._webStoreServices.CurrentCultureId).Any())) { List <Customer.Address> addresses = c.CustomerClient.GetAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, this._webStoreServices.CurrentCultureId).ToList(); if (addresses.Any(a => a.Name.Equals(viewModel.Name, StringComparison.InvariantCulture) && a.AddressId != viewModel.AddressId)) { success = false; this.ModelState.AddModelError("DuplicatedName", this._localizer("Address name already used").ToString()); } else { Customer.Address newAddress = this.GetAddress(viewModel); Customer.Address previousAddress = addresses.FirstOrDefault(a => a.AddressId == viewModel.AddressId); addresses.Add(newAddress); addresses.Remove(previousAddress); c.CustomerClient.UpdateAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, addresses); if (previousAddress == null) { this._addressEventHandlers.Trigger(h => h.Created(newAddress)); } else { this._addressEventHandlers.Trigger(h => h.Updated(newAddress)); } } } else { success = false; this.ModelState.AddModelError("RegionRequired", this._localizer("Region is required").ToString()); } } ); if (success) { return(this.Json(new { name = viewModel.Name, shippingAddressIsDifferent = viewModel.ShippingAddressIsDifferent })); } } return(this.BuildAddressShape(viewModel)); }
private void SetAddresses(Guid billingAddress, Nullable <Guid> shippingAddressId) { this._webStoreServices.UsingClient( c => { Guid finalShippingAddressId = shippingAddressId ?? billingAddress; Customer.Address address = c.CustomerClient.GetAddresses(this._webStoreServices.CurrentUserName, this._webStoreServices.CurrentCultureId) .FirstOrDefault(a => a.AddressId == finalShippingAddressId); this._webStoreServices.CurrentRegionId = address.RegionId; this._webStoreServices.CurrentCountryId = address.CountryId; c.BasketClient.SetCustomerAddressToBasket(this._webStoreServices.CurrentUserName, this._webStoreServices.BasketName, billingAddress, shippingAddressId); } ); }
public void DeleteAddress(Guid addressId) { this._webStoreServices.UsingClient(c => { List <Customer.Address> addresses = c.CustomerClient.GetAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, this._webStoreServices.CurrentCultureId).ToList(); Customer.Address addressToRemove = addresses.FirstOrDefault(a => a.AddressId == addressId); if (addressToRemove != null) { addresses.Remove(addressToRemove); c.CustomerClient.UpdateAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, addresses); this._addressEventHandlers.Trigger(h => h.Removed(addressToRemove)); } } ); }
public PartialViewResult GetAddress(Guid addressId, Nullable <Boolean> promptShippingAddressIsDifferent, Nullable <Boolean> shippingAddressIsDifferent) { AddressViewModel viewModel = null; this._webStoreServices.UsingClient( c => { Customer.Address address = c.CustomerClient.GetAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, this._webStoreServices.CurrentCultureId) .FirstOrDefault(a => a.AddressId == addressId); if (address != null) { viewModel = new AddressViewModel { PromptShippingAddressIsDifferent = promptShippingAddressIsDifferent.HasValue && promptShippingAddressIsDifferent.Value, ShippingAddressIsDifferent = shippingAddressIsDifferent.HasValue && shippingAddressIsDifferent.Value, Named = true, AddressId = address.AddressId, City = address.City, Company = address.Company, CountryId = address.CountryId, DigiCode = address.DigiCode, Email = address.Email, FaxNumber = address.FaxNumber, FirstName = address.FirstName, Floor = address.Floor, LastName = address.LastName, Line1 = address.Line1, Line2 = address.Line2, Line3 = address.Line3, MiddleName = address.MiddleName, MobileNumber = address.MobileNumber, Name = address.Name, PhoneNumber = address.PhoneNumber, RegionId = address.RegionId, ZipCode = address.ZipCode }; } } ); return(this.BuildAddressShape(viewModel)); }