Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
示例#1
0
		protected override void OnSetUp()
		{
			using (var session = OpenSession())
			using (var transaction = session.BeginTransaction())
			{
				var john = new Customer
				{
					AssignedId = 1,
					Name = "John"
				};
				var other = new Customer
				{
					AssignedId = 2,
					Name = "Other"
				};
				var johnBusiness = new CustomerAddress
				{
					Customer = john,
					Type = "Business",
					Address = "123 E West Ave.",
					City = "New York",
					OtherCustomer = other
				};

				session.Save(john);
				session.Save(other);
				session.Save(johnBusiness);
				session.Flush();
				transaction.Commit();
			}
		}
 public override void DeleteContactAddress(CustomerAddress address)
 {
     var addressToDelete = _addresses.FirstOrDefault(x => x.AddressId == address.AddressId);
     if (addressToDelete != null)
     {
         _addresses.Remove(addressToDelete);
     }
 }
 public override void UpdateContactAddress(CustomerAddress address)
 {
     var addressToUpdate = _addresses.FirstOrDefault(x => x.AddressId == address.AddressId);
     if (addressToUpdate != null)
     {
         addressToUpdate = address;
     }
 }
        /// <summary>
        /// Gets the defaults.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns></returns>
        protected string GetDefaults(CustomerAddress address)
        {
            var ret = "";
            var contact = CustomerContext.Current.CurrentContact;

            if (contact.PreferredBillingAddressId.HasValue && contact.PreferredBillingAddressId == address.AddressId)
                ret += "<strong>Default Billing</strong><br/>";

            if (contact.PreferredShippingAddressId.HasValue && contact.PreferredShippingAddressId == address.AddressId)
                ret += "<strong>Default Shipping</strong>";
            return ret;
        }
 /// <summary>
 /// If the customer has not selected a country, we pick the 
 /// first country for the current market.
 /// </summary>
 /// <param name="address">The address.</param>
 private static void CheckCountryCode(CustomerAddress address)
 {
     if (string.IsNullOrEmpty(address.CountryCode))
     {
         var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>(); // TODO: constructor inject
         var market = currentMarket.GetCurrentMarket();
         if (market != null && market.Countries.Any())
         {
             address.CountryCode = market.Countries.FirstOrDefault();
         }
     }
 }
        private void LoadCustomerAddresses()
        {
            SL8_WTF_DataBaseSettings objSL8_WTF_DataBaseSettings;
            DataTable       objDataTable = new DataTable();
            SqlDataAdapter  objDataAdapter;
            SqlCommand      objSQLCommand;
            CustomerAddress objCustomerAddress;
            string          strSQL;


            objSL8_WTF_DataBaseSettings = new SL8_WTF_DataBaseSettings();
            strSQL = QueryDefinitions.GetQuery("SelectCustomerAddresses", new string[] { mintCustomerNumber.ToString() });
            objSL8_WTF_DataBaseSettings.SQLConnection.Open();
            objSQLCommand  = new SqlCommand(strSQL, objSL8_WTF_DataBaseSettings.SQLConnection);
            objDataAdapter = new SqlDataAdapter(objSQLCommand);
            objDataAdapter.Fill(objDataTable);

            mobjCustomerAddressList = new BindingList <CustomerAddress>();

            foreach (DataRow objRow in objDataTable.Rows)
            {
                objCustomerAddress = new CustomerAddress();

                objCustomerAddress.Name         = objRow["Name"].ToString();
                objCustomerAddress.AddressLine1 = objRow["Addr##1"].ToString();
                objCustomerAddress.AddressLine2 = objRow["Addr##2"].ToString();
                objCustomerAddress.AddressLine3 = objRow["Addr##3"].ToString();
                objCustomerAddress.AddressLine4 = objRow["Addr##4"].ToString();
                objCustomerAddress.City         = objRow["City"].ToString();
                objCustomerAddress.State        = objRow["State"].ToString();
                objCustomerAddress.ZipCode      = objRow["ZIP"].ToString();
                objCustomerAddress.Country      = objRow["Country"].ToString();

                mobjCustomerAddressList.Add(objCustomerAddress);
            }

            mintSelectedAddressIndex = -1;

            if (objDataTable.Rows.Count > 0)
            {
                SelectCustomerAddress(0);
                grpAddress.Enabled = (mobjSelectedLabel.AddressLineCount > 0);
            }
            else
            {
                MessageBox.Show("No addresses found for customer!", "No Addresses Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                lblAddrCt.Text     = "";
                grpAddress.Enabled = false;
            }
        }
示例#7
0
        public IActionResult Add([FromBody] dynamic customerData)
        {
            ValidateSession();
            int customerId = 0;
            int billingAddressId, shippingAddressId = 0;

            try
            {
                if (customerData != null)
                {
                    Lms_CustomerPoco customerPoco = JsonConvert.DeserializeObject <Lms_CustomerPoco>(JsonConvert.SerializeObject(customerData[0]));

                    CustomerAddress customerBillingAddress  = JsonConvert.DeserializeObject <CustomerAddress>(JsonConvert.SerializeObject(customerData[1]));
                    CustomerAddress customerShippingAddress = JsonConvert.DeserializeObject <CustomerAddress>(JsonConvert.SerializeObject(customerData[2]));

                    customerId = CreateNewCustomer(customerPoco);
                    customerBillingAddress.CustomerId  = customerId;
                    customerShippingAddress.CustomerId = customerId;

                    if (customerId < 1)
                    {
                        DeleteCustomerById(customerId);
                        return(Json(""));
                    }

                    billingAddressId  = AddOrGetAddress(customerBillingAddress);
                    shippingAddressId = AddOrGetAddress(customerShippingAddress);
                    if (billingAddressId < 1 && shippingAddressId < 1)
                    {
                        DeleteCustomerById(customerId);
                        return(Json(""));
                    }

                    if (billingAddressId > 0)
                    {
                        SetBillingShippingAddress(customerId, billingAddressId, (byte)Enum_AddressType.Billing, true);
                    }

                    if (shippingAddressId > 0)
                    {
                        SetBillingShippingAddress(customerId, shippingAddressId, (byte)Enum_AddressType.Shipping, true);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(customerId.ToString()));
        }
示例#8
0
 internal int DeleteCustomerAddress(CustomerAddress CustomerAddress)
 {
     try
     {
         context.Entry(CustomerAddress).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
         return(100);
     }
     catch (Exception ex)
     {
         CustomerAddress.ErrorMessage = ex.Message;
         return(404);
     }
 }
示例#9
0
        public object SetDefaultAddress(CustomerAddress addressObj)
        {
            OperationsStatusViewModel OperationsStatusViewModelObj = null;

            try
            {
                OperationsStatusViewModelObj = Mapper.Map <OperationsStatus, OperationsStatusViewModel>(_customerBusiness.SetDefaultAddress(addressObj.CustomerID, addressObj.ID));
                return(JsonConvert.SerializeObject(new { Result = true, Records = OperationsStatusViewModelObj }));
            }
            catch (Exception ex)
            {
                return(JsonConvert.SerializeObject(new { Result = false, Message = ex.Message }));
            }
        }
示例#10
0
        public void UpdateCustomerInfo(Customer customer, CustomerAddress billingAddress, CustomerAddress shippingAddress)
        {
            try
            {
                var profileId = UserManager.FindById(User.Identity.GetUserId()).UserProfile.Id;

                var custo = _customerService.FindCustomerBy(profileId);

                custo.CustomerAlias   = customer.CustomerAlias;
                custo.BillingAddress  = customer.BillingAddress;
                custo.ShippingAddress = customer.ShippingAddress;
                custo.ContactEmail    = customer.ContactEmail;
                custo.ContactTel      = customer.ContactTel;

                //_customerService.UpdateCustomerInfo(custo);

                //new code: customer address
                var billingAddr  = _customerService.FindCustomerAddress(custo.Id, 1); //get billing address
                var shippingAddr = _customerService.FindCustomerAddress(custo.Id, 2); //get shipping address

                if (billingAddr != null)
                {
                    billingAddr.AddressStreet      = billingAddress.AddressStreet;
                    billingAddr.AddressCity        = billingAddress.AddressCity;
                    billingAddr.AddressProState    = billingAddress.AddressProState;
                    billingAddr.AddressPostZipCode = billingAddress.AddressPostZipCode;
                    billingAddr.AddressType        = billingAddress.AddressType;
                    billingAddr.CustomerId         = customer.Id;
                    billingAddress.AddressCountry  = "Canada";
                }

                if (shippingAddr != null)
                {
                    shippingAddr.AddressStreet      = shippingAddress.AddressStreet;
                    shippingAddr.AddressCity        = shippingAddress.AddressCity;
                    shippingAddr.AddressProState    = shippingAddress.AddressProState;
                    shippingAddr.AddressPostZipCode = shippingAddress.AddressPostZipCode;
                    shippingAddr.AddressType        = shippingAddress.AddressType;
                    shippingAddr.CustomerId         = customer.Id;
                    shippingAddr.AddressCountry     = "Canada";
                }


                _customerService.UpdateCustomerInfo(custo, billingAddress, shippingAddress);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#11
0
        public ActionResult ShowInvoiceAddressPartial(string customerId)
        {
            CustomerAddress customerAddress = new CustomerAddress();

            if (customerId == null)
            {
                return(Content(""));
            }
            else
            {
                customerAddress = _context.CustomerAddresses.Where(a => a.CustomerId == customerId && a.IsInvoiceAddress == true).Single();
            }
            return(PartialView("~/Views/Shared/_CustomerInvoiceAddress.cshtml", customerAddress));
        }
        /// <summary>
        /// Binds the address.
        /// </summary>
        public void BindAddress()
        {
            CustomerAddress address = GetCurrentAddress();

            if (address != null)
            {
                this.AddressInfo = address;
                //CommonHelper.SelectListItem(Country, address.CountryCode);
                //if (!StateTxt.Visible)
                //    CommonHelper.SelectListItem(State, address.State);
                //else
                //    StateTxt.Text = address.State;
            }
        }
        public AddressDataWindow(bool newData, int someonesId, AddressOwner addressOwner, CustomerAddress customerAddress, bool showsaveButton)
        {
            InitializeComponent();
            DropShadow.DropShadowToWindow(this);
            _newData         = newData;
            _someonesId      = someonesId;
            _addressOwner    = addressOwner;
            _customerAddress = customerAddress;
            SetShowSaveButton(showsaveButton);
            SetComboboxEntrys();
            MakeAllTextBoxesReadOnly(showsaveButton);

            DataContext = new Backend.Models.Address();
        }
示例#14
0
        /// <summary>
        /// Updates a customer's address by address name.
        /// </summary>
        /// <param name="customerId">The ID of the customer to update the address for.</param>
        /// <param name="customerAddress">The name of the address to update.</param>
        /// <returns>A CustomerAddress document instance containing the updated address.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="customerId"/> is null or empty.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="customerAddress"/>.Id is null or empty.</exception>
        /// <exception cref="ApiException">Thrown when a <see cref="Fault"/> document is returned.</exception>
        public CustomerAddress UpdateCustomerAddress(string customerId, CustomerAddress customerAddress)
        {
            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId), Properties.Resources.Error_Missing_Customer_ID);
            }

            if (string.IsNullOrEmpty(customerAddress?.Id))
            {
                throw new ArgumentNullException(nameof(customerAddress), Properties.Resources.Error_Missing_Address_Name);
            }

            throw new NotImplementedException();
        }
示例#15
0
        // DELETE: odata/CustomerAddresses(5)
        public async Task <IHttpActionResult> Delete([FromODataUri] int key)
        {
            CustomerAddress customerAddress = await db.CustomerAddresses.FindAsync(key);

            if (customerAddress == null)
            {
                return(NotFound());
            }

            db.CustomerAddresses.Remove(customerAddress);
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#16
0
        public void Validate_ValidCountry_CheckPassed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsFalse(validator.CheckFailed),
                () => Assert.IsFalse(validator.CountryNotSet),
                () => Assert.IsFalse(validator.StateNotFromCountry)
                );
        }
示例#17
0
        // GET: CustomerAddresses1/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerAddress customerAddress = db.CustomerAddresses.Find(id);

            if (customerAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(customerAddress));
        }
