Example #1
0
 public void InsertData()
 {
     try
     {
         List      oList     = ClientContext.Web.Lists.GetByTitle("Partnere");
         CamlQuery camlQuery = new CamlQuery();
         camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>";
         ListItemCollection collListItem = oList.GetItems(camlQuery);
         ClientContext.Load(collListItem);
         ClientContext.ExecuteQuery();
         var contentStatusId = Extension.GetApprovedConentStatusId(DKBSDbContext);
         foreach (ListItem oListItem in collListItem)
         {
             var hyperLink = ((FieldUrlValue)(oListItem["CISite"]));
             if (hyperLink != null)
             {
                 var           hLink   = ((FieldUrlValue)(oListItem["CISite"])).Url;
                 ClientContext Context = new ClientContext(hLink);
                 Context.AuthenticationMode           = ClientAuthenticationMode.FormsAuthentication;
                 Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("CRM Automation", "9LEkTny4");
                 Context.ExecuteQuery();
                 List oListData = Context.Web.Lists.GetByTitle("Inspirationskategorier (EN)");
                 camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>";
                 ListItemCollection oListDataItem = oListData.GetItems(camlQuery);
                 Context.Load(oListDataItem);
                 Context.ExecuteQuery();
                 CRMPartner partner = DKBSDbContext.CRMPartner.Where(p => p.AccountId == oListItem.Id.ToString()).Single();
                 foreach (ListItem oItem in oListDataItem)
                 {
                     try
                     {
                         log.Info($"PartnerInspirationCategoriesUK started. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}");
                         PartnerInspirationCategoriesUK uk = new PartnerInspirationCategoriesUK();
                         uk.Heading         = oItem["Headline"].ToSharepointString();
                         uk.CRMPartnerId    = partner.CRMPartnerId;
                         uk.Description     = oItem["Description"].ToSharepointString();
                         uk.CreatedBy       = oItem.GetAuthor();
                         uk.LastModifiedBY  = oItem.GetEditor();
                         uk.CreatedDate     = oItem.GetCreateDate();
                         uk.LastModified    = oItem.GetModifiedDate();
                         uk.ContentStatusId = contentStatusId;
                         uk.Price           = oItem["Price"].ToDecimal();
                         uk.Sorting         = oItem["Position"].ToInt();
                         uk.SharepointId    = oItem.Id;
                         DKBSDbContext.PartnerInspirationCategoriesUK.Add(uk);
                         DKBSDbContext.SaveChanges();
                         log.Info($"PartnerInspirationCategoriesUK completed. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}");
                     }
                     catch (Exception ex)
                     {
                         ErrorCount += 1;
                         log.Error($"PartnerInspirationCategoriesUK unable to process. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}", ex);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ErrorCount += ErrorCount;
         log.Error($"Unable to load Inspirationskategorier (EN)", ex);
     }
     log.Info($"Total ErrorCount:{ErrorCount}");
 }