public Sitecore.Analytics.Tracking.Contact CreateContact(string identifier, string firstName, string lastName, string email, string language) { var contactRepository = new ContactRepository(); var contact = contactRepository.LoadContactReadOnly(identifier); if (contact == null) { contact = contactRepository.CreateContact(ID.NewID); contact.Identifiers.AuthenticationLevel = AuthenticationLevel.None; contact.System.Classification = 0; contact.ContactSaveMode = ContactSaveMode.AlwaysSave; contact.Identifiers.Identifier = identifier; contact.System.OverrideClassification = 0; contact.System.Value = 0; contact.System.VisitCount = 0; var contactPreferences = contact.GetFacet<IContactPreferences>("Preferences"); contactPreferences.Language = language; var contactEmailAddresses = contact.GetFacet<IContactEmailAddresses>("Emails"); contactEmailAddresses.Entries.Create("Preferred").SmtpAddress = email; contactEmailAddresses.Preferred = "Preferred"; var contactPersonalInfo = contact.GetFacet<IContactPersonalInfo>("Personal"); contactPersonalInfo.FirstName = firstName; contactPersonalInfo.Surname = lastName; contactRepository.SaveContact(contact, new ContactSaveOptions(true, null)); } Tracker.Current.Session.Identify(identifier); return contact; }
public override void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext = null, params object[] data) { _log = Sitecore.Diagnostics.LoggerFactory.GetLogger("LogFileAppender"); var name = adaptedFields.GetEntryByName("Full Name"); var contactno = adaptedFields.GetEntryByName("Contact Number"); var email = adaptedFields.GetEntryByName("Email Address"); var Age = adaptedFields.GetEntryByName("Age"); var Company = adaptedFields.GetEntryByName("Company"); var Designation = adaptedFields.GetEntryByName("Designation"); _log.Info("Writing comment to database"); HttpContext.Current.Session["Email"] = email; /// var goal = new PageEventData("My Custom Goal", Guid.Parse("{47FF654B-76B2-49EF-A6AA-C61AE6093768}")); // Tracker.Current.CurrentPage.Register(goal); LockAttemptResult <Contact> lockResult; ContactRepository contactRepository = Sitecore.Configuration.Factory.CreateObject("tracking/contactRepository", true) as ContactRepository; ContactManager contactManager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as ContactManager; var contact = Tracker.Current?.Contact; if (contact == null) { lockResult = new LockAttemptResult <Contact>(LockAttemptStatus.NotFound, null, null); contact = contactRepository.CreateContact(Sitecore.Data.ID.NewID); contact.Identifiers.AuthenticationLevel = Sitecore.Analytics.Model.AuthenticationLevel.None; contact.Identifiers.Identifier = "*****@*****.**"; contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known; contact.System.Value = 0; contact.System.VisitCount = 0; contact.ContactSaveMode = ContactSaveMode.AlwaysSave; contactManager.FlushContactToXdb(contact); // VisitorIdentification s = new VisitorIdentification(); } else { lockResult = contactManager.TryLoadContact(contact.ContactId); contact = lockResult.Object; } if (contact != null) { var contactEmailAddresses = contact.GetFacet <IContactCommentsFacet>("Contact Details"); if (!contactEmailAddresses.CustomerDetails.Contains("Contact Details")) { contactEmailAddresses.CustomerDetails.Create("Contact Details"); contactEmailAddresses.CustomerDetails["Contact Details"].Age = "18"; contactEmailAddresses.CustomerDetails["Contact Details"].Company = "Companyemarr"; contactEmailAddresses.CustomerDetails["Contact Details"].FullName = "Designationdsddf"; contactEmailAddresses.CustomerDetails["Contact Details"].Email = "Emailaddress"; } var leaseOwner = new LeaseOwner(GetType() + Guid.NewGuid().ToString(), LeaseOwnerType.OutOfRequestWorker); contactManager.SaveAndReleaseContactToXdb(contact); } }
public Sitecore.Analytics.Tracking.Contact CreateContact(string identifier, string firstName, string lastName, string email, string language) { var contactRepository = new ContactRepository(); var contact = contactRepository.LoadContactReadOnly(identifier); if (contact == null) { contact = contactRepository.CreateContact(ID.NewID); contact.Identifiers.AuthenticationLevel = AuthenticationLevel.None; contact.System.Classification = 0; contact.ContactSaveMode = ContactSaveMode.AlwaysSave; contact.Identifiers.Identifier = identifier; contact.System.OverrideClassification = 0; contact.System.Value = 0; contact.System.VisitCount = 0; var contactPreferences = contact.GetFacet <IContactPreferences>("Preferences"); contactPreferences.Language = language; var contactEmailAddresses = contact.GetFacet <IContactEmailAddresses>("Emails"); contactEmailAddresses.Entries.Create("Preferred").SmtpAddress = email; contactEmailAddresses.Preferred = "Preferred"; var contactPersonalInfo = contact.GetFacet <IContactPersonalInfo>("Personal"); contactPersonalInfo.FirstName = firstName; contactPersonalInfo.Surname = lastName; contactRepository.SaveContact(contact, new ContactSaveOptions(true, null)); } Tracker.Current.Session.Identify(identifier); return(contact); }
public void Unit_CreateContact_Valid() { Contacts contact = getMockContact(); dbContext.Setup(c => c.SaveChanges()).Returns(1); bool response = contactRepository.CreateContact(contact); Assert.AreEqual(true, response); }
public ActionResult Create(ContactVM model) { ContactRepository contactRepository = new ContactRepository(); Contact contact = new Contact(); contact.Name = model.Name; contact.Company = model.Company; contact.Position = model.Position; contact.PhoneNumber = model.PhoneNumber; contactRepository.CreateContact(contact); return(RedirectToAction("Index")); }
public Contact CreateContact() { var identifier = "XGen" + ContactCount; var contactRepository = new ContactRepository(); var contact = contactRepository.LoadContactReadOnly(identifier); while (contact != null) { ContactCount++; identifier = "XGen" + ContactCount; contact = contactRepository.LoadContactReadOnly(identifier); } contact = contactRepository.CreateContact(ID.NewID); contact.Identifiers.AuthenticationLevel = AuthenticationLevel.None; contact.System.Classification = 0; contact.ContactSaveMode = ContactSaveMode.AlwaysSave; contact.Identifiers.Identifier = "XGen" + ContactCount; contact.System.OverrideClassification = 0; contact.System.Value = 0; contact.System.VisitCount = 0; var contactPreferences = contact.GetFacet <IContactPreferences>("Preferences"); contactPreferences.Language = _languages[ContactCount % _languages.Length]; var contactPersonalInfo = contact.GetFacet <IContactPersonalInfo>("Personal"); contactPersonalInfo.FirstName = Faker.Name.First(); contactPersonalInfo.Surname = Faker.Name.Last(); var contactEmailAddresses = contact.GetFacet <IContactEmailAddresses>("Emails"); contactEmailAddresses.Entries.Create("Work").SmtpAddress = Faker.Internet.Email($"{contactPersonalInfo.FirstName} {contactPersonalInfo.Surname}"); contactEmailAddresses.Preferred = "Work"; var leaseOwner = new LeaseOwner("CONTACT_CREATE", LeaseOwnerType.OutOfRequestWorker); var options = new ContactSaveOptions(true, leaseOwner, null); contactRepository.SaveContact(contact, options); DoContactCreated(contact); return(contact); }
public ActionResult Create([Bind(Include = "Id,Name,MobileNumber,OwnerAccountId,ContactAccountId")] Contact contact) { if (ModelState.IsValid) { Account account = (Account)Session["loggedInUser"]; contactRepo.CreateContact(contact, account); if (accountRepo.ContactHasAccount(contact.MobileNumber)) { return(RedirectToAction("NewChat", "Chat", new { id = contact.MobileNumber })); } } else { ModelState.AddModelError("Create contact-error", "Some of the fields are wrong"); } return(RedirectToAction("Index")); }
private void Run() { while (true) { Console.WriteLine("Please, press:"); Console.WriteLine("C - Create"); Console.WriteLine("R - Retrieve"); Console.WriteLine("U - Update"); Console.WriteLine("D - Delete"); Console.WriteLine("Q - Query all contacts (limit to 128 items)"); var input = Console.ReadKey(); Console.WriteLine("\n------------"); switch (input.Key) { case ConsoleKey.C: ContactRepository.CreateContact(); break; case ConsoleKey.R: ContactRepository.RetrieveContact(); break; case ConsoleKey.U: ContactRepository.UpdateContact(); break; case ConsoleKey.D: ContactRepository.DeleteContact(); break; case ConsoleKey.Q: ContactRepository.QueryAllContacts(); break; default: return; } Console.WriteLine("------------"); } }
private void AddContact() { // ContactController newContact = userInterface.GetNewContactInformation(); Contact newContact = userInterface.GetNewContactInformation(); // ContactController addedContact = repository.CreateContact(newContact); Contact addedContact = repository.CreateContact(newContact); if (addedContact != null)//Successfully added to repository { //Show the new contact, including the ID that came from the respository userInterface.DisplayContact(addedContact); userInterface.ShowActionSuccess("Add Contact"); } else//Failed to add to repository { userInterface.ShowActionFailure("Add Contact"); } }
public ActionResult Index(SubscribeModel subscribe) { if (ModelState.IsValid) { using (new SecurityDisabler()) { try { string emailAddress = subscribe.Email; EmailHelper emailhelper = new EmailHelper(); ContactRepository contactRepository = Sitecore.Configuration.Factory.CreateObject("tracking/contactRepository", true) as ContactRepository; var contact = contactRepository.LoadContactReadOnly(emailAddress); ContactManager contactManager = Sitecore.Configuration.Factory.CreateObject("tracking/contactManager", true) as ContactManager; LockAttemptResult <Contact> lockResult; if (contact == null) { lockResult = new LockAttemptResult <Contact>(LockAttemptStatus.NotFound, null, null); contact = contactRepository.CreateContact(Sitecore.Data.ID.NewID); contact.Identifiers.AuthenticationLevel = Sitecore.Analytics.Model.AuthenticationLevel.None; contact.Identifiers.Identifier = emailAddress; contact.Identifiers.IdentificationLevel = ContactIdentificationLevel.Known; contact.System.Value = 0; contact.System.VisitCount = 0; contact.ContactSaveMode = ContactSaveMode.AlwaysSave; contactManager.FlushContactToXdb(contact); } else { lockResult = contactManager.TryLoadContact(contact.ContactId); contact = lockResult.Object; } var personal = contact.GetFacet <Sitecore.Analytics.Model.Entities.IContactPersonalInfo>("Personal"); personal.FirstName = subscribe.FullName; var emailAddresses = contact.GetFacet <Sitecore.Analytics.Model.Entities.IContactEmailAddresses>("Emails"); if (!emailAddresses.Entries.Contains("Email")) { emailAddresses.Entries.Create("Email"); } var email = emailAddresses.Entries["Email"]; email.SmtpAddress = emailAddress; emailAddresses.Preferred = "Email"; var contactEmailAddresses = contact.GetFacet <IVisitorSubscribtionFacet>("Contact Details"); if (!contactEmailAddresses.SubscriptionDetails.Contains("Subscriber Details")) { contactEmailAddresses.SubscriptionDetails.Create("Subscriber"); contactEmailAddresses.SubscriptionDetails["Subscriber"].FullName = subscribe.FullName; contactEmailAddresses.SubscriptionDetails["Subscriber"].ContactNumber = subscribe.ContactNumber; contactEmailAddresses.SubscriptionDetails["Subscriber"].Email = subscribe.Email; contactEmailAddresses.SubscriptionDetails["Subscriber"].Comments = subscribe.Comments; } ContactListManager listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", false) as ContactListManager; contactManager.SaveAndReleaseContactToXdb(contact); Tracker.Current.Session.Identify(subscribe.Email); //Getting the Email Campaign ManagerRoot Item managerRoot = Sitecore.Data.Database.GetDatabase(SitecoreHelper.GetSitecoreDB().ToString()).GetItem(GlobalProperties.EmailCampaignMangerRoot); RecipientId recipient = RecipientRepository.GetDefaultInstance().ResolveRecipientId("xdb:" + contact.ContactId); var recipientId = new Sitecore.Modules.EmailCampaign.Xdb.XdbContactId(contact.ContactId); Sitecore.Modules.EmailCampaign.ClientApi.UpdateSubscriptions(recipientId, new[] { GlobalGuids.ContactList }, new string[] { }, managerRoot.ID.ToString(), false); emailhelper.SendEmail(subscribe); subscribe.IsFormEnabled = false; } catch (Exception ex) { subscribe.IsError = true; subscribe.IsFormEnabled = false; Sitecore.Diagnostics.Log.Error(ex.Message, this); } } return(View("~/Views/Pages/Subscribe.cshtml", subscribe)); } subscribe.IsError = false; subscribe.IsFormEnabled = true; return(View("~/Views/Pages/Subscribe.cshtml", subscribe)); }
public IActionResult PostContact([FromForm] Contact contact) { var contactId = contactRepository.CreateContact(contact); return(RedirectToAction(nameof(Edit), new { contactId })); }