示例#18
0
        public OperationsStatus DeleteAddress(CustomerAddress customerAddress)
        {
            OperationsStatus operationsStatusObj = null;

            try
            {
                operationsStatusObj = _customerRepository.DeleteAddress(customerAddress);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(operationsStatusObj);
        }
示例#19
0
        public CustomerAddress GetAddressByAddress(int AddressID)
        {
            CustomerAddress Address = null;

            try
            {
                Address = _customerRepository.GetAddressByAddress(AddressID);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Address);
        }
        public void SaveToCustomerAddress(CustomerAddress customerAddress)
        {
            var customerAdressInDb =
                _context.CustomerAddress.FirstOrDefault(
                    x => x.AddressID == customerAddress.AddressID && x.CustomerID == customerAddress.CustomerID);
            if (customerAdressInDb == null)
            {
                _context.Entry(customerAddress).State = (EntityState)EntityState.Added;
            }

            _context.Entry(customerAddress.Address).State = EntityState.Unchanged;
            _context.Entry(customerAddress.Customer).State = EntityState.Unchanged;
            _context.SaveChanges();
        }
        /// <summary>
        /// If current user is registered user, try to save the OrderAddress to its Contact.
        /// </summary>
        /// <param name="orderAddress">The modified order address.</param>
        /// <param name="customerAddressType">The customer address type.</param>
        private static void TrySaveCustomerAddress(IOrderAddress orderAddress, CustomerAddressTypeEnum customerAddressType)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            var httpProfile = HttpContext.Current.Profile;
            var profile     = httpProfile == null ? null : new CustomerProfileWrapper(httpProfile);

            if (profile == null || profile.IsAnonymous)
            {
                return;
            }

            // Add to contact address
            var customerContact = PrincipalInfo.CurrentPrincipal.GetCustomerContact();

            if (customerContact != null)
            {
                var customerAddress = CustomerAddress.CreateForApplication();
                customerAddress.Name               = orderAddress.Id;
                customerAddress.AddressType        = customerAddressType;
                customerAddress.City               = orderAddress.City;
                customerAddress.CountryCode        = orderAddress.CountryCode;
                customerAddress.CountryName        = orderAddress.CountryName;
                customerAddress.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber;
                customerAddress.Email              = orderAddress.Email;
                customerAddress.EveningPhoneNumber = orderAddress.EveningPhoneNumber;
                customerAddress.FirstName          = orderAddress.FirstName;
                customerAddress.LastName           = orderAddress.LastName;
                customerAddress.Line1              = orderAddress.Line1;
                customerAddress.Line2              = orderAddress.Line2;
                customerAddress.PostalCode         = orderAddress.PostalCode;
                customerAddress.RegionName         = orderAddress.RegionName;
                customerAddress.RegionCode         = orderAddress.RegionCode;

#pragma warning disable 618
                if (customerContact.ContactAddresses == null || !IsAddressInCollection(customerContact.ContactAddresses, customerAddress))
#pragma warning restore 618
                {
                    // If there is an address has the same name with new address,
                    // rename new address by appending the index to the name.
                    var addressCount = customerContact.ContactAddresses.Count(a => a.Name == customerAddress.Name);
                    customerAddress.Name = $"{customerAddress.Name}{(addressCount == 0 ? string.Empty : "-" + addressCount.ToString())}";

                    customerContact.AddContactAddress(customerAddress);
                    customerContact.SaveChanges();
                }
            }
        }
