Ejemplo n.º 1
0
        public ActionResult AddressAdd()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var model = new AddressModel();
            PrepareModel(model:model,
                address: null
                );

            model.Email = _workContext.CurrentCustomer.Email;
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult AddressAdd(AddressModel model, FormCollection form)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;

            if (ModelState.IsValid)
            {

                var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(model.ZipPostalCode);

                var address = new Address();

                address.Address1 = model.Address1;
                address.Address2 = model.Address2;

                address.Email = model.Email;

                if (zipcodeResult != null)
                {
                    address.City = model.City;
                    address.State = model.StateProvinceName;
                }

                address.PhoneNumber = model.PhoneNumber;
                address.ZipPostalCode = model.ZipPostalCode;
                address.CreatedOnUtc = DateTime.UtcNow;

                customer.Addresses.Add(address);
                _customerService.UpdateCustomer(customer);

                return RedirectToRoute("CustomerAddresses");
            }

            //If we got this far, something failed, redisplay form

            return View(model);
        }
Ejemplo n.º 3
0
 protected void PrepareModel(AddressModel model, Address address)
 {
     if (address != null)
     {
         model.Id = address.Id;
         model.Address1 = address.Address1;
         model.Address2 = address.Address2;
         model.City = address.City;
         model.Email = _workContext.CurrentCustomer.Email; // address.Email;
         model.PhoneNumber = address.PhoneNumber;
         model.StateProvinceName = address.State;
         model.ZipPostalCode = address.ZipPostalCode;
     }
 }
Ejemplo n.º 4
0
        public ActionResult Addresses()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;

            var model = new CustomerAddressListModel();
            var addresses = customer.Addresses
                .ToList();
            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                PrepareModel(
                    model:addressModel,
                    address: address);
                model.Addresses.Add(addressModel);
            }
            return View(model);
        }
Ejemplo n.º 5
0
        public ActionResult AddressEdit(AddressModel model, int addressId, FormCollection form)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;
            //find address (ensure that it belongs to the current customer)
            var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
            if (address == null)
                //address is not found
                return RedirectToRoute("CustomerAddresses");

            if (ModelState.IsValid)
            {
                var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(model.ZipPostalCode);

                address.Address1 = model.Address1;
                address.Address2 = model.Address2;

                if (zipcodeResult != null)
                {
                    address.City = model.City;
                    address.State = model.StateProvinceName;
                }

                address.Email = model.Email;
                address.PhoneNumber = model.PhoneNumber;
                address.ZipPostalCode = model.ZipPostalCode;
                _addressService.UpdateAddress(address);

                return RedirectToRoute("CustomerAddresses");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 6
0
        public ActionResult AddressEdit(int addressId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
                return new HttpUnauthorizedResult();

            var customer = _workContext.CurrentCustomer;
            //find address (ensure that it belongs to the current customer)
            var address = customer.Addresses.FirstOrDefault(a => a.Id == addressId);
            if (address == null)
                //address is not found
                return RedirectToRoute("CustomerAddresses");

            var model = new AddressModel();
            PrepareModel(model: model,
                address: address
                );

            return View(model);
        }