public void InsertData() { try { List oListData = ClientContext.Web.Lists.GetByTitle("Centrets lokaler i tal"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='MaxPeopleAtTable' /><FieldRef Name='MaxPeopleAtUTable' /><FieldRef Name='MaxPeopleAtSchoolBoard' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='MaxPeopleByIsland' /><FieldRef Name='MaxPeopleInOneRoom' /><FieldRef Name='DivideRoom' /><FieldRef Name='Remarks' /><FieldRef Name='SiteCIIDLookup' /></ViewFields></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); ClientContext.Load(oListDataItem); ClientContext.ExecuteQuery(); var contentStatusId = Extension.GetApprovedConentStatusId(DKBSDbContext); foreach (ListItem oItem in oListDataItem) { CRMPartner partner = DKBSDbContext.CRMPartner.FirstOrDefault(p => p.AccountId == oItem.GetLookupId("SiteCIIDLookup")); if (partner == null) { ErrorCount += 1; log.Error($"Partner not found SharepointId:{oItem.Id}"); continue; } try { log.Info($"Partner room info started. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}"); PartnerCenterRoomInfo pRoom = new PartnerCenterRoomInfo() { RoomName = oItem["Title"].ToSharepointString(), SharepointId = oItem.GetId(), MaxPersonsAtMeetingTable = oItem["MaxPeopleAtTable"].ToInt(), MaxPersonsAtRowOfChairs = oItem["MaxPeopleInOneRoom"].ToInt(), MaxPersonsAtSchoolTable = oItem["MaxPeopleAtSchoolBoard"].ToInt(), MaxPersonsAtUTable = oItem["MaxPeopleAtUTable"].ToInt(), MaxPersonsAtIslands = oItem["MaxPeopleByIsland"].ToInt(), IsRoomdividetosmallroom = oItem["DivideRoom"].ToBoolean(), Remark = oItem["Remarks"].ToSharepointString(), CreatedDate = oItem.GetCreateDate(), LastModifiedBY = oItem.GetEditor(), CreatedBy = oItem.GetAuthor(), LastModified = oItem.GetModifiedDate(), ContentStatusId = contentStatusId, CRMPartnerId = partner.CRMPartnerId }; DKBSDbContext.Add(pRoom); DKBSDbContext.SaveChanges(); log.Info($"Partner room info completed. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Partner room info unable to process. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}", ex); } } } catch (Exception) { log.Error($"Unable to load Centrets lokaler i tal"); } log.Info($"Total ErrorCount:{ErrorCount}"); }
public PolicyResponse AddPolicy(PolicyRequest request) { var policy = new Policy() { Name = request.Name, Description = request.Description, CreatedBy = "user", CreatedDate = DateTime.UtcNow }; foreach (var resource in request.ResourceIds) { var resouce = new ResourcePolicy() { ResourceId = resource, PolicyId = policy.PolicyId }; policy.ResourcePolicies.Add(resouce); } _dbContext.Policy.Add(policy); _dbContext.SaveChanges(); return(_mapper.Map <PolicyResponse>(policy)); }
public static int GetApprovedConentStatusId(DKBSDbContext dbContext) { var contentStatus = dbContext.ContentStatus.FirstOrDefault(p => p.Description.ToLower() == "approved"); if (contentStatus == null) { contentStatus = new ContentStatus { Description = "Approved", CreatedBy = "Migration", CreatedDate = DateTime.Now, LastModifiedBy = "Migration", LastModified = DateTime.Now }; dbContext.ContentStatus.Add(contentStatus); dbContext.SaveChanges(); } return(contentStatus.ContentStatusId); }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { SP.List oListData = clientContext.Web.Lists.GetByTitle("Email templates"); CamlQuery camlQuery = new CamlQuery(); // camlQuery.ViewXml = "<View Scope='Recursive'><Query></Query></View>"; camlQuery.ViewXml = "<View><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='Subject' /><FieldRef Name='EmailBody' /><FieldRef Name='MailLanguage' /><FieldRef Name='Created' /><FieldRef Name='Modified' /></ViewFields></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Subject"]); Console.WriteLine(oItem["EmailBody"]); // Console.WriteLine(oItem["MailLanguage"]); // Console.WriteLine(((SP.FieldUserValue)(oItem["MailLanguage"])).LookupValue); EmailTemplate emailtemp = new EmailTemplate(); // if (oItem["ID"] != null) // if (Convert.ToInt32(oItem["ID"])>13) var x = Convert.ToDateTime(oItem["Modified"].ToString()); if (x.Year >= 2018) { if (oItem["Subject"] != null) { emailtemp.Subject = oItem["Subject"].ToString(); } else { emailtemp.Subject = "Missing Subject"; } emailtemp.Name = oItem["Title"].ToString(); // emailtemp.Subject = oItem["Subject"].ToString(); emailtemp.Content = oItem["EmailBody"].ToString(); emailtemp.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); emailtemp.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); emailtemp.CreatedBy = (((SP.FieldUserValue)(oItem["Author"])).LookupValue).ToString(); emailtemp.LastModifiedBy = (((SP.FieldUserValue)(oItem["Editor"])).LookupValue).ToString(); emailtemp.Language = "DK"; emailtemp.IsActive = true; dbContext.Add(emailtemp); dbContext.SaveChanges(); } } } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.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(); foreach (ListItem oListItem in collListItem) { var hyperLink = ((SP.FieldUrlValue)(oListItem["CISite"])); if (hyperLink != null) { Console.WriteLine("ID: {0} \nTitle: {1} \nSite: {2} \nSiteUrl: {3} ", oListItem.Id, oListItem["Title"], oListItem["CISite"], oListItem["CISiteShortUrl"]); var hLink = ((SP.FieldUrlValue)(oListItem["CISite"])).Url; Console.WriteLine(hLink); ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("CRM Automation", "9LEkTny4"); Context.ExecuteQuery(); SP.List oListData = Context.Web.Lists.GetByTitle("Kursuspakke"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1} \nKursuspakkeUK:{2} \nOffered: {3} \nPrice:{4}", oItem.Id, oItem["Title"], oItem["KursuspakkeUK"], oItem["Offered"], oItem["Price"]); Console.WriteLine("IncludedInPriceAdditional: {0} \nIncludedInPriceDefault:{1} \nOptionalPurchases: {2} \nPricePerYear:{3}", oItem["IncludedInPriceAdditional"], oItem["IncludedInPriceDefault"], oItem["OptionalPurchases"], oItem["PricePerYear"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["KursuspakkeID"]); CoursePackage coursePackage = dbContext.CoursePackage.Where(p => p.CoursePackageName == oItem["Title"].ToString()).First(); PartnerCoursePackage partnerCoursePackage = new PartnerCoursePackage(); PartnerPackageYear partnerPackageYear = new PartnerPackageYear(); // partnerCoursePackage.CRMPartnerId = oListItem.Id; partnerCoursePackage.CRMPartnerId = 1; //hard-coded value for test purpose partnerCoursePackage.CoursePackageId = coursePackage.CoursePackageId; // partnerCoursePackage.CoursePackageId = oItem.Id; partnerCoursePackage.ContentStatusId = 1; //hard-coded value for test purpose partnerCoursePackage.Offered = Convert.ToBoolean(oItem["Offered"]); partnerCoursePackage.Price = Convert.ToDecimal(oItem["Price"]); partnerCoursePackage.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); partnerCoursePackage.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); partnerCoursePackage.LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; partnerCoursePackage.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; partnerPackageYear.PartnerCoursePackageId = oItem.Id; // if(oItem["PricePerYear"] != null) partnerPackageYear.Year = Convert.ToInt32(oItem["PricePerYear"]); partnerPackageYear.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); partnerPackageYear.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); partnerPackageYear.LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; partnerPackageYear.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; //partnerPackageYear.PricePerPerson = oItem. if (oItem["IncludedInPriceDefault"] != null) { ArrayList parsedData = new ArrayList(); partnerCoursePackage.PartnerPackageIncludedItems = new List <PartnerPackageIncludedItem>(); SharedFunctions sharedFunctions = new SharedFunctions(); parsedData = sharedFunctions.ParseFunction(oItem["IncludedInPriceDefault"].ToString()); if (parsedData.Count > 0) { foreach (List <String> pacakageData in parsedData) { Console.WriteLine(pacakageData); Array pacakageDataArray = pacakageData.ToArray(); PackageIncludedItem packageIncludedItem = dbContext.PackageIncludedItem.Where(p => p.DK == pacakageData[0]).First(); partnerCoursePackage.PartnerPackageIncludedItems.Add(new PartnerPackageIncludedItem() { PartnerCoursePackageId = oItem.Id, PartnerPackageIncludedItemId = packageIncludedItem.PackageIncludedItemId, Offered = (pacakageData.Count > 2 ? (pacakageData[2] == "checked" ? true : false) : false) }); } } } //else //{ // partnerCoursePackage.PartnerPackageIncludedItems.Add(new PartnerPackageIncludedItems() { CoursePackageId = Convert.ToInt32(oItem["ID"]) }); //} if (oItem["IncludedInPriceAdditional"] != null) { ArrayList parsedData = new ArrayList(); partnerCoursePackage.PartnerPackageIncludedItems = new List <PartnerPackageIncludedItem>(); SharedFunctions sharedFunctions = new SharedFunctions(); parsedData = sharedFunctions.ParseFunction(oItem["IncludedInPriceAdditional"].ToString()); if (parsedData.Count > 0) { foreach (List <String> pacakageData in parsedData) { Console.WriteLine(pacakageData); Array pacakageDataArray = pacakageData.ToArray(); partnerCoursePackage.PartnerPackageAdditionalItems.Add(new PartnerPackageAdditionalItem() { PartnerCoursePackageId = oItem.Id, DK = pacakageData[0], CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()), LastModified = Convert.ToDateTime(oItem["Modified"].ToString()), LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue, CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue, Price = Convert.ToDecimal(oItem["Price"]) }); } } } if (oItem["OptionalPurchases"] != null) { ArrayList parsedData = new ArrayList(); partnerCoursePackage.PartnerPackageIncludedItems = new List <PartnerPackageIncludedItem>(); SharedFunctions sharedFunctions = new SharedFunctions(); parsedData = sharedFunctions.ParseFunction(oItem["OptionalPurchases"].ToString()); if (parsedData.Count > 0) { foreach (List <String> pacakageData in parsedData) { Console.WriteLine(pacakageData); Array pacakageDataArray = pacakageData.ToArray(); partnerCoursePackage.PartnerPackageAdditionalItems.Add(new PartnerPackageAdditionalItem() { PartnerCoursePackageId = oItem.Id, DK = pacakageData[0], CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()), LastModified = Convert.ToDateTime(oItem["Modified"].ToString()), LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue, CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue //Price = pacakageData[2] == "" ? 0 : Convert.ToDecimal(pacakageData[2]) }); } } } dbContext.Add(partnerCoursePackage); dbContext.SaveChanges(); } } } } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.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(); foreach (ListItem oListItem in collListItem) { var hyperLink = ((SP.FieldUrlValue)(oListItem["CISite"])); if (hyperLink != null) { Console.WriteLine("ID: {0} \nTitle: {1} \nSite: {2} \nSiteUrl: {3} ", oListItem.Id, oListItem["Title"], oListItem["CISite"], oListItem["CISiteShortUrl"]); var hLink = ((SP.FieldUrlValue)(oListItem["CISite"])).Url; Console.WriteLine(hLink); ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("CRM Automation", "9LEkTny4"); Context.ExecuteQuery(); SP.List oListData = Context.Web.Lists.GetByTitle("Aktiviteter"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nHeadline: {1}", oItem["ID"], oItem["Headline"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Title"]); Console.WriteLine(oItem["Description"]); Console.WriteLine(oItem["Picture"]); Console.WriteLine(oItem["Price"]); PartnerInspirationCategoriesDK partnerInspirationCategoriesDK = new PartnerInspirationCategoriesDK(); // partnerInspirationCategoriesDK.ContentStatusId = 2;//Approved // partnerInspirationCategoriesDK.CRMPartnerId = oListItem.Id; partnerInspirationCategoriesDK.ContentStatusId = 1; //Approved partnerInspirationCategoriesDK.CRMPartnerId = 1; if (oItem["Headline"] != null) { partnerInspirationCategoriesDK.Heading = oItem["Headline"].ToString(); } // partnerInspirationCategoriesDK.CRMPartnerId = 1; if (oItem["Description"] != null) { partnerInspirationCategoriesDK.Description = oItem["Description"].ToString(); } if (oItem["ID"] != null) { partnerInspirationCategoriesDK.SharepointId = oItem.Id; } if (((SP.FieldUserValue)(oItem["Author"])).LookupValue != null) { partnerInspirationCategoriesDK.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; } if (((SP.FieldUserValue)(oItem["Editor"])).LookupValue != null) { partnerInspirationCategoriesDK.LastModifiedBY = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; } if (oItem["Created"] != null) { partnerInspirationCategoriesDK.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); } if (oItem["Modified"] != null) { partnerInspirationCategoriesDK.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); } if (oItem["Price"] != null) { partnerInspirationCategoriesDK.Price = Convert.ToDecimal(oItem["Price"].ToString()); } dbContext.Add(partnerInspirationCategoriesDK); dbContext.SaveChanges(); } } } } catch (Exception) { throw; } }
public async void InsertData() { try { var oListData = ClientContext.Web.Lists.GetByTitle("Aftaler & dokumenter"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); ClientContext.Load(oListDataItem); ClientContext.Load(oListDataItem, t => t.Include(p => p.Id, p => p.ContentType, p => p.DisplayName, p => p.FieldValuesAsText)); ClientContext.ExecuteQuery(); log.Info($"Aftaler & dokumenter List data pulled successfully."); foreach (ListItem oItem in oListDataItem) { DocumentCategory category; List <PartnerType> partnerTypes = new List <PartnerType>(); try { log.Info($"Document data processing started Id :{oItem.GetId()}"); DocumentMetaData doc = new DocumentMetaData() { CreatedBy = oItem.GetAuthor(), CreatedDate = oItem.GetCreateDate(), LastModifiedBy = oItem.GetEditor(), LastModifiedDate = oItem.GetModifiedDate(), }; doc.ExpirationDate = oItem.GetModifiedDate(); if (oItem["RelatedPartnerType"] != null) { var childIdField = oItem["RelatedPartnerType"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { if (!DKBSDbContext.PartnerType.ToList().Exists(p => p.PartnerTypeTitle.ToLower() == lookupValue.LookupValue.ToLower())) { var partnerType = new PartnerType() { PartnerTypeTitle = lookupValue.LookupValue, CreatedBy = doc.CreatedBy, CreatedDate = doc.CreatedDate, LastModified = doc.LastModifiedDate, LastModifiedBy = doc.LastModifiedBy }; DKBSDbContext.PartnerType.Add(partnerType); DKBSDbContext.SaveChanges(); partnerTypes.Add(partnerType); } else { var partnerType = DKBSDbContext.PartnerType.FirstOrDefault(p => p.PartnerTypeTitle.ToLower() == lookupValue.LookupValue.ToLower()); if (partnerType != null) { partnerTypes.Add(partnerType); } } } } } ClientContext.Load(oItem.ContentType); ClientContext.ExecuteQuery(); if (!DKBSDbContext.DocumentCategory.ToList().Exists(p => p.CategoryName.ToLower() == oItem.ContentType.Name.ToLower())) { category = new Domain.DocumentCategory { CategoryName = oItem.ContentType.Name, CreatedBy = doc.CreatedBy, CreatedDate = doc.CreatedDate, LastModified = doc.LastModifiedDate, LastModifiedBy = doc.LastModifiedBy }; DKBSDbContext.DocumentCategory.Add(category); DKBSDbContext.SaveChanges(); } else { category = DKBSDbContext.DocumentCategory.FirstOrDefault(p => p.CategoryName.ToLower() == oItem.ContentType.Name.ToLower()); } if (oItem.FileSystemObjectType == FileSystemObjectType.File) { Microsoft.SharePoint.Client.File lfile = oItem.File; ClientContext.Load(lfile); ClientContext.ExecuteQuery(); doc.FileName = oItem.File.Name; log.Info($"Document uploading started FileName :{doc.FileName}"); var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ClientContext, lfile.ServerRelativeUrl); var url = await _storageService.SaveDocumentAsync(fileInfo.Stream, doc.FileName, category.DocumentCategoryId); log.Info($"Document uploaded sucessfully. started FileName :{doc.FileName} Category: {oItem.ContentType.Name}"); } var document = new Document() { DocumentCategoryId = category.DocumentCategoryId, ExpirationDate = doc.ExpirationDate, CreatedBy = doc.CreatedBy, CreatedDate = doc.CreatedDate, LastModified = doc.LastModifiedDate, LastModifiedBy = doc.LastModifiedBy, Details = doc.Detail, DocumentName = doc.FileName, FileName = doc.FileName }; foreach (var partnerType in partnerTypes) { var partnerTypeDoc = new PartnerTypeDocument(); partnerTypeDoc.DocumentId = document.DocumentId; partnerTypeDoc.PartnerTypeId = partnerType.PartnerTypeId; document.PartnerTypeDocuments.Add(partnerTypeDoc); } DKBSDbContext.Document.Add(document); DKBSDbContext.SaveChanges(); log.Info($"Document upload successfully Name :{doc.FileName}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Unable to upload file. Id:{oItem.GetId()}", ex); } } } catch (Exception ex) { ErrorCount += 1; log.Error("Unable to get documents data from sharepoint.", ex); } log.Info($"Total ErrorCount:{ErrorCount}"); }
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) { try { 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("Aktiviteter"); 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($"PartnerInspirationCategoriesDK started. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}"); PartnerInspirationCategoriesDK dk = new PartnerInspirationCategoriesDK(); dk.CRMPartnerId = partner.CRMPartnerId; dk.ContentStatusId = contentStatusId; dk.Heading = oItem["Headline"].ToSharepointString(); dk.Description = oItem["Description"].ToSharepointString(); dk.SharepointId = oItem.GetId(); dk.CreatedBy = oItem.GetAuthor(); dk.LastModifiedBY = oItem.GetEditor(); dk.CreatedDate = oItem.GetCreateDate(); dk.LastModified = oItem.GetModifiedDate(); dk.Price = oItem["Price"].ToDecimal(); dk.Sorting = oItem["Position"].ToInt(); DKBSDbContext.PartnerInspirationCategoriesDK.Add(dk); DKBSDbContext.SaveChanges(); log.Info($"PartnerInspirationCategoriesDK completed. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"PartnerInspirationCategoriesDK unable to process. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}", ex); } } } } catch (Exception ex) { ErrorCount += 1; log.Error($"PartnerInspirationCategoriesDK unable to process. Partner Id: {oListItem.GetId()}", ex); } } } catch (Exception) { ErrorCount += ErrorCount; log.Error($"Unable to load Centrets lAktiviteter"); } log.Info($"Total ErrorCount:{ErrorCount}"); }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Centrets lokaler i tal"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='MaxPeopleAtTable' /><FieldRef Name='MaxPeopleAtUTable' /><FieldRef Name='MaxPeopleAtSchoolBoard' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='MaxPeopleByIsland' /><FieldRef Name='MaxPeopleInOneRoom' /><FieldRef Name='DivideRoom' /><FieldRef Name='Remarks' /><FieldRef Name='SiteCIIDLookup' /></ViewFields></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); // Console.WriteLine(((SP.FieldUserValue)(oItem["SiteCIDLookup"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["MaxPeopleAtTable"]); Console.WriteLine(oItem["MaxPeopleAtUTable"]); Console.WriteLine(oItem["MaxPeopleAtSchoolBoard"]); Console.WriteLine(oItem["MaxPeopleByIsland"]); Console.WriteLine(oItem["MaxPeopleInOneRoom"]); Console.WriteLine(oItem["DivideRoom"]); Console.WriteLine(oItem["Remarks"]); PartnerCenterRoomInfo partnerCenterRoomInfo = new PartnerCenterRoomInfo(); if (oItem["Title"] != null) { partnerCenterRoomInfo.RoomName = oItem["Title"].ToString(); } if (oItem["ID"] != null) { partnerCenterRoomInfo.SharepointId = oItem.Id; // partnerCenterRoomInfo.PartnerCenterRoomInfoSpId = oItem.Id; } if (oItem["MaxPeopleAtTable"] != null) { partnerCenterRoomInfo.MaxPersonsAtMeetingTable = Convert.ToInt32(oItem["MaxPeopleAtTable"]); } if (oItem["MaxPeopleInOneRoom"] != null) { partnerCenterRoomInfo.MaxPersonsAtRowOfChairs = Convert.ToInt32(oItem["MaxPeopleInOneRoom"]); } if (oItem["MaxPeopleAtSchoolBoard"] != null) { partnerCenterRoomInfo.MaxPersonsAtSchoolTable = Convert.ToInt32(oItem["MaxPeopleAtSchoolBoard"]); } if (oItem["MaxPeopleAtUTable"] != null) { partnerCenterRoomInfo.MaxPersonsAtUTable = Convert.ToInt32(oItem["MaxPeopleAtUTable"]); } if (oItem["MaxPeopleByIsland"] != null) { partnerCenterRoomInfo.MaxPersonsAtIslands = Convert.ToInt32(oItem["MaxPeopleByIsland"]); } if (oItem["DivideRoom"] != null && oItem["DivideRoom"].ToString() != "") { partnerCenterRoomInfo.IsRoomdividetosmallroom = Convert.ToBoolean(oItem["DivideRoom"]); } if (oItem["Remarks"] != null) { partnerCenterRoomInfo.Remark = oItem["Remarks"].ToString(); } if (oItem["Created"] != null) { partnerCenterRoomInfo.CreatedDate = Convert.ToDateTime(oItem["Created"]); } if (oItem["Editor"] != null) { partnerCenterRoomInfo.LastModifiedBY = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; } if (oItem["Author"] != null) { partnerCenterRoomInfo.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; } if (oItem["Modified"] != null) { partnerCenterRoomInfo.LastModified = Convert.ToDateTime(oItem["Modified"]); } //partnerCenterRoomInfo.CRMPartnerId = 1; if (oItem["SiteCIIDLookup"] != null) { Console.WriteLine(oItem["SiteCIIDLookup"]); var childIdField = oItem["SiteCIIDLookup"] as FieldLookupValue; if (childIdField != null) { Console.WriteLine("LookupID: " + childIdField.LookupId.ToString()); Console.WriteLine("LookupValue: " + childIdField.LookupValue.ToString()); partnerCenterRoomInfo.CRMPartnerId = childIdField.LookupId; } } dbContext.Add(partnerCenterRoomInfo); dbContext.SaveChanges(); } } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Provision"); ListItemCollectionPosition position = null; var page = 1; do { CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='Recursive'><Query></Query><RowLimit>5000</RowLimit></View>"; camlQuery.ListItemCollectionPosition = position; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); position = oListDataItem.ListItemCollectionPosition; foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Afrejse"]); Console.WriteLine(oItem["Ankomst"]); Console.WriteLine(oItem["DatoForAfsendelse"]); Console.WriteLine(oItem["Debtor"]); Console.WriteLine(oItem["Pris"]); Console.WriteLine(oItem["LinkToParentItem"]); Console.WriteLine(oItem["UnitID"]); if (oItem["PartnerLookup"] != null) { Console.WriteLine(oItem["PartnerLookup"]); var childIdField = oItem["PartnerLookup"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } if (oItem["Kunde"] != null) { Console.WriteLine(oItem["Kunde"]); var childIdField = oItem["Kunde"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } if (oItem["BookingerID"] != null) { Console.WriteLine(oItem["BookingerID"]); var childIdField = oItem["BookingerID"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } Provision provision = new Provision(); provision.ProvisionId = 1;//index; To Do compile error. provision.CRMPartnerId = 1; provision.CustomerId = 3; provision.BookingId = 7; if (oItem["Pris"] != null) { provision.Price = Convert.ToDecimal(oItem["Pris"]); } if (oItem["Created"] != null) { provision.CreatedDate = Convert.ToDateTime(oItem["Created"]); } if (oItem["DatoForAfsendelse"] != null) { provision.DateofShipment = Convert.ToDateTime(oItem["DatoForAfsendelse"]); } if (oItem["Debtor"] != null) { provision.Debtor = oItem["Debtor"].ToString(); } if (oItem["Title"] != null) { provision.ProvisionName = oItem["Title"].ToString(); } provision.UnitID = Convert.ToInt32(oItem["UnitID"]); provision.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; provision.ProvisionSpID = Convert.ToInt32(oItem["ID"]); provision.LastModified = oItem["Modified"].ToString(); provision.LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; dbContext.Add(provision); dbContext.SaveChanges(); } page++; }while (position != null); } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Service request communications"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Communications"]); Console.WriteLine(oItem["FromMyIT"]); Console.WriteLine(oItem["Created"]); Console.WriteLine(oItem["CopyToCloseRemark"]); Console.WriteLine(oItem["IsPartnerSideCommunication"]); Console.WriteLine(oItem["ProcedureInfoCommunication"]); if (oItem["ServiceRequestID"] != null) { Console.WriteLine(oItem["ServiceRequestID"]); var childIdField = oItem["ServiceRequestID"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } if (oItem["ITProcedureID"] != null) { Console.WriteLine(oItem["ITProcedureID"]); var childIdField = oItem["ITProcedureID"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } ChatCommunications chatCommunications = new ChatCommunications(); if (oItem["Title"] != null) { chatCommunications.ChatTitle = oItem["Title"].ToString(); } else { chatCommunications.ChatTitle = "No Chat Title"; } chatCommunications.BookingId = 7; if (oItem["Communications"] != null) { chatCommunications.ChatCommunication = oItem["Communications"].ToString(); } chatCommunications.ProcedureId = 2; if (oItem["IsPartnerSideCommunication"] != null) { chatCommunications.IsPartnerSideCommunication = Convert.ToBoolean(oItem["IsPartnerSideCommunication"]); } if (oItem["ProcedureInfoCommunication"] != null) { chatCommunications.ProcedureCommunication = Convert.ToBoolean(oItem["ProcedureInfoCommunication"]); } if (oItem["ID"] != null) { chatCommunications.SharepointId = Convert.ToInt32(oItem["ID"]); } chatCommunications.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; chatCommunications.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); dbContext.Add(chatCommunications); dbContext.SaveChanges(); } } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Service katalog"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); SharedFunctions sharedFunctions = new SharedFunctions(); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["KursuspakkeUK"]); Console.WriteLine(oItem["Offered"]); Console.WriteLine(oItem["Price"]); Console.WriteLine(oItem["KursuspakkeID"]); Console.WriteLine(oItem["IncludedInPriceDefault"]); Console.WriteLine(oItem["IncludedInPriceAdditional"]); Console.WriteLine(oItem["OptionalPurchases"]); var coursepack = new CoursePackage(); coursepack.CoursePackageName = oItem["Title"].ToString(); coursepack.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); coursepack.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); //coursepack.Offered = oItem["Offered"].ToString(); coursepack.Price = Convert.ToDecimal(oItem["Price"]); //coursepack.CreatedBy = oItem["Author"].ToString(); // coursepack.LastModifiedBy = oItem["Editor"].ToString(); coursepack.CreatedBy = (((SP.FieldUserValue)(oItem["Author"])).LookupValue).ToString(); coursepack.LastModifiedBy = (((SP.FieldUserValue)(oItem["Editor"])).LookupValue).ToString(); ArrayList parsedData = new ArrayList(); coursepack.PackageIncludedItems = new List <PackageIncludedItem>(); if (oItem["IncludedInPriceDefault"] != null) { parsedData = sharedFunctions.ParseFunction(oItem["IncludedInPriceDefault"].ToString()); if (parsedData.Count > 0) { foreach (List <String> pacakageData in parsedData) { Console.WriteLine(pacakageData); Array pacakageDataArray = pacakageData.ToArray(); coursepack.PackageIncludedItems.Add(new PackageIncludedItem() { CoursePackageId = Convert.ToInt32(oItem["ID"]), DK = pacakageData[0].ToString() }); } } } else { coursepack.PackageIncludedItems.Add(new PackageIncludedItem() { CoursePackageId = Convert.ToInt32(oItem["ID"]) }); } dbContext.Add(coursepack); dbContext.SaveChanges(); //if (oItem["KursuspakkeTypen"] != null) //{ // Console.WriteLine(oItem["KursuspakkeTypen"]); // var childIdField = oItem["KursuspakkeTypen"] as FieldLookupValue[]; // if (childIdField != null) // { // foreach (var lookupValue in childIdField) // { // var childId_Value = lookupValue.LookupValue; // var childId_Id = lookupValue.LookupId; // Console.WriteLine("LookupID: " + childId_Id.ToString()); // Console.WriteLine("LookupValue: " + childId_Value.ToString()); // } // } //} } } catch (Exception) { throw; } }
public int Complete() { return(_context.SaveChanges()); }
public void InsertData() { try { List oList = ClientContext.Web.Lists.GetByTitle("Partnere"); CamlQuery camlQuery = new CamlQuery(); //<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>49</Value></Eq> camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Where></Query></View>"; ListItemCollection collListItem = oList.GetItems(camlQuery); ClientContext.Load(collListItem); ClientContext.ExecuteQuery(); //get content status Id. var contentStatusId = Extension.GetApprovedConentStatusId(DKBSDbContext); foreach (ListItem oListItem in collListItem) { var hyperLink = ((FieldUrlValue)(oListItem["CISite"])); if (hyperLink != null) { try { var hLink = ((FieldUrlValue)(oListItem["CISite"])).Url; ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(Configuration["SharePointUserName"], Configuration["SharePointPassword"]); Context.ExecuteQuery(); List oListData = Context.Web.Lists.GetByTitle("Kursuspakke"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { log.Info($"Partner course package data process started Partner Id: {oItem.Id}"); try { log.Info($"Partner course package data process started Kursuspakke: {oItem.Id} Service Catalog Id { oItem["KursuspakkeID"].ToInt(true, 0)}"); CoursePackage coursePackage = DKBSDbContext.CoursePackage.Where(p => p.SharepointId == oItem["KursuspakkeID"].ToInt(true, 0)).Single(); CRMPartner partner = DKBSDbContext.CRMPartner.Where(p => p.AccountId == oListItem.Id.ToString()).Single(); PartnerCoursePackage partnerPackage = new PartnerCoursePackage(); partnerPackage.CRMPartnerId = partner.CRMPartnerId; partnerPackage.SharepointId = oItem.Id; partnerPackage.CoursePackageId = coursePackage.CoursePackageId; partnerPackage.ContentStatusId = contentStatusId; partnerPackage.Offered = oItem["Offered"].ToBoolean(); partnerPackage.Price = oItem["Price"].ToDecimal(); partnerPackage.CreatedDate = oItem.GetCreateDate(); partnerPackage.LastModified = oItem.GetModifiedDate(); partnerPackage.LastModifiedBy = oItem.GetEditor(); partnerPackage.CreatedBy = oItem.GetAuthor(); var includedPriceDetails = oItem["IncludedInPriceDefault"].ParseString(); var additionalIncluded = oItem["IncludedInPriceAdditional"].ParseString(); var optionalPurchages = oItem["OptionalPurchases"].ParseString(); var pricePerYear = oItem["PricePerYear"].ParseString(); // Included in price foreach (var item in includedPriceDetails) { var packageItem = DKBSDbContext.PackageIncludedItem.First(p => p.CoursePackageId == coursePackage.CoursePackageId && p.DK == item[0]); PartnerPackageIncludedItem ppi = new PartnerPackageIncludedItem() { PartnerCoursePackageId = partnerPackage.PartnerCoursePackageId, CreatedDate = oItem.GetCreateDate(), LastModified = oItem.GetModifiedDate(), LastModifiedBy = oItem.GetEditor(), CreatedBy = oItem.GetAuthor(), PackageIncludedItemId = packageItem.PackageIncludedItemId, Offered = item[2].IsChecked(), }; partnerPackage.PartnerPackageIncludedItems.Add(ppi); } // additional included foreach (var item in additionalIncluded) { PartnerPackageAdditionalItem ppai = new PartnerPackageAdditionalItem() { PartnerCoursePackageId = partnerPackage.PartnerCoursePackageId, CreatedDate = oItem.GetCreateDate(), LastModified = oItem.GetModifiedDate(), LastModifiedBy = oItem.GetEditor(), CreatedBy = oItem.GetAuthor(), DK = item[0], UK = item[1] }; partnerPackage.PartnerPackageAdditionalItems.Add(ppai); } // optional purchages in price foreach (var item in optionalPurchages) { PartnerPackageAdditionalItem ppai = new PartnerPackageAdditionalItem() { PartnerCoursePackageId = partnerPackage.PartnerCoursePackageId, CreatedDate = oItem.GetCreateDate(), LastModified = oItem.GetModifiedDate(), LastModifiedBy = oItem.GetEditor(), CreatedBy = oItem.GetAuthor(), DK = item[0], UK = item[1], Price = item[2].ToDecimal(defaultData: true, defaultDataValue: 0).Value }; partnerPackage.PartnerPackageAdditionalItems.Add(ppai); } // Price next year foreach (var item in pricePerYear) { PartnerPackageYear pny = new PartnerPackageYear() { PartnerCoursePackageId = partnerPackage.PartnerCoursePackageId, CreatedDate = oItem.GetCreateDate(), LastModified = oItem.GetModifiedDate(), LastModifiedBy = oItem.GetEditor(), CreatedBy = oItem.GetAuthor(), Year = item[0].ToInt(true, 0).Value, PricePerPerson = item[1].ToDecimal(true, 0).Value, }; partnerPackage.PartnerPackageYears.Add(pny); } DKBSDbContext.Add(partnerPackage); DKBSDbContext.SaveChanges(); log.Info($"Partner course package data process completed Kursuspakke: {oItem.Id} Service Catalog Id { oItem["KursuspakkeID"].ToInt(true, 0)}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Error:Unable to insert Course package Kursuspakke Id: {oItem.Id} Service Catalog Id { oItem["KursuspakkeID"].ToInt(true, 0)}", ex); } } log.Info($"Partner course package data process completed Partner Id: {oListItem.Id}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Error:Unable to pull Kursuspakke. PartnerId:{oListItem.Id}", ex); } } } } catch (Exception ex) { log.Error($"Error:Unable to pull Partnere.", ex); } log.Info($"Total ErrorCount:{ErrorCount}"); }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Service request notes"); ListItemCollectionPosition position = null; var page = 1; do { CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='Recursive'><Query></Query><RowLimit>5000</RowLimit></View>"; camlQuery.ListItemCollectionPosition = position; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); position = oListDataItem.ListItemCollectionPosition; foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Action"]); Console.WriteLine(oItem["ScheduleAction"]); Console.WriteLine(oItem["PlannedStart"]); Console.WriteLine(oItem["Notify"]); Console.WriteLine(oItem["PlannedEnd"]); Console.WriteLine(oItem["CopyToCloseRemark"]); if (oItem["ServiceRequestID"] != null) { Console.WriteLine(oItem["ServiceRequestID"]); var childIdField = oItem["ServiceRequestID"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } if (oItem["CloseField"] != null) { Console.WriteLine(oItem["CloseField"]); var childIdField = oItem["CloseField"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } InternalComments internalComments = new InternalComments(); internalComments.BookingId = 7; if (oItem["Action"] != null) { internalComments.Comments = oItem["Action"].ToString(); } // internalComments.InternalNotifyId = 1; if (oItem["ID"] != null) { internalComments.SharepointId = Convert.ToInt32(oItem["ID"]); } if (oItem["Author"] != null) { internalComments.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; } if (oItem["Created"] != null) { internalComments.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); } dbContext.Add(internalComments); dbContext.SaveChanges(); } page++; }while (position != null); } catch (Exception) { throw; } }
public void Complete() { _dbContext.SaveChanges(); }
public async void InsertData() { var oList = ClientContext.Web.Lists.GetByTitle("Partnere"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='Recursive'><Query><ViewFields><FieldRef Name='ID'/><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='CISite'/><FieldRef Name='CISiteShortUrl'/></ViewFields></Query></View>"; ListItemCollection collListItem = oList.GetItems(camlQuery); ClientContext.Load(collListItem); ClientContext.ExecuteQuery(); log.Info($"Partnere & dokumenter List data pulled successfully."); foreach (ListItem oListItem in collListItem) { try { var hyperLink = ((FieldUrlValue)(oListItem["CISite"])); log.Info($"Partner CISite Partner Id {oListItem.Id} Title :{oListItem["Title"]}"); if (hyperLink != null) { CRMPartner crmPartner = DKBSDbContext.CRMPartner.FirstOrDefault(p => p.SharePointId == int.Parse(oListItem["ID"].ToString())); if (crmPartner == null) { log.Error($"Partner not found in dkbs sql database Sharepoint Id:{oListItem.GetId()}"); continue; } log.Info($"Started Partner Id {oListItem.Id} Title :{oListItem["Title"]}"); var hLink = ((FieldUrlValue)(oListItem["CISite"])).Url; ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(Configuration["SharePointUserName"], Configuration["SharePointPassword"]); Context.ExecuteQuery(); var oListData = Context.Web.Lists.GetByTitle("Billeder"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); log.Info($"Pictures/Billeder List data pulled successfully. Partner Id {oListItem.GetId()}"); foreach (ListItem oItem in oListDataItem) { try { if (oItem.FileSystemObjectType == FileSystemObjectType.Folder) { Microsoft.SharePoint.Client.Folder ifolder = oItem.Folder; Context.Load(ifolder); Context.ExecuteQuery(); if (!string.IsNullOrWhiteSpace(ifolder.Name.ToLower())) { var pictureFolder = DKBSDbContext.PictureFolder.FirstOrDefault(p => p.FolderName.ToLower() == ifolder.Name.ToLower()); if (pictureFolder == null) { pictureFolder = new PictureFolder { CreatedBy = oItem.GetAuthor(), CreatedDate = oItem.GetCreateDate(), LastModifiedBy = oItem.GetEditor(), LastModified = oItem.GetModifiedDate(), FolderName = ifolder.Name }; DKBSDbContext.PictureFolder.Add(pictureFolder); DKBSDbContext.SaveChanges(); } } } if (oItem.FileSystemObjectType == FileSystemObjectType.File) { PictureFolder pictureFolder = null; Microsoft.SharePoint.Client.File lfile = oItem.File; Context.Load(lfile); Context.ExecuteQuery(); try { //get the folder var tempArray = lfile.ServerRelativeUrl.Replace(@"/" + lfile.Name, "").Split('/'); var folderName = tempArray.ToList().Last(); pictureFolder = DKBSDbContext.PictureFolder.FirstOrDefault(p => p.FolderName.ToLower() == folderName.ToLower()); if (pictureFolder == null) { log.Error($"Unable to find folder for picture. Id:{oItem["ID"]} Picture Name :{lfile.Name} Path : {lfile.ServerRelativeUrl}"); throw new ArgumentNullException($"Unable to find folder for picture. Id:{oItem.GetId()} Picture Name :{lfile.Name} Path : {lfile.ServerRelativeUrl}"); } log.Info($"Picture Name :{lfile.Name} upload started."); var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(Context, lfile.ServerRelativeUrl); await _storageService.SavePictureAsync(fileInfo.Stream, lfile.Name, crmPartner.CRMPartnerId, pictureFolder.PictureFolderId); } catch (Exception ex) { log.Error($"Unable to upload picture. Id:{oItem.GetId()} Picture Name :{lfile.Name}", ex); throw ex; } var picture = new Picture() { CreatedBy = oItem.GetAuthor(), CreatedDate = oItem.GetCreateDate(), LastModifiedBy = oItem.GetEditor(), LastModified = oItem.GetModifiedDate(), CRMPartnerId = crmPartner.CRMPartnerId, PictureFolderId = pictureFolder.PictureFolderId, PictureName = lfile.Name, Title = lfile.Title }; picture.Description = oItem["Description"].ToSharepointString(); picture.Position = oItem["ImagePosition"].ToInt(); DKBSDbContext.Picture.Add(picture); DKBSDbContext.SaveChanges(); log.Info($"Picture Name :{lfile.Name} uploaded successfully."); } } catch (Exception ex) { ErrorCount += 1; log.Error($"Unable to upload picture. Id:{oItem.GetId()}", ex); } } } } catch (Exception ex) { ErrorCount += 1; log.Error($"Partner pictures unable to load Id:{oListItem.GetId()}", ex); } } }
public void InsertData() { try { List oListData = ClientContext.Web.Lists.GetByTitle("Service katalog"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); ClientContext.Load(oListDataItem); ClientContext.ExecuteQuery(); log.Info($"Service katalog List data pulled successfully."); foreach (ListItem oItem in oListDataItem) { try { log.Info($"Service katalog process started [Id]:{oItem.GetId()}"); var coursepack = new CoursePackage(); coursepack.SharepointId = oItem.GetId(); coursepack.CoursePackageName = oItem["Title"].ToString(); coursepack.CreatedDate = oItem.GetCreateDate(); coursepack.LastModified = oItem.GetModifiedDate(); coursepack.Offered = oItem["Offered"].ToBoolean(); coursepack.Price = oItem["Price"].ToDecimal(); coursepack.CreatedBy = oItem.GetAuthor(); coursepack.LastModifiedBy = oItem.GetEditor(); coursepack.PackageIncludedItems = new List <PackageIncludedItem>(); var childData = oItem["IncludedInPriceDefault"].ParseString(); foreach (string[] item in childData) { coursepack.PackageIncludedItems.Add( new PackageIncludedItem { CoursePackageId = coursepack.CoursePackageId, DK = item[0], UK = item[1], Included = item[2].ToBoolean(defaultData: true), SortingOrder = item[3].ToInt(), CreatedBy = coursepack.CreatedBy, CreatedDate = coursepack.CreatedDate, LastModified = coursepack.LastModified, LastModifiedBy = coursepack.LastModifiedBy }); } DKBSDbContext.CoursePackage.Add(coursepack); DKBSDbContext.SaveChanges(); log.Info($"Service katalog process completed [Id]:{oItem.GetId()}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Error:Service katalog [Id]:{oItem.GetId().ToString()}", ex); } } } catch (Exception ex) { ErrorCount += 1; log.Error($"Error:Unable to pull Service katalog.", ex); } log.Info($"Total ErrorCount:{ErrorCount}"); }
public void InsertData() { try { List oListData = ClientContext.Web.Lists.GetByTitle("Centret_i_tal"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); ClientContext.Load(oListDataItem); ClientContext.ExecuteQuery(); var contentStatusId = Extension.GetApprovedConentStatusId(DKBSDbContext); foreach (ListItem oItem in oListDataItem) { try { PartnerCenterInfo cinfo = new PartnerCenterInfo(); var partnerName = oItem["Title"].ToSharepointString(); if (string.IsNullOrWhiteSpace(partnerName)) { ErrorCount += 1; log.Error($"Partner center info partner name is empty. for Id : {oItem.GetId()}"); continue; } var partners = DKBSDbContext.CRMPartner.Where(p => p.PartnerName.Trim().ToLower() == partnerName.Trim().ToLower()); if (partners == null || partners.Count() == 0) { ErrorCount += 1; log.Error($"Partner center info partner not found for Id : {oItem.GetId()}"); continue; } if (partners.Count() > 1) { ErrorCount += 1; log.Error($"Partner center info partner name repeated more than oncee. for Id : {oItem.GetId()} partner name:{partners.First().PartnerName}"); continue; } log.Info($"Partner center info process started.{partners.First().PartnerName} and Id : {oItem.GetId()}"); cinfo.CRMPartnerId = partners.First().CRMPartnerId; cinfo.ContentStatusId = contentStatusId; cinfo.AgreementForEmployees = oItem["AgreementForEmployees"].ToBoolean(); cinfo.AirCondition = oItem["AirCon"].ToBoolean(); cinfo.AirportDistance = oItem["DistanceToAirport"].ToFloat(); cinfo.Auditoriums = oItem["NumberOfAuditoriums"].ToInt(); cinfo.Bar = oItem["Bar"].ToBoolean(); cinfo.Casino = oItem["Casino"].ToBoolean(); cinfo.Chamber = oItem["Plenum"].ToInt(); cinfo.CookingSchool = oItem["CookingSchool"].ToBoolean(); cinfo.CreatedBy = oItem.GetAuthor(); cinfo.CreatedDate = oItem.GetCreateDate(); cinfo.DiningArea = oItem["DinningArea"].ToInt(); cinfo.DistanceToAddtiionalAccommodation = oItem["DistanceToAdditionalAccomodation"].ToFloat(); cinfo.DistanceToBus = oItem["DistanceToBusStop"].ToFloat(); cinfo.DistanceToFreeParking = oItem["DistanceToTheFreeParking"].ToFloat(); cinfo.DistanceToMotorway = oItem["DistanceToMotorway"].ToFloat(); cinfo.DistanceToPayParking = oItem["DistanceToThePaidParking"].ToFloat(); cinfo.EnvironmentalCertificate = oItem["EnvironmentalCertificate"].ToBoolean(); cinfo.FitnessRoom = oItem["FitnessRoom"].ToBoolean(); cinfo.Golf = oItem["Golf"].ToBoolean(); cinfo.GreenArea = oItem["GreenArea"].ToBoolean(); cinfo.GroupRooms = oItem["TeamRoom"].ToInt(); cinfo.Handicapfriendly = oItem["HandicapFriendly"].ToBoolean(); cinfo.HandicapRooms = oItem["HandicapRooms"].ToInt(); cinfo.LastModified = oItem.GetModifiedDate(); cinfo.LastModifiedBY = oItem.GetEditor(); cinfo.Lounge = oItem["Lounge"].ToBoolean(); cinfo.MaxAccommodation = oItem["MaximumAccommodations"].ToSharepointString(); cinfo.MaxDiningPlacesInRestaurant = oItem["AreaRestaurant"].ToInt(); cinfo.MaxDiningPlacesInRoom = oItem["PrivateRoom"].ToInt(); cinfo.MaximumNumberOfVisitors = oItem["MaxDiners"].ToInt(); cinfo.MaxSpaceAtRowOfChairs = oItem["MaximumTableSeats"].ToInt(); cinfo.MaxspaceAtTables = oItem["MaximumTableSeats"].ToInt(); cinfo.MaxSpaceInAuditorium = oItem["MaximumSeatsInAuditorium"].ToInt(); cinfo.MinParticipants = oItem["MinimumAttendees"].ToInt(); cinfo.NoOfRooms = oItem["NumberOfRooms"].ToInt(); cinfo.NumberOfDoubleRooms = oItem["DoubleRooms"].ToInt(); cinfo.NumberOfFreeParkingSpaces = oItem["NumberOfFreeParkingSpace"].ToInt(); cinfo.NumberOfParkingSpaces = oItem["NumberOfPaidParkingSpace"].ToInt(); cinfo.NumberOfSingleRooms = oItem["SingleRooms"].ToInt(); cinfo.Pool = oItem["Pool"].ToBoolean(); cinfo.RegionsAgreement = oItem["RegionAgreement"].ToBoolean(); cinfo.Spa = oItem["Spa"].ToBoolean(); cinfo.StateAgreement = oItem["StateAgreement"].ToBoolean(); cinfo.StationDdistance = oItem["DistanceToTrainStation"].ToFloat(); cinfo.Suite = oItem["Suite"].ToInt(); cinfo.TotalRooms = oItem["TotalNumberOfRooms"].ToInt(); cinfo.SharepointId = oItem.GetId(); DKBSDbContext.Add(cinfo); DKBSDbContext.SaveChanges(); log.Info($"Partner center info process completed.{partners.First().PartnerName} and Id : {oItem.GetId()}"); } catch (Exception ex) { ErrorCount += 1; log.Error($"Partner center info Error. Id : {oItem.GetId()}", ex); } } } catch (Exception ex) { ErrorCount += 1; log.Error($"Unble to pull Partner center info", ex); } log.Info($"Total ErrorCount:{ErrorCount}"); }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.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(); foreach (ListItem oListItem in collListItem) { var hyperLink = ((SP.FieldUrlValue)(oListItem["CISite"])); if (hyperLink != null) { Console.WriteLine("ID: {0} \nTitle: {1} \nSite: {2} \nSiteUrl: {3} ", oListItem.Id, oListItem["Title"], oListItem["CISite"], oListItem["CISiteShortUrl"]); var hLink = ((SP.FieldUrlValue)(oListItem["CISite"])).Url; Console.WriteLine(hLink); ClientContext Context = new ClientContext(hLink); Context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; Context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("CRM Automation", "9LEkTny4"); Context.ExecuteQuery(); SP.List oListData = Context.Web.Lists.GetByTitle("Centerbeskrivelse"); camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>"; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); Context.Load(oListDataItem); Context.ExecuteQuery(); foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nDescription: {1} \nLanguageType:{2} \nRooms:{3}", oItem["ID"], oItem["Description"], oItem["LanguageType"], oItem["Rooms"]); Console.WriteLine("TraficConnections: {0} \nCapacity: {1} \nFacilities:{2} \nActivities:{3}", oItem["TraficConnections"], oItem["Capacity"], oItem["Facilities"], oItem["Activities"]); Console.WriteLine("TextOffer: {0} \nFurtherIncluded: {1}", oItem["TextOffer"], oItem["FurtherIncluded"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); PartnerCenterDescription partnerCenterDescription = new PartnerCenterDescription(); // partnerCenterDescription.CRMPartnerId = 1;//oListItem.Id partnerCenterDescription.CRMPartnerId = oListItem.Id; // partnerCenterDescription.ContentStatusId = 2;//Approved if (oItem["Rooms"] != null) { partnerCenterDescription.Rooms = oItem["Rooms"].ToString(); } if (oItem["Capacity"] != null) { partnerCenterDescription.Capacity = oItem["Capacity"].ToString(); } if (oItem["Facilities"] != null) { partnerCenterDescription.Facilities = oItem["Facilities"].ToString(); } if (oItem["Activities"] != null) { partnerCenterDescription.Activities = oItem["Activities"].ToString(); } if (oItem["TextOffer"] != null) { partnerCenterDescription.TextforQuotationforEmail = oItem["TextOffer"].ToString(); } if (oItem["TraficConnections"] != null) { partnerCenterDescription.Transportation = oItem["TraficConnections"].ToString(); } if (oItem["Description"] != null) { partnerCenterDescription.Description = oItem["Description"].ToString(); } if (oItem["ID"] != null) { partnerCenterDescription.PartnerCenterDescriptionSpId = oItem["ID"].ToString(); } if (oItem["FurtherIncluded"] != null) { partnerCenterDescription.AdditionalIncluded = oItem["FurtherIncluded"].ToString(); } if (oItem["LanguageType"] != null) { partnerCenterDescription.Language = oItem["LanguageType"].ToString(); } if (((SP.FieldUserValue)(oItem["Author"])).LookupValue != null) { partnerCenterDescription.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; } if (oItem["Created"] != null) { partnerCenterDescription.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); } if (((SP.FieldUserValue)(oItem["Editor"])).LookupValue != null) { partnerCenterDescription.LastModifiedBY = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue; } if (oItem["Modified"] != null) { partnerCenterDescription.LastModified = Convert.ToDateTime(oItem["Modified"].ToString()); } partnerCenterDescription.ContentStatusId = 1; dbContext.Add(partnerCenterDescription); dbContext.SaveChanges(); } } } } catch (Exception) { throw; } }
public void InsertData(ClientContext clientContext, DKBSDbContext dbContext) { try { Console.WriteLine(" Successfully Connected"); SP.List oListData = clientContext.Web.Lists.GetByTitle("Service request conversation items"); ListItemCollectionPosition position = null; var page = 1; do { CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View Scope='Recursive'><Query></Query><RowLimit>5000</RowLimit></View>"; camlQuery.ListItemCollectionPosition = position; ListItemCollection oListDataItem = oListData.GetItems(camlQuery); clientContext.Load(oListDataItem); clientContext.ExecuteQuery(); position = oListDataItem.ListItemCollectionPosition; foreach (ListItem oItem in oListDataItem) { Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]); Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue); Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue); Console.WriteLine(oItem["Created"].ToString()); Console.WriteLine(oItem["Modified"].ToString()); Console.WriteLine(oItem["Message"]); Console.WriteLine(oItem["Sender"]); Console.WriteLine(oItem["CcAdresses"]); Console.WriteLine(oItem["MessageId"]); if (oItem["RelatedServiceRequest"] != null) { Console.WriteLine(oItem["RelatedServiceRequest"]); var childIdField = oItem["RelatedServiceRequest"] as FieldLookupValue[]; if (childIdField != null) { foreach (var lookupValue in childIdField) { var childId_Value = lookupValue.LookupValue; var childId_Id = lookupValue.LookupId; Console.WriteLine("LookupID: " + childId_Id.ToString()); Console.WriteLine("LookupValue: " + childId_Value.ToString()); } } } EmailConversation emailConversation = new EmailConversation(); emailConversation.BookingId = 7; //hardcode if (oItem["MessageId"] != null) { emailConversation.MessageId = Convert.ToInt32(oItem["MessageId"]); } if (oItem["Message"] != null) { emailConversation.Message = oItem["Message"].ToString(); } emailConversation.EmailTitle = oItem["Title"].ToString(); if (oItem["Sender"] != null) { emailConversation.Sender = oItem["Sender"].ToString(); } if (oItem["CcAdresses"] != null) { emailConversation.CCAddress = oItem["CcAdresses"].ToString(); } if (oItem["To"] != null) { emailConversation.To = oItem["To"].ToString(); } if (oItem["ID"] != null) { emailConversation.SharepointId = Convert.ToInt32(oItem["ID"]); } emailConversation.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue; emailConversation.CreatedDate = Convert.ToDateTime(oItem["Created"].ToString()); dbContext.Add(emailConversation); dbContext.SaveChanges(); } page++; }while (position != null); } catch (Exception) { throw; } }