示例#22
0
        public void Save(CustomerAddressDTO address)
        {
            using (var db = new Context())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    var addressToSave = CustomerAddress.FromDto(address);
                    db.CustomerAddress.AddOrUpdate(addressToSave);

                    db.SaveChanges();
                    transaction.Commit();
                }
            }
        }
        public CustomerContact CreateCustomer(string email, string password, string phone, OrderAddress billingAddress,
                                              OrderAddress shippingAddress, bool hasPassword, Action <MembershipCreateStatus> userCreationFailed)
        {
            MembershipCreateStatus createStatus;
            var user = Membership.CreateUser(email, password, email, null, null, true, out createStatus);

            switch (createStatus)
            {
            case MembershipCreateStatus.Success:

                Roles.AddUserToRole(user.UserName, Mediachase.Commerce.Core.AppRoles.EveryoneRole);
                Roles.AddUserToRole(user.UserName, Mediachase.Commerce.Core.AppRoles.RegisteredRole);

                var customer = CustomerContext.Current.GetContactForUser(user);
                customer.FirstName = billingAddress.FirstName;
                customer.LastName  = billingAddress.LastName;
                customer.FullName  = string.Format("{0} {1}", customer.FirstName, customer.LastName);
                customer.SetPhoneNumber(phone);
                customer.SetHasPassword(hasPassword);

                var customerBillingAddress = CustomerAddress.CreateForApplication(Mediachase.Commerce.Core.AppContext.Current.ApplicationId);
                OrderAddress.CopyOrderAddressToCustomerAddress(billingAddress, customerBillingAddress);
                customer.AddContactAddress(customerBillingAddress);
                customer.SaveChanges();
                customer.PreferredBillingAddressId = customerBillingAddress.AddressId;
                customerBillingAddress.Name        = string.Format("{0}, {1} {2}", customerBillingAddress.Line1,
                                                                   customerBillingAddress.PostalCode, customerBillingAddress.City);
                CheckCountryCode(customerBillingAddress);
                BusinessManager.Update(customerBillingAddress);
                customer.SaveChanges();

                var customerShippingAddress = CustomerAddress.CreateForApplication(Mediachase.Commerce.Core.AppContext.Current.ApplicationId);
                OrderAddress.CopyOrderAddressToCustomerAddress(shippingAddress, customerShippingAddress);
                customer.AddContactAddress(customerShippingAddress);
                customer.SaveChanges();
                customer.PreferredShippingAddressId = customerShippingAddress.AddressId;
                customerShippingAddress.Name        = string.Format("{0}, {1} {2}", customerShippingAddress.Line1,
                                                                    customerShippingAddress.PostalCode, customerShippingAddress.City);
                CheckCountryCode(customerShippingAddress);
                BusinessManager.Update(customerShippingAddress);
                customer.SaveChanges();

                return(customer);

            default:
                userCreationFailed(createStatus);
                break;
            }
            return(null);
        }
