/// <summary>
        /// Updates the address
        /// </summary>
        /// <param name="address">Address</param>
        public virtual void UpdateAddress(Address address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            _addressRepository.Update(address);
        }
        public bool addAddress(GutterCleanOrder entity)
        {
            var customer = _workContext.CurrentCustomer;

               // var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(entity.Zipcode);

            var address = new Address();

            address.Address1 = entity.Address;
            //address.Address2 = entity.Address2;

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

            address.PhoneNumber = model.PhoneNumber; */
            address.ZipPostalCode = entity.Zipcode;
            address.CreatedOnUtc = entity.CreatedOnUtc;//DateTime.UtcNow;

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

            return true;
        }
        /// <summary>
        /// Inserts an address
        /// </summary>
        /// <param name="address">Address</param>
        public virtual void InsertAddress(Address address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            address.CreatedOnUtc = DateTime.UtcNow;

            _addressRepository.Insert(address);
        }
        /// <summary>
        /// Gets a value indicating whether address is valid (can be saved)
        /// </summary>
        /// <param name="address">Address to validate</param>
        /// <returns>Result</returns>
        public virtual bool IsAddressValid(Address address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            if (String.IsNullOrWhiteSpace(address.Email))
                return false;

            return true;
        }
        public ActionResult GutterCleanInfoRegister(GutterCleanInfoModel model, bool captchaValid)
        {
            GutterCleanRequestModel requestModel = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
            if (requestModel == null)
            {
                return RedirectToRoute("GutterCleanRequest");
            }

            string returnUrl = string.Empty;

            if (!captchaValid)
            {
                ModelState.AddModelError("", "Wrong Captcha code.");
            }

            var zipcodeResult = _zipCodeService.GetZipCodeDetailByZipcode(model.ZipCode);
            if (zipcodeResult != null)
            {

            }
            else
            {
                ModelState.AddModelError("", "Zipcode is not valid.");

            }

            if (ModelState.IsValid)
            {

                if (!_workContext.CurrentCustomer.IsRegistered())
                {
                    //Already registered customer.
                    _authenticationService.SignOut();

                    //Save a new record
                    _workContext.CurrentCustomer = _customerService.InsertGuestCustomer();

                    var customer = _workContext.CurrentCustomer;
                    customer.FirstName = model.FirstName;
                    customer.LastName = model.LastName;

                    customer.Address1 = model.Address;
                    customer.ZipPostalCode = model.ZipCode;

                    bool isApproved = true;
                    string password = Guid.NewGuid().ToString();
                    var registrationRequest = new CustomerRegistrationRequest(customer, model.Email, password.Substring(0, 8), isApproved);

                    var registrationResult = _customerService.RegisterCustomer(registrationRequest);
                    if (registrationResult.Success)
                    {

                        //login customer now
                        if (isApproved)
                            _authenticationService.SignIn(customer, true);

                        switch (UserRegistrationType.Standard)
                        {

                            case UserRegistrationType.Standard:
                                {

                                    var address = new Address();
                                    address.Address1 = model.Address;
                                    address.Address2 = "";
                                    address.City = zipcodeResult.CityName;
                                    address.Email = model.Email;
                                    address.State = zipcodeResult.StateName;
                                    address.PhoneNumber = "";
                                    address.ZipPostalCode = model.ZipCode;
                                    address.CreatedOnUtc = DateTime.UtcNow;

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

                                    //send email
                                    _workflowMessageService.SendCustomerWelcomeMessage(customer);

                                    GutterCleanRequestModel Requestmodel = _httpContext.Session["GutterCleanRequestModel"] as GutterCleanRequestModel;
                                    if (Requestmodel == null)
                                    {
                                        return RedirectToRoute("GutterCleanRequest");
                                    }
                                    else
                                    {

                                        return RedirectToRoute("ProcessPayment");
                                    }
                                }
                            default:
                                {
                                    return RedirectToRoute("GutterCleanRequest");

                                }
                        }
                    }

                    //errors
                    foreach (var error in registrationResult.Errors)
                        ModelState.AddModelError("", error);
                }
                else
                {
                    /// user is already registered
                    return RedirectToRoute("ProcessPayment");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        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);
        }
 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;
     }
 }