Exemplo n.º 1
0
 private AddressViewModel Initialize(AddressViewModel viewModel)
 {
     if (viewModel != null)
     {
         viewModel.Countries = this._webStoreServices.StoreContext.AvailableCountries.Select(ac => new SelectListItem { Text = ac.Name, Value = ac.CountryId.ToString() });
         if (viewModel.CountryId.HasValue)
         {
             this._webStoreServices.UsingClient(c => viewModel.Regions = c.StoreClient.GetRegions(viewModel.CountryId.Value).Select(r => new SelectListItem { Text = r.Name, Value = r.RegionId.ToString() }));
         }
     }
     return viewModel;
 }
Exemplo n.º 2
0
 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).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
                 };
             }
         }
     );
     this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
     return this.BuildAddressShape(viewModel);
 }
Exemplo n.º 3
0
 private ShapePartialResult BuildAddressShape(AddressViewModel viewModel)
 {
     return new ShapePartialResult(this, this._shapeFactory.EditorTemplate(TemplateName: "User/Address", Model: this.Initialize(viewModel)));
 }
Exemplo n.º 4
0
 private Customer.Address GetAddress(AddressViewModel viewModel)
 {
     return new Customer.Address
     {
         AddressId = viewModel.AddressId.HasValue ? viewModel.AddressId.Value : Guid.NewGuid(),
         City = viewModel.City,
         Company = viewModel.Company,
         CountryId = viewModel.CountryId.Value,
         DigiCode = viewModel.DigiCode,
         Email = viewModel.Email,
         FaxNumber = viewModel.FaxNumber,
         FirstName = viewModel.FirstName,
         Floor = viewModel.Floor,
         LastName = viewModel.LastName,
         Line1 = viewModel.Line1,
         Line2 = viewModel.Line2,
         Line3 = viewModel.Line3,
         MiddleName = viewModel.MiddleName,
         MobileNumber = viewModel.MobileNumber,
         Name = viewModel.Name,
         PhoneNumber = viewModel.PhoneNumber,
         RegionId = viewModel.RegionId,
         ZipCode = viewModel.ZipCode
     };
 }
Exemplo n.º 5
0
 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).Any()))
                 {
                     List<Customer.Address> addresses = c.CustomerClient.GetAddresses(this._orchardServices.WorkContext.CurrentUser.UserName).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
                     {
                         addresses.Remove(addresses.FirstOrDefault(a => a.AddressId == viewModel.AddressId));
                         addresses.Add(this.GetAddress(viewModel));
                         c.CustomerClient.UpdateAddresses(this._orchardServices.WorkContext.CurrentUser.UserName, addresses);
                     }
                 }
                 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 UpdateAddress(Address address, AddressViewModel viewModel)
 {
     address.City = viewModel.City;
     address.Company = viewModel.Company;
     address.CountryId = viewModel.CountryId.Value;
     address.DigiCode = viewModel.DigiCode;
     address.Email = viewModel.Email;
     address.FaxNumber = viewModel.FaxNumber;
     address.FirstName = viewModel.FirstName;
     address.Floor = viewModel.Floor;
     address.LastName = viewModel.LastName;
     address.Line1 = viewModel.Line1;
     address.Line2 = viewModel.Line2;
     address.Line3 = viewModel.Line3;
     address.MiddleName = viewModel.MiddleName;
     address.MobileNumber = viewModel.MobileNumber;
     address.PhoneNumber = viewModel.PhoneNumber;
     address.RegionId = viewModel.RegionId;
     address.ZipCode = viewModel.ZipCode;
 }
 private ActionResult RegisterAddress(Address address, AddressViewModel viewModel)
 {
     if (this.ModelState.IsValid)
     {
         Boolean success = false;
         this._webStoreServices.UsingClient(
             c =>
             {
                 if (viewModel.RegionId.HasValue || (!viewModel.RegionId.HasValue && !c.StoreClient.GetRegions(viewModel.CountryId.Value).Any()))
                 {
                     success = true;
                 }
                 else
                 {
                     success = false;
                     this.ModelState.AddModelError("RegionRequired", this._localizer("Region is required").ToString());
                 }
             }
         );
         if (success)
         {
             this.UpdateAddress(address, viewModel);
             if (address == this.RawBillingAddress)
             {
                 this.ShippingAddressIsDifferent = viewModel.ShippingAddressIsDifferent;
                 if (!this.ShippingAddressIsDifferent)
                 {
                     this.SetAddresses(this.RawBillingAddress, null);
                 }
                 return this.Json(new { shippingAddressIsDifferent = this.ShippingAddressIsDifferent });
             }
             else
             {
                 this.SetAddresses(this.RawBillingAddress, this.RawShippingAddress);
                 return this.Json(new { success = true });
             }
         }
     }
     this.Initialize(viewModel);
     return new ShapePartialResult(this, this._shapeFactory.EditorTemplate(TemplateName: "User/Address", Model: viewModel));
 }
 private AddressViewModel GetAddressViewModel(Address address)
 {
     Boolean isBillingAddress = address == this.RawBillingAddress;
     AddressViewModel viewModel = new AddressViewModel
     {
         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,
         PhoneNumber = address.PhoneNumber,
         RegionId = address.RegionId,
         ZipCode = address.ZipCode,
         PromptShippingAddressIsDifferent = isBillingAddress,
         PromptEmail = isBillingAddress,
         ShippingAddressIsDifferent = this.ShippingAddressIsDifferent,
         DisplayNexButton = true,
         Named = false
     };
     this.Initialize(viewModel);
     return viewModel;
 }
 public ActionResult RegisterShippingAddress(AddressViewModel viewModel)
 {
     return this.RegisterAddress(this.RawShippingAddress, viewModel);
 }