示例#24
0
 public static CustomerAddressViewModel CustomerAddressMapper(CustomerAddress address)
 {
     return(new CustomerAddressViewModel
     {
         Id = address.Id,
         Country = address.Country,
         City = address.City,
         Address1 = address.Address1,
         Address2 = address.Address2,
         Email = address.Email,
         CreatedOn = DateTime.UtcNow,
         UpdatedOn = DateTime.UtcNow,
     });
 }
示例#25
0
 /// <summary>
 /// Maps a CustomerAddress data model to a CustomerAddressModel view model
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public static CustomerAddressModel MapCustomerAddress(CustomerAddress address)
 {
     return(new CustomerAddressModel {
         Id = address.Id,
         AddressLine1 = address.AddressLine1,
         AddressLine2 = address.AddressLine2,
         City = address.City,
         State = address.State,
         PostalCode = address.PostalCode,
         Country = address.Country,
         CreatedOn = DateTime.UtcNow,
         UpdatedOn = DateTime.UtcNow,
     });
 }
示例#26
0
        public void ShoppingCart_TaxIsCorrect()
        {
            var cart = CreateCartWithCustomerInfo(Factory.CustomerAnonymous);

            cart.AddItem(Factory.SKUWithTaxes.SKUID);

            var billingAddress = new CustomerAddress(Factory.CustomerAddressUSA);

            cart.BillingAddress = billingAddress;

            var originalCart = cart.OriginalCart;

            Assert.AreEqual(cart.TotalTax, originalCart.TotalTax);
        }
示例#27
0
        protected void BindSelectedLevelAAddress()
        {
            IQueryable <CustomerAddress> addresses = UserOrganization.Addresses.Cast <CustomerAddress>().AsQueryable().Where(a => a.GetString("Name") == ddlLevelAShippingAddress.SelectedValue);

            if (addresses.Any())
            {
                CustomerAddress address = addresses.First();
                this.litSelectedShippingLine1.Text = address.Line1;
                this.litSelectedShippingLine2.Text = address.Line2;
                this.litSelectedShippingState.Text = address.State;
                this.litSelectedShippingCity.Text  = address.City;
                this.litSelectedShippingZip.Text   = address.PostalCode;
            }
        }
示例#28
0
 /// <summary>
 /// Maps a CustomerAddress to CustomerAddressModel
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public static CustomerAddressModel MapCustomerAddress(CustomerAddress address)
 {
     return(new CustomerAddressModel
     {
         AddressLine1 = address.AddressLine1,
         AddressLine2 = address.AddressLine2,
         City = address.City,
         State = address.State,
         Country = address.Country,
         PostalCode = address.PostalCode,
         CreatedOn = address.CreatedOn,
         UpdatedOn = address.UpdatedOn
     });
 }
