protected void btnAddChangeContact_Click(object sender, EventArgs e) { if (!ValidateFormData()) { return; } var contact = new CustomerContact { Name = txtContactName.Text, Country = cboCountry.SelectedItem.Text, CountryId = Int32.Parse(cboCountry.SelectedValue), City = HttpUtility.HtmlEncode(txtContactCity.Text), RegionName = HttpUtility.HtmlEncode(txtContactZone.Text), Address = HttpUtility.HtmlEncode(txtContactAddress.Text), Zip = HttpUtility.HtmlEncode(txtContactZip.Text), }; switch (ViewState["AddOrEdit"].ToString()) { case "Add": contact.CustomerGuid = Customer.Id; CustomerService.AddContact(contact, Customer.Id); break; case "Edit": contact.CustomerContactID = new Guid(CustomerContacts.SelectedValue); CustomerService.UpdateContact(contact); break; } DisplayAddressBook(); mvAdressBook.SetActiveView(vAdressBook); }
public async Task AddContact_OK() { //Arrange var mockLogger = new Mock <ILogger <CustomerService> >(); var mockCustomerApi = new Mock <customerApi.ICustomerApiClient>(); var mockReferenceDataApi = new Mock <referenceDataApi.IReferenceDataApiClient>(); var mockSalesPersonApi = new Mock <salesPersonApi.ISalesPersonApiClient>(); mockReferenceDataApi.Setup(x => x.GetContactTypesAsync()) .ReturnsAsync(new List <referenceDataApi.Models.GetContactTypes.ContactType> { new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Owner" }, new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Marketing Assistant" }, new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Order Administrator" } }); mockCustomerApi .Setup(x => x.GetCustomerAsync <customerApi.Models.GetCustomer.StoreCustomer>(It.IsAny <string>())) .ReturnsAsync(new StoreCustomerBuilder() .WithTestValues() .Build() ); var svc = new CustomerService( mockLogger.Object, Mapper.CreateMapper(), mockCustomerApi.Object, mockReferenceDataApi.Object, mockSalesPersonApi.Object ); //Act var viewModel = new EditCustomerContactViewModel { CustomerContact = new CustomerContactViewModel { ContactType = "Owner", ContactPerson = new PersonViewModel { FirstName = "Orlando", MiddleName = "N.", LastName = "Gee" } } }; await svc.AddContact(viewModel); //Assert mockCustomerApi.Verify(x => x.UpdateCustomerAsync( It.IsAny <string>(), It.IsAny <customerApi.Models.UpdateCustomer.Customer>() )); }
public string AddContact(CustomerContact contact, string customerId) { if (!AuthorizeService.CheckAdminCookies()) { return(MsgAuthFailed); } Guid errCode = CustomerService.AddContact(contact, new Guid(customerId)); return(errCode != Guid.Empty ? string.Format(MsgAddContactSuccess, contact.CustomerContactID) : string.Format(MsgAddContactFailed, contact.CustomerContactID, errCode)); }
private void UpdateCustomerContact() { CustomerService.UpdateCustomer(PageData.OrderConfirmationData.Customer); var newContact = PageData.OrderConfirmationData.ShippingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); if (!PageData.OrderConfirmationData.BillingIsShipping) { newContact = PageData.OrderConfirmationData.BillingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); } }
protected void btnRegUserWithounAddressGoNext_Click(object sender, EventArgs e) { CustomerService.AddContact(GetShippingContactForReg(), CustomerSession.CurrentCustomer.Id); if (!ckbBillingIsShippingReg.Checked) { CustomerService.AddContact(GetBillingContactForReg(), CustomerSession.CurrentCustomer.Id); } OnNextStep(new FirstStepNextEventArgs { BillingIsShipping = ckbBillingIsShippingReg.Checked, ShippingContact = GetShippingContactForReg(), BillingContact = !ckbBillingIsShippingReg.Checked ? GetBillingContactForReg() : null, Customer = CustomerSession.CurrentCustomer }); }
public async Task AddContact_ReturnsViewModel() { //Arrange var mockLogger = new Mock <ILogger <CustomerService> >(); var mockCustomerApi = new Mock <customerApi.ICustomerApiClient>(); var mockReferenceDataApi = new Mock <referenceDataApi.IReferenceDataApiClient>(); var mockSalesPersonApi = new Mock <salesPersonApi.ISalesPersonApiClient>(); mockReferenceDataApi.Setup(x => x.GetContactTypesAsync()) .ReturnsAsync(new List <referenceDataApi.Models.GetContactTypes.ContactType> { new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Owner" }, new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Marketing Assistant" }, new referenceDataApi.Models.GetContactTypes.ContactType { Name = "Order Administrator" } }); var svc = new CustomerService( mockLogger.Object, Mapper.CreateMapper(), mockCustomerApi.Object, mockReferenceDataApi.Object, mockSalesPersonApi.Object ); //Act var viewModel = await svc.AddContact("AW00000001", "A Bike Store"); //Assert viewModel.IsNewContact.Should().Be(true); viewModel.ContactTypes.Count().Should().Be(4); viewModel.ContactTypes.ToList()[0].Text.Should().Be("--Select--"); }
private void RegistrationNow() { try { if (CustomerService.CheckCustomerExist(PageData.OrderConfirmationData.Customer.EMail)) { ShowMessage(Notify.NotifyType.Error, Resource.Client_Registration_CustomerExist); return; } var id = CustomerService.InsertNewCustomer(new Customer { CustomerGroupId = CustomerGroupService.DefaultCustomerGroup, Password = PageData.OrderConfirmationData.Customer.Password, FirstName = PageData.OrderConfirmationData.Customer.FirstName, LastName = PageData.OrderConfirmationData.Customer.LastName, Phone = PageData.OrderConfirmationData.Customer.Phone, SubscribedForNews = false, EMail = PageData.OrderConfirmationData.Customer.EMail, CustomerRole = Role.User, BonusCardNumber = PageData.OrderConfirmationData.Customer.BonusCardNumber }); if (id == Guid.Empty) { return; } PageData.OrderConfirmationData.Customer.Id = id; AuthorizeService.SignIn(PageData.OrderConfirmationData.Customer.EMail, PageData.OrderConfirmationData.Customer.Password, false, true); var newContact = PageData.OrderConfirmationData.ShippingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); if (!PageData.OrderConfirmationData.BillingIsShipping) { newContact = PageData.OrderConfirmationData.BillingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); } var registrationMail = new RegistrationMailTemplate(SettingsMain.SiteUrl, PageData.OrderConfirmationData.Customer.FirstName, PageData.OrderConfirmationData.Customer.LastName, AdvantShop.Localization.Culture.ConvertDate(DateTime.Now), PageData.OrderConfirmationData.Customer.Password, Resource.Client_Registration_No, PageData.OrderConfirmationData.Customer.EMail); registrationMail.BuildMail(); if (CustomerContext.CurrentCustomer.IsVirtual) { ShowMessage(Notify.NotifyType.Notice, Resource.Client_Registration_Whom + PageData.OrderConfirmationData.Customer.EMail + '\r' + Resource.Client_Registration_Text + registrationMail.Body); } else { SendMail.SendMailNow(PageData.OrderConfirmationData.Customer.EMail, registrationMail.Subject, registrationMail.Body, true); SendMail.SendMailNow(SettingsMail.EmailForRegReport, registrationMail.Subject, registrationMail.Body, true); } } catch (Exception ex) { Debug.LogError(ex); } }
private void SaveContactForHQAccount(ref Contact currentContact, ref Customer currentCustomer) { try { //is new / wants to be shared if (currentContact.IsNew && currentContact.Shared) { //add to all branches currentContact.Key = service.AddContact(currentContact); foreach (var branch in currentCustomer.Branches) { var contact = new Contact { Name = currentContact.Name, Phone = currentContact.Phone, PhoneExt = currentContact.PhoneExt, Fax = currentContact.Fax, FaxExt = currentContact.FaxExt, MobilePhone = currentContact.MobilePhone, Email = currentContact.Email, CntctOwnerKey = branch.Key, ParentKey = currentContact.Key, Shared = true, EMailFormat = 3, EntityType = 501, CreateDate = currentContact.IsNew ? DateTime.Now : currentContact.CreateDate, CreateUserID = currentContact.IsNew ? Environment.UserName : currentContact.CreateUserID, Title = currentContact.Title, Module = module.ToString(), Deleted = currentContact.Deleted, IsDirty = false }; service.AddContact(contact); } } //is new / not shared else if (currentContact.IsNew && !currentContact.Shared) { /*add new to single branch*/ currentContact.Key = service.AddContact(currentContact); } // not new / shared else if (!currentContact.IsNew && currentContact.Shared) { foreach (var branch in currentCustomer.Branches) { //find possible match var currentContactKey = currentContact.Key; var possibleMatch = branch.Contacts.FirstOrDefault(c => c.ParentKey == currentContactKey); if (possibleMatch != null) { //if found update those possibleMatch.Name = currentContact.Name; possibleMatch.Email = currentContact.Email; possibleMatch.Title = currentContact.Title; possibleMatch.Phone = currentContact.Phone; possibleMatch.Phone = currentContact.Phone; possibleMatch.PhoneExt = currentContact.PhoneExt; possibleMatch.Fax = currentContact.Fax; possibleMatch.FaxExt = currentContact.FaxExt; possibleMatch.MobilePhone = currentContact.MobilePhone; possibleMatch.UpdateDate = currentContact.IsNew ? currentContact.UpdateDate : DateTime.Now; possibleMatch.UpdateUserID = currentContact.IsNew ? currentContact.UpdateUserID : Environment.UserName; possibleMatch.Shared = currentContact.Shared; possibleMatch.Deleted = currentContact.Shared ? (short)0 : (short)1; possibleMatch.CreditMemo = currentContact.CreditMemo; possibleMatch.Invoice = currentContact.Invoice; possibleMatch.Statement = currentContact.Statement; } else { //if not found - create new var contact = new Contact { Name = currentContact.Name, Phone = currentContact.Phone, PhoneExt = currentContact.PhoneExt, Fax = currentContact.Fax, FaxExt = currentContact.FaxExt, MobilePhone = currentContact.MobilePhone, Email = currentContact.Email, CntctOwnerKey = branch.Key, ParentKey = currentContact.Key, Shared = currentContact.Shared, EMailFormat = 3, EntityType = 501, CreateDate = currentContact.IsNew ? DateTime.Now : currentContact.CreateDate, CreateUserID = currentContact.IsNew ? Environment.UserName : currentContact.CreateUserID, Title = currentContact.Title, Module = module.ToString(), Deleted = currentContact.Shared ? (short)0 : (short)1, IsDirty = false, CreditMemo = currentContact.CreditMemo, Invoice = currentContact.Invoice, Statement = currentContact.Statement, DebitMemo = currentContact.DebitMemo }; service.AddContact(contact); } } service.UpdateCustomer(currentCustomer); DeleteRestoreForHQAccount(ref currentContact, ref currentCustomer); } //not new / being unshared else if (!currentContact.IsNew && !currentContact.Shared) { foreach (var branch in currentCustomer.Branches) { var currentContactKey = currentContact.Key; var possibleMatch = branch.Contacts.FirstOrDefault(c => c.ParentKey == currentContactKey); if (possibleMatch != null) { possibleMatch.Shared = false; possibleMatch.Deleted = 1; possibleMatch.CreditMemo = false; possibleMatch.Invoice = false; possibleMatch.Statement = false; possibleMatch.DebitMemo = false; } } service.UpdateCustomer(currentCustomer); DeleteRestoreForHQAccount(ref currentContact, ref currentCustomer); } } catch (Exception ex) { EmailSender.EmailUnexpectedException(ex, currentContact.Customer, "Module: SaveContactForHQAccount"); MessageBox.Show("Error saving, please try restarting."); } }
private void RegistrationNow() { try { if (CustomerService.CheckCustomerExist(PageData.OrderConfirmationData.Customer.EMail)) { ShowMessage(Notify.NotifyType.Error, Resource.Client_Registration_CustomerExist); } Guid id = CustomerService.InsertNewCustomer(new Customer { CustomerGroupId = CustomerGroupService.DefaultCustomerGroup, Password = PageData.OrderConfirmationData.Customer.Password, FirstName = PageData.OrderConfirmationData.Customer.FirstName, LastName = PageData.OrderConfirmationData.Customer.LastName, Phone = PageData.OrderConfirmationData.Customer.Phone, SubscribedForNews = false, EMail = PageData.OrderConfirmationData.Customer.EMail, CustomerRole = Role.User }); if (id == Guid.Empty) { return; } PageData.OrderConfirmationData.Customer.Id = id; AuthorizeService.AuthorizeTheUser(PageData.OrderConfirmationData.Customer.EMail, PageData.OrderConfirmationData.Customer.Password, false); // Shipping contact ----------------------------- var newContact = PageData.OrderConfirmationData.ShippingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); // Billing contact --------------------------- if (!PageData.OrderConfirmationData.BillingIsShipping) { newContact = PageData.OrderConfirmationData.BillingContact; CustomerService.AddContact(newContact, PageData.OrderConfirmationData.Customer.Id); } //------------------------------------------ var clsParam = new ClsMailParamOnRegistration { FirstName = PageData.OrderConfirmationData.Customer.FirstName, LastName = PageData.OrderConfirmationData.Customer.LastName, RegDate = AdvantShop.Localization.Culture.ConvertDate(DateTime.Now), Password = PageData.OrderConfirmationData.Customer.Password, Subsrcibe = Resource.Client_Registration_No, ShopURL = SettingsMain.SiteUrl }; string message = SendMail.BuildMail(clsParam); if (CustomerSession.CurrentCustomer.IsVirtual) { ShowMessage(Notify.NotifyType.Notice, Resource.Client_Registration_Whom + PageData.OrderConfirmationData.Customer.EMail + '\r' + Resource.Client_Registration_Text + message); } else { SendMail.SendMailNow(PageData.OrderConfirmationData.Customer.EMail, SettingsMain.SiteUrl + " - " + string.Format(Resource.Client_Registration_RegSuccessful, PageData.OrderConfirmationData.Customer.EMail), message, true); SendMail.SendMailNow(SettingsMail.EmailForRegReport, SettingsMain.SiteUrl + " - " + string.Format(Resource.Client_Registration_RegSuccessful, PageData.OrderConfirmationData.Customer.EMail), message, true); } //------------------------------------------ } catch (Exception ex) { Debug.LogError(ex); ShowMessage(Notify.NotifyType.Error, ex.Message + " at registration"); } }