예제 #1
0
 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));
 }
예제 #2
0
        // GET: ColumnNavigation
        public ActionResult Index()
        {
            //ContactRepository contactRepository = Sitecore.Configuration.Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;

            ////var contactRepository = new ContactRepository();
            //var contact = contactRepository.LoadContactReadOnly("*****@*****.**");
            //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 = "*****@*****.**";
            //    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;
            //}
            ////CustomerDetailElement hh = new CustomerDetailElement();

            ////contact.Tags.Add("ContactLists", "test");

            //var contactEmailAddresses = contact.GetFacet<IContactCommentsFacet>("Contact Details");

            //if (!contactEmailAddresses.CustomerDetails.Contains("Contact Details"))
            //{
            //    contactEmailAddresses.CustomerDetails.Create("Contact Details");
            //    contactEmailAddresses.CustomerDetails["Contact Details"].Age = "12";
            //    contactEmailAddresses.CustomerDetails["Contact Details"].Company = "Companydfd";
            //    contactEmailAddresses.CustomerDetails["Contact Details"].Designation = "Designationdsddf";
            //    contactEmailAddresses.CustomerDetails["Contact Details"].Email = "Emaila";
            //}
            //var leaseOwner = new LeaseOwner(GetType() + Guid.NewGuid().ToString(), LeaseOwnerType.OutOfRequestWorker);
            //Tracker.Current.Session.Identify("*****@*****.**");
            ////contactManager.MergeContacts(contact, Tracker.Current.Contact);
            //// var options = new ContactSaveOptions(true, leaseOwner);
            //// Session.Abandon();
            //// repository.SaveContact(myContact, options);


            //ContactListManager listManager = Sitecore.Configuration.Factory.CreateObject("contactListManager", false) as ContactListManager;
            ////var list = listManager.FindById("{35858223-52DC-4785-E865-E164A01B0314}");
            ////List<ContactData> contactList = new List<ContactData>();

            ////var contacts = listManager.GetContacts(list); //this is how to get all contacts
            ////ContactData a = new ContactData() { Identifier = contact.Identifiers.Identifier };
            ////contactList.Add(a);
            ////listManager.AssociateContacts(list, contactList);
            ////contactManager.SaveAndReleaseContactToXdb(contact);


            ////listManager.AssociateContacts(list, contactList);
            //Item managerRoot = Sitecore.Data.Database.GetDatabase("master").GetItem("/sitecore/content/Email Campaign");

            //var recipientId = new Sitecore.Modules.EmailCampaign.Xdb.XdbContactId(contact.ContactId);
            //Sitecore.Modules.EmailCampaign.ClientApi.UpdateSubscriptions(recipientId, new[] { "{35858223-52DC-4785-E865-E164A01B0314}" }, new string[] { }, managerRoot.ID.ToString(), false);
            ////Sitecore.Modules.EmailCampaign.ClientApi.SendStandardMessage()


            ////ListManager<ContactList, ContactData> listManager = Factory.CreateObject("contactListManager", false) as ListManager<ContactList, ContactData>;
            ////using (new SecurityDisabler())
            ////{
            ////    using (IEnumerator<ContactList> enumerator = ((IEnumerable<ContactList>)listManager.GetAll((string)null, true)).GetEnumerator())
            ////    {
            ////        while (((IEnumerator)enumerator).MoveNext())
            ////        {
            ////            ContactList current = enumerator.Current;
            ////            //   output.AppendLine(current.Id.ToString());
            ////            Item obj = Factory.GetDatabase("master").GetItem(current.Id);
            ////            //this.Response.Write("List: " + current.get_DisplayName() + ", list id: (" + current.get_Id() + "), contacts in index: " + (object)listManager.GetContacts(current).Count<ContactData>() + ", contacts in field: " + ((BaseItem)obj).get_Item("Recipients"));
            ////            if (obj != null && listManager.GetContacts(current).Count<ContactData>() > int.Parse(((BaseItem)obj).Fields["Recipients"].ToString()))
            ////            {
            ////                obj.Editing.BeginEdit();
            ////                //  output.AppendLine(listManager.GetContacts(current).Count<ContactData>().ToString());
            ////                ((BaseItem)obj).Fields["Recipients"].Value = listManager.GetContacts(current).Count<ContactData>().ToString();
            ////                obj.Editing.EndEdit();
            ////                //this.Response.Write("</br>List field was updated");
            ////            }
            ////            //this.Response.Write("</br></br>");
            ////        }
            ////    }
            ////}

            //////var contact1 = Tracker.Current.Contact;
            //////var data1 = contact1.GetFacet<IEmployeeData>("Employee Data");
            //////data1.EmployeeId = "ABC123";
            ////new EventRaiser().RaiseEvent();
            ////new TriggerEvent().Trigger();
            ////CustomPipelineArgs pipelineArgs = new CustomPipelineArgs(Sitecore.Mvc.Presentation.PageContext.Current.Item);
            ////CorePipeline.Run("CustomPipeline", pipelineArgs);
            ////if (!pipelineArgs.Valid && !string.IsNullOrEmpty(pipelineArgs.Message))
            ////{
            ////    // Execute code here to deal with failed validation
            ////}



            //List<ColumnNavigationItem> navigation = new List<ColumnNavigationItem>();
            //Item homeItem = SitecoreHelper.GetSitecoreDB().GetItem("/sitecore/content/pier/pier7home", Sitecore.Context.Language);
            //foreach (Item childItem in homeItem.Children)
            //{
            //    Item checkItem = SitecoreHelper.GetSitecoreDB().GetItem(childItem.ID, Sitecore.Context.Language);
            //    var columnNavItem = SitecoreHelper.GetItem<ColumnNavigationItem>(checkItem.ID.ToGuid(), Sitecore.Context.Language);
            //    var pageMetaData = SitecoreHelper.GetItem<ExternalMetadata>(checkItem.ID.ToGuid(), Sitecore.Context.Language);

            //    if (checkItem != null && checkItem.Versions.Count > 0 && pageMetaData.IncludeInSitemap)
            //    {
            //        navigation.Add(columnNavItem);
            //    }
            //}
            //ColumnNavigationViewModel Navigation = new ColumnNavigationViewModel() { ColumnNavigationItems = navigation };

            var sitecoreService = new SitecoreService("web");
            var items           = Sitecore.Context.Item;
            var model1          = sitecoreService.Cast <MenuItem>(items);
            var model2          = sitecoreService.CreateType <ExternalMetadata>(items);

            List <ColumnNavigationItem> navigation = new List <ColumnNavigationItem>();
            var data = SitecoreHelper.GetItems <ColumnNavigationItem>(new Guid(GlobalGuids.ColumnNavigationItem),
                                                                      String.Format("{0}{1}", GlobalProperties.NavigationRootFolder, RenderingContext.CurrentOrNull.Rendering.Item.Name));

            foreach (var item in data)
            {
                Item checkItem = SitecoreHelper.GetSitecoreDB().GetItem(new Sitecore.Data.ID(item.Id), Sitecore.Context.Language);
                if (checkItem != null && checkItem.Versions.Count > 0)
                {
                    navigation.Add(item);
                }
            }
            ColumnNavigationViewModel Navigation = new ColumnNavigationViewModel()
            {
                ColumnNavigationItems = navigation
            };

            return(View("~/Views/Common/ColumnNavigation.cshtml", Navigation));
        }