示例#29
0
        public async Task <IActionResult> GetbyIdAsync([FromRoute] int customerNumber, [FromRoute] string id)
        {
            //TODO return not found error
            // var customerItem = await _customerContext.RetailCustomer.SingleOrDefaultAsync(i => i.Id == customerToUpdate.Id);

            // if (customerItem == null)
            // {
            //     return NotFound(new { Message = $"Item with id {customerToUpdate.Id} not found." });
            // }

            CustomerAddress customer = await _customerContext.CustomerAddress.Where(x => x.CustomerNumber == customerNumber && x.Id == id).SingleOrDefaultAsync();

            return(Ok(customer));
        }
        public void ClearCache()
        {
            var options = GetRepositoryOptionsBuilder(ContextProviderType.InMemory)
                          .UseCachingProvider(new InMemoryCacheProvider())
                          .Options;

            var customerRepo = new Repository <Customer>(options);
            var customer     = new Customer {
                Name = "Random Name"
            };

            customerRepo.Add(customer);

            var customerAddressRepo = new Repository <CustomerAddress>(options);
            var customerAddress     = new CustomerAddress()
            {
                CustomerId = customer.Id
            };

            customerAddressRepo.Add(customerAddress);

            Assert.True(customerRepo.CacheEnabled);
            Assert.False(customerRepo.CacheUsed);

            Assert.NotNull(customerRepo.Find(x => x.Id == customer.Id));
            Assert.False(customerRepo.CacheUsed);

            Assert.NotNull(customerAddressRepo.Find(x => x.Id == customerAddress.Id));
            Assert.False(customerAddressRepo.CacheUsed);

            Assert.NotNull(customerRepo.Find(x => x.Id == customer.Id));
            Assert.True(customerRepo.CacheUsed);

            Assert.NotNull(customerAddressRepo.Find(x => x.Id == customerAddress.Id));
            Assert.True(customerAddressRepo.CacheUsed);

            customerRepo.ClearCache();

            Assert.NotNull(customerRepo.Find(x => x.Id == customer.Id));
            Assert.False(customerRepo.CacheUsed);

            Assert.NotNull(customerAddressRepo.Find(x => x.Id == customerAddress.Id));
            Assert.True(customerAddressRepo.CacheUsed);

            customerAddressRepo.ClearCache();

            Assert.NotNull(customerAddressRepo.Find(x => x.Id == customerAddress.Id));
            Assert.False(customerAddressRepo.CacheUsed);
        }
示例#31
0
        public void Validate_CountryNotSet_CheckFailed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            address.Country = null;

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsTrue(validator.CheckFailed),
                () => Assert.IsTrue(validator.CountryNotSet)
                );
        }
        public async Task CustomerAddressTest_PostAsync_200()
        {
            Case sampleCase = this.GenerateSampleCase();

            Case returnCase = await ApiClient.PostCaseAsync(sampleCase);

            CustomerAddress address = new CustomerAddress();

            address.City = "Cork";

            CustomerAddress returnAddress = await ApiClient.PostCustomerAddressAsync(returnCase.Id, address);

            Assert.IsTrue(returnAddress.Id != Guid.Empty);
            Assert.AreEqual("Cork", returnAddress.City);
        }
        public async Task CustomerAddressTest_GetAllAsync_200()
        {
            Case sampleCase = this.GenerateSampleCaseWithAddress();

            CustomerAddress address = new CustomerAddress();

            address.City = "Dublin";
            sampleCase.Customer.Addresses.Add(address);

            Case returnCase = await ApiClient.PostCaseAsync(sampleCase);

            IList <CustomerAddress> returnCustomerAddresses = await ApiClient.GetCustomerAddressesAsync(returnCase.Id);

            Assert.IsTrue(returnCustomerAddresses.Count > 1);
        }
示例#34
0
        public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Customer forThisCustomer)
        {
            AddressRepository rep = new AddressRepository(db);
            int addressid         = rep.SaveAddress(address);

            if (address.IsNew)
            {
                CustomerAddress ca = new CustomerAddress();
                ca.AddressId  = addressid;
                ca.CustomerId = forThisCustomer.CustomerId;
                db.CustomerAddresses.InsertOnSubmit(ca);
                db.SubmitChanges();
            }
            return(addressid);
        }
示例#35
0
        public void Validate_StateNotFromCountry_CheckFailed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            address.State = mStateFromUnknownCountry;

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsTrue(validator.CheckFailed),
                () => Assert.IsTrue(validator.StateNotFromCountry)
                );
        }
示例#36
0
        public int CreateAddress(CustomerAddress address)
        {
            using (var connection = _connectionFactory.CreateConnection())
            {
                address.CustomerAddressId = Spry.InsertInto <CustomerAddress>(CUSTOMER_ADDRESS_TABLE)
                                            .Value(_ => address.CustomerId)
                                            .Value(_ => address.LineOne)
                                            .Value(_ => address.City)
                                            .Value(_ => address.Country)
                                            .Value(_ => address.PostCode)
                                            .ExecuteScalar <int>(connection);

                return(address.CustomerAddressId);
            }
        }
示例#37
0
        public AddressViewModel ConvertCustomerAddressToAddressViewModel(CustomerAddress address)
        {
            if (address == null) return null;

            var model = new AddressViewModel
            {
                AddressId = address.AddressId,
                City = address.City,
                Address = address.Name,
                FirstName = address.FirstName,
                LastName = address.LastName,
                ZIPCode = address.RegionCode,
                Type = address.AddressType.ToString()
            };
            return model;
        }
示例#38
0
 public void MapCustomerAddressToModel(Address address, CustomerAddress customerAddress)
 {
     address.Line1 = customerAddress.Line1;
     address.Line2 = customerAddress.Line2;
     address.City = customerAddress.City;
     address.CountryName = customerAddress.CountryName;
     address.CountryCode = customerAddress.CountryCode;
     address.Email = customerAddress.Email;
     address.FirstName = customerAddress.FirstName;
     address.LastName = customerAddress.LastName;
     address.PostalCode = customerAddress.PostalCode;
     address.SaveAddress = HttpContext.Current.User.Identity.IsAuthenticated;
     address.Region = customerAddress.RegionName ?? customerAddress.State;
     address.ShippingDefault = customerAddress.Equals(_customercontext.CurrentContact.PreferredShippingAddress);
     address.BillingDefault = customerAddress.Equals(_customercontext.CurrentContact.PreferredBillingAddress);
     address.AddressId = customerAddress.AddressId;
     address.Modified = customerAddress.Modified;
     address.Name = customerAddress.Name;
     address.DaytimePhoneNumber = customerAddress.DaytimePhoneNumber;
 }
 public void MapToModel(CustomerAddress customerAddress, AddressModel addressModel)
 {
     addressModel.Line1 = customerAddress.Line1;
     addressModel.Line2 = customerAddress.Line2;
     addressModel.City = customerAddress.City;
     addressModel.CountryName = customerAddress.CountryName;
     addressModel.CountryCode = customerAddress.CountryCode;
     addressModel.Email = customerAddress.Email;
     addressModel.FirstName = customerAddress.FirstName;
     addressModel.LastName = customerAddress.LastName;
     addressModel.PostalCode = customerAddress.PostalCode;
     addressModel.CountryRegion = new CountryRegionViewModel
     {
         Region = customerAddress.RegionName ?? customerAddress.RegionCode ?? customerAddress.State
     };
     addressModel.ShippingDefault = _customerContext.CurrentContact.PreferredShippingAddress != null 
                                         && customerAddress.Name == _customerContext.CurrentContact.PreferredShippingAddress.Name;
     addressModel.BillingDefault = _customerContext.CurrentContact.PreferredBillingAddress != null 
                                         && customerAddress.Name == _customerContext.CurrentContact.PreferredBillingAddress.Name;
     addressModel.AddressId = customerAddress.Name;
     addressModel.Name = customerAddress.Name;
     addressModel.DaytimePhoneNumber = customerAddress.DaytimePhoneNumber;
 }
        public void UpdateCustomerInfo(Customer customer, CustomerAddress billingAddress, CustomerAddress shippingAddress)
        {
            try
            {
                var profileId = UserManager.FindById(User.Identity.GetUserId()).UserProfile.Id;

                var custo = _customerService.FindCustomerBy(profileId);

                custo.CustomerAlias = customer.CustomerAlias;
                custo.BillingAddress = customer.BillingAddress;
                custo.ShippingAddress = customer.ShippingAddress;
                custo.ContactEmail = customer.ContactEmail;
                custo.ContactTel = customer.ContactTel;

                //_customerService.UpdateCustomerInfo(custo);

                //new code: customer address
                var billingAddr = _customerService.FindCustomerAddress(custo.Id, 1); //get billing address
                var shippingAddr = _customerService.FindCustomerAddress(custo.Id, 2); //get shipping address

                if (billingAddr != null)
                {
                    billingAddr.AddressStreet = billingAddress.AddressStreet;
                    billingAddr.AddressCity = billingAddress.AddressCity;
                    billingAddr.AddressProState = billingAddress.AddressProState;
                    billingAddr.AddressPostZipCode = billingAddress.AddressPostZipCode;
                    billingAddr.AddressType = billingAddress.AddressType;
                    billingAddr.CustomerId = customer.Id;
                    billingAddress.AddressCountry = "Canada";
                }

                if (shippingAddr != null)
                {
                    shippingAddr.AddressStreet = shippingAddress.AddressStreet;
                    shippingAddr.AddressCity = shippingAddress.AddressCity;
                    shippingAddr.AddressProState = shippingAddress.AddressProState;
                    shippingAddr.AddressPostZipCode = shippingAddress.AddressPostZipCode;
                    shippingAddr.AddressType = shippingAddress.AddressType;
                    shippingAddr.CustomerId = customer.Id;
                    shippingAddr.AddressCountry = "Canada";
                }

                _customerService.UpdateCustomerInfo(custo, billingAddress, shippingAddress);
            }
            catch (Exception)
            {

                throw;
            }
        }
示例#41
0
 private void UpdateAddress(AddressViewModel address, CustomerAddress customerAddress)
 {
     if (CustomerContext.Current.CurrentContactId != Guid.Empty)
     {
         var contact = CustomerContext.Current.GetContactById(CustomerContext.Current.CurrentContactId);
         if (contact != null)
         {
             customerAddress = ConvertAddressViewModelToCustomerAddress(address);
             contact.UpdateContactAddress(customerAddress);
             contact.SaveChanges();
         }
     }
 }
 public override void AddContactAddress(CustomerAddress address)
 {
     address.AddressId = new PrimaryKeyId(Guid.Parse(address.Name));
     _addresses.Add(address);
 }
示例#43
0
        public void UpdateCustomerInfo(Customer customer, CustomerAddress billingAddress,
            CustomerAddress shippingAddress)
        {
            try
            {
                _customerRepository.Update(customer);

                var bAddress = _customerAddressRepository.GetAll().FirstOrDefault(c => c.CustomerId == customer.Id && c.AddressType == 1);

                if (bAddress != null)
                {
                    //_custRepository.UpdateCusotmerAddress(customer.Id, billingAddress);

                    bAddress.AddressCity = billingAddress.AddressCity;
                    bAddress.AddressStreet = billingAddress.AddressStreet;
                    bAddress.AddressProState = billingAddress.AddressProState;
                    bAddress.AddressPostZipCode = billingAddress.AddressPostZipCode;
                    bAddress.AddressCountry = billingAddress.AddressCountry;

                    _customerAddressRepository.Update(bAddress);
                }
                else
                {
                    //_custRepository.AddCusotmerAddress(customer.Id, billingAddress);
                    if (billingAddress.AddressStreet != null && billingAddress.AddressCity != null && billingAddress.AddressProState != null
                        && billingAddress.AddressPostZipCode != null)
                    {
                        _customerAddressRepository.Add(billingAddress);
                    }

                }

                var sAddress = _customerAddressRepository.GetAll().FirstOrDefault(c => c.CustomerId == customer.Id && c.AddressType == 2);

                if (sAddress != null)
                {
                    //_custRepository.UpdateCusotmerAddress(customer.Id, billingAddress);
                    sAddress.AddressCity = shippingAddress.AddressCity;
                    sAddress.AddressStreet = shippingAddress.AddressStreet;
                    sAddress.AddressProState = shippingAddress.AddressProState;
                    sAddress.AddressPostZipCode = shippingAddress.AddressPostZipCode;
                    sAddress.AddressCountry = shippingAddress.AddressCountry;

                    _customerAddressRepository.Update(sAddress);
                }
                else
                {
                    //_custRepository.AddCusotmerAddress(customer.Id, shippingAddress);
                    if (shippingAddress.AddressStreet != null && shippingAddress.AddressCity != null && shippingAddress.AddressProState != null
                        && shippingAddress.AddressPostZipCode != null)
                    {
                        _customerAddressRepository.Add(shippingAddress);
                    }

                }

                _uow.Save();
            }
            catch (Exception ex)
            {

                throw new Exception("Failed updating the customer", ex);
            }
        }
示例#44
0
        private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage)
        {
            Address address = null;

            if (customerAddress != null)
            {
                address = new Address();
                MapCustomerAddressToModel(address, customerAddress);
            }

            return address;
        }
示例#45
0
 public MyProfileVM(PurchaseOrder[] orders, CustomerAddress billingAddr, CustomerAddress shippingAddr)
 {
     this.Orders = orders;
     this.BillingAddress = billingAddr;
     this.ShippingAddress = shippingAddr;
 }
        private AddressModel ConvertAddress(CustomerAddress customerAddress)
        {
            AddressModel addressModel = null;

            if (customerAddress != null)
            {
                addressModel = new AddressModel();
                MapToModel(customerAddress, addressModel);
            }

            return addressModel;
        }
        public AddressBookServiceTests()
        {
            _address1 = CustomerAddress.CreateInstance();
            _address1.AddressId = new PrimaryKeyId(new Guid(_address1Id));
            _address1.Name = _address1.AddressId.ToString();

            var address2 = CustomerAddress.CreateInstance();
            address2.AddressId = new PrimaryKeyId(new Guid(_address2Id));
            address2.Name = address2.AddressId.ToString();

            _currentContact = new FakeCurrentContact(new[] { _address1, address2 })
            {
                PreferredBillingAddress = _address1,
                PreferredShippingAddress = _address1
            };
            var customerContext = new FakeCustomerContext(_currentContact);
            var countryManager = new FakeCountryManager();

            _subject = new AddressBookService(customerContext, countryManager, new Mock<IOrderFactory>().Object);
        }
	private void attach_CustomerAddresses(CustomerAddress entity)
	{
		this.SendPropertyChanging();
		entity.Customer = this;
	}
 partial void InsertCustomerAddress(CustomerAddress instance);
 partial void UpdateCustomerAddress(CustomerAddress instance);
 public virtual void UpdateContactAddress(CustomerAddress address)
 {
     CustomerContext.Current.CurrentContact.UpdateContactAddress(address);
 }
 partial void DeleteCustomerAddress(CustomerAddress instance);
        public void Setup()
        {
            _address1 = CustomerAddress.CreateInstance();
            _address1.AddressId = new PrimaryKeyId(Guid.NewGuid());
            _address1.Name = _address1.AddressId.ToString();

            _address2 = CustomerAddress.CreateInstance();
            _address2.AddressId = new PrimaryKeyId(Guid.NewGuid());
            _address2.Name = _address2.AddressId.ToString();
            
            _currentContact = new FakeCurrentContact(new[] { _address1, _address2 });
            var customerContext = new FakeCustomerContext(_currentContact);
            var countryManager = new FakeCountryManager();

            _subject = new AddressBookService(customerContext, countryManager);
        }
 public void MapToAddress(AddressModel addressModel, CustomerAddress customerAddress)
 {
     customerAddress.Name = addressModel.Name;
     customerAddress.City = addressModel.City;
     customerAddress.CountryCode = addressModel.CountryCode;
     customerAddress.CountryName = _countryManager.GetCountries().Country.Where(x => x.Code == addressModel.CountryCode).Select(x => x.Name).FirstOrDefault();
     customerAddress.FirstName = addressModel.FirstName;
     customerAddress.LastName = addressModel.LastName;
     customerAddress.Line1 = addressModel.Line1;
     customerAddress.Line2 = addressModel.Line2;
     customerAddress.DaytimePhoneNumber = addressModel.DaytimePhoneNumber;
     customerAddress.PostalCode = addressModel.PostalCode;
     customerAddress.RegionName = addressModel.CountryRegion.Region;
     customerAddress.RegionCode = addressModel.CountryRegion.Region;
     // Commerce Manager expects State to be set for addresses in order management. Set it to be same as
     // RegionName to avoid issues.
     customerAddress.State = addressModel.CountryRegion.Region;
     customerAddress.Email = addressModel.Email;
     customerAddress.AddressType =
         CustomerAddressTypeEnum.Public |
         (addressModel.ShippingDefault ? CustomerAddressTypeEnum.Shipping : 0) |
         (addressModel.BillingDefault ? CustomerAddressTypeEnum.Billing : 0);
 }
        public CheckoutViewModelFactoryTests()
        {
            _cart = new FakeCart(new MarketImpl(new MarketId(Currency.USD)), Currency.USD);
            _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem());
            _cart.Forms.Single().CouponCodes.Add("couponcode");

            _cashPayment = new PaymentMethodViewModel<PaymentMethodBase> { SystemName = cashPaymentName };
            _creditPayment = new PaymentMethodViewModel<PaymentMethodBase> { SystemName = creditPaymentName };
            var paymentServiceMock = new Mock<IPaymentService>();
            var marketMock = new Mock<IMarket>();
            var currentMarketMock = new Mock<ICurrentMarket>();
            var languageServiceMock = new Mock<LanguageService>(null, null, null, null);
            var paymentMethodViewModelFactory = new PaymentMethodViewModelFactory(currentMarketMock.Object, languageServiceMock.Object, paymentServiceMock.Object);

            currentMarketMock.Setup(x => x.GetCurrentMarket()).Returns(marketMock.Object);
            languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(new CultureInfo("en-US"));
            paymentServiceMock.Setup(x => x.GetPaymentMethodsByMarketIdAndLanguageCode(It.IsAny<string>(), "en")).Returns(
               new[]
               {
                    new PaymentMethodModel { Description = "Lorem ipsum", FriendlyName = "payment method 1", LanguageId = "en", PaymentMethodId = Guid.NewGuid(), SystemName = cashPaymentName },
                    new PaymentMethodModel { Description = "Lorem ipsum", FriendlyName = "payment method 2", LanguageId = "en", PaymentMethodId = Guid.NewGuid(), SystemName = creditPaymentName }
               });

            var addressBookServiceMock = new Mock<IAddressBookService>();
            addressBookServiceMock.Setup(x => x.List()).Returns(() => new List<AddressModel> { new AddressModel { AddressId = "addressid" } });
            _preferredBillingAddress = CustomerAddress.CreateInstance();
            _preferredBillingAddress.Name = "preferredBillingAddress";
            addressBookServiceMock.Setup(x => x.GetPreferredBillingAddress()).Returns(_preferredBillingAddress);
            addressBookServiceMock.Setup(x => x.UseBillingAddressForShipment()).Returns(true);

            _startPage = new StartPage();
            var contentLoaderMock = new Mock<IContentLoader>();
            contentLoaderMock.Setup(x => x.Get<StartPage>(It.IsAny<PageReference>())).Returns(_startPage);

            var orderFactoryMock = new Mock<IOrderFactory>();
            var urlResolverMock = new Mock<UrlResolver>();
            var httpcontextMock = new Mock<HttpContextBase>();
            var requestMock = new Mock<HttpRequestBase>();

            requestMock.Setup(x => x.Url).Returns(new Uri("http://site.com"));
            requestMock.Setup(x => x.UrlReferrer).Returns(new Uri("http://site.com"));
            httpcontextMock.Setup(x => x.Request).Returns(requestMock.Object);

            Func<CultureInfo> func = () => CultureInfo.InvariantCulture;
            var shipmentViewModelFactoryMock = new Mock<ShipmentViewModelFactory>(null, null, null, null, null, null, func, null);
            shipmentViewModelFactoryMock.Setup(x => x.CreateShipmentsViewModel(It.IsAny<ICart>())).Returns(() => new[]
            {
                new ShipmentViewModel {
                    CartItems = new[]
                    {
                        new CartItemViewModel { Quantity = 1 }
                    }
                }
            });

            _subject = new CheckoutViewModelFactory(
                new MemoryLocalizationService(),
                paymentMethodViewModelFactory,
                addressBookServiceMock.Object,
                contentLoaderMock.Object,
                orderFactoryMock.Object,
                urlResolverMock.Object,
                (() => httpcontextMock.Object),
                shipmentViewModelFactoryMock.Object);
        }
 public static CustomerAddress CreateCustomerAddress(int customerID, int addressID, string addressType, global::System.Guid rowguid, global::System.DateTime modifiedDate)
 {
     CustomerAddress customerAddress = new CustomerAddress();
     customerAddress.CustomerID = customerID;
     customerAddress.AddressID = addressID;
     customerAddress.AddressType = addressType;
     customerAddress.rowguid = rowguid;
     customerAddress.ModifiedDate = modifiedDate;
     return customerAddress;
 }
 public void AddToCustomerAddresses(CustomerAddress customerAddress)
 {
     base.AddObject("CustomerAddresses", customerAddress);
 }
	private void detach_CustomerAddresses(CustomerAddress entity)
	{
		this.SendPropertyChanging();
		entity.Address = null;
	}
示例#59
0
 public int SaveAddress(HsrOrderApp.BL.DomainModel.Address address, HsrOrderApp.BL.DomainModel.Customer forThisCustomer)
 {
     AddressRepository rep = new AddressRepository(db);
     int addressid = rep.SaveAddress(address);
     if (address.IsNew)
     {
         CustomerAddress ca = new CustomerAddress();
         ca.AddressId = addressid;
         ca.CustomerId = forThisCustomer.CustomerId;
         db.CustomerAddresses.InsertOnSubmit(ca);
         db.SubmitChanges();
     }
     return addressid;
 }