Example #1
0
        static void Main(string[] args)
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            BasicConfigurator.Configure(hierarchy);
            ILog log = LogManager.GetLogger(typeof(Program));

            log.Info("Documents upload started.");
            log.Info("Documents upload started.");

            var dbContext = new DKBSDbContext(new DbContextOptions <DKBSDbContext>());
            //BookingService obj = new BookingService();
            //obj.InsertData(SharepointService.ClientContext, dbContext);
            //  CoursePackageService obj = new CoursePackageService();
            // EmailTemplateService obj = new EmailTemplateService();
            // PartnerCoursePackageService obj = new PartnerCoursePackageService();
            //  partnerInspirationCategoriesDKService obj = new partnerInspirationCategoriesDKService();
            //  partnerInspirationCategoriesUKService obj = new partnerInspirationCategoriesUKService();
            // partnerCenterDescriptionService obj = new partnerCenterDescriptionService();
            //   PartnerCenterRoomInfoService obj = new PartnerCenterRoomInfoService();// problems with IsRoomDivided
            PartnerCenterInfoService obj = new PartnerCenterInfoService();

            // InternalCommentsService obj = new InternalCommentsService();
            // EmailConversationService obj = new EmailConversationService();
            // ChatCommunicationService obj = new ChatCommunicationService();
            // ProvisionService obj = new ProvisionService();
            //ProcedureService obj = new ProcedureService();
            // var dbContext = new DKBSDbContext(new DbContextOptions<DKBSDbContext>());
            //var regions = dbContext.Region.ToList();
            //dbContext.Region.Add(new Domain.Region { Name = "Test Region" });
            //dbContext.SaveChanges();
            //var regions1 = dbContext.Region.ToList();
            obj.InsertData(SharepointService.ClientContext, dbContext);
        }
 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}");
 }
Example #3
0
        public MigrationBase()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Environment.CurrentDirectory)
                          .AddJsonFile($"appsettings.development.json", optional: true);

            this.Configuration = builder.Build();
            DKBSDbContext      = new DKBSDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <DKBSDbContext>());
            ClientContext      = GetClientContext();
        }
Example #4
0
        //private IAzureStorageService _azureStorageService;
        //private string _picturesContainerName;

        public ChoiceRepository(DKBSDbContext dbContext, IMapper mapper, IUnitOfWork unitOfWork, IAzureStorageHelper azureStorageHelper)
        {
            //_configuration = configuration;
            _dbContext  = dbContext;
            _mapper     = mapper;
            _unitOfWork = unitOfWork;
            //_azureStorageService = azureStorageService;
            _azureStorageHelper = azureStorageHelper;
            //_picturesContainerName = _configuration["AzureStorage:PicturesContainerName"];
        }
Example #5
0
 public UnitOfWork(DKBSDbContext context)
 {
     _context = context;
     CoursePackageRepository        = new CoursePackageRepository(_context);
     PartnerCoursePackageRepository = new PartnerCoursePackageRepository(_context);
     BookingRepository                        = new BookingRepository(_context);
     ProcedureRepository                      = new ProcedureRepository(_context);
     PartnerInfoPubFacingRepository           = new PartnerInfoPubFacingRepository(_context);
     WPartnerProvisionRepository              = new WPartnerProvisionRepository(_context);
     WPartnerAlternativeServiceRepository     = new WPartnerAlternativeServiceRepository(_context);
     WPartnerBookingArrangementTypeRepository = new WPartnerArrangementTypeRepository(_context);
     WPartnerRoomRepository                   = new WPartnerRoomRepostory(_context);
 }
Example #6
0
        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);
        }
Example #7
0
        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;
            }
        }
Example #8
0
        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;
            }
        }
Example #9
0
        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}");
        }
Example #10
0
        public void InsertData(ClientContext clientContext, DKBSDbContext dbContext)
        {
            // sample msg remove later
            log.Info("BookingService upload started.");
            log.Error("BookingService err started.");


            try
            {
                Console.WriteLine(" Successfully Connected");

                List oList = clientContext.Web.Lists.GetByTitle("Bookinger");
                ContentTypeCollection ctColl = oList.ContentTypes;
                clientContext.Load(ctColl);
                clientContext.ExecuteQuery();
                foreach (ContentType ct in ctColl)
                {
                    if (ct.Name == "Bookinger" || ct.Name == "Gamle sager")
                    {
                        Console.WriteLine(ct.Name);
                        Console.WriteLine("---Please wait while list item is displaying.---");
                        //                   try
                        //                 {
                        {
                            string contentTypeName = ct.Name;
                            ListItemCollectionPosition position = null;
                            var page = 1;
                            do
                            {
                                var query = new CamlQuery()
                                {
                                    ViewXml = String.Format("<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>{0}</Value></Eq></Where></Query><RowLimit>300</RowLimit></View>", contentTypeName)
                                };
                                query.ListItemCollectionPosition = position;
                                ListItemCollection collListItem = oList.GetItems(query);
                                clientContext.Load(collListItem);
                                clientContext.ExecuteQuery();
                                position = collListItem.ListItemCollectionPosition;
                                Console.WriteLine(position);
                                foreach (ListItem oListItem in collListItem)
                                {
                                    Console.WriteLine("ID: {0} \nTitle: {1} ", oListItem.Id, oListItem["Title"]);
                                    //Console.WriteLine(((SP.FieldUserValue)(oListItem["Author"])).LookupValue);
                                    //Console.WriteLine(((SP.FieldUserValue)(oListItem["Editor"])).LookupValue);
                                    Console.WriteLine(oListItem["Created"].ToString());
                                    Console.WriteLine(oListItem["Modified"].ToString());
                                    Console.WriteLine(oListItem["Modified"]);
                                    Console.WriteLine(oListItem["ProcedureInfo"]);

                                    Console.WriteLine(oListItem["ITProcedureReasonComments"]);
                                    Console.WriteLine(oListItem["Flow"]);
                                    Console.WriteLine(oListItem["Parkeret_x0020_indtil"]);
                                    Console.WriteLine(oListItem["OrderView"]);
                                    Console.WriteLine(oListItem["InternalHistoryNote"]);
                                    Console.WriteLine(oListItem["FirstClosingDate"]);
                                    Console.WriteLine(oListItem["MeetingSeries"]);
                                    Console.WriteLine(oListItem["AdditionalSeriesText"]);
                                    Console.WriteLine(oListItem["IsMainSeriesCase"]);
                                    Console.WriteLine(oListItem["MailLanguage"]);

                                    Console.WriteLine(oListItem["Ankomst"]);
                                    Console.WriteLine(oListItem["Afrejse"]);
                                    Console.WriteLine(oListItem["Eksakte_x0020_oplysninger_x0020_"]);
                                    Console.WriteLine(oListItem["Vores_x0020_noter"]);
                                    Console.WriteLine(oListItem["Form_x00e5_l"]);
                                    Console.WriteLine(oListItem["Antal_x0020_deltagere"]);
                                    Console.WriteLine(oListItem["Deltagere"]);
                                    Console.WriteLine(oListItem["Bordopstilling"]);
                                    Console.WriteLine(oListItem["Arrangementtype"]);
                                    Console.WriteLine(oListItem["Antal_x0020_grupperum"]);
                                    Console.WriteLine(oListItem["AlternativtServices"]);

                                    Console.WriteLine(oListItem["Supplerende_x0020__x00f8_nsker_x"]);
                                    Console.WriteLine(oListItem["_x00d8_nsket_x0020_geografisk_x0"]);
                                    Console.WriteLine(oListItem["Responsible"]);
                                    Console.WriteLine(oListItem["Statsaftale"]);
                                    Console.WriteLine(oListItem["Regionsaftale"]);
                                    Console.WriteLine(oListItem["CenterMatching"]);
                                    Console.WriteLine(oListItem["Hvor_x0020_kender_x0020_du_x0020"]);
                                    Console.WriteLine(oListItem["Henvist_x0020_kontaktperson"]);
                                    Console.WriteLine(oListItem["fldEmail"]);
                                    Console.WriteLine(oListItem["fldMobil"]);
                                    Console.WriteLine(oListItem["fldTelefon"]);

                                    Console.WriteLine(oListItem["Henvist_x0020_firma"]);
                                    Console.WriteLine(oListItem["fldAdresse"]);
                                    Console.WriteLine(oListItem["flsBranche"]);
                                    Console.WriteLine(oListItem["Title"]);
                                    Console.WriteLine(oListItem["CanceledStatusDropDown"]);
                                    Console.WriteLine(oListItem["CanceledStatusText"]);
                                    Console.WriteLine(oListItem["Placeringskommentar"]);
                                    Console.WriteLine(oListItem["GreenKeySR"]);
                                    Console.WriteLine(oListItem["AgreementForEmployeesSR"]);
                                    Console.WriteLine(oListItem["DisabledAccessSR"]);

                                    Console.WriteLine(oListItem["BarSR"]);
                                    Console.WriteLine(oListItem["LoungeSR"]);
                                    Console.WriteLine(oListItem["GamesSR"]);
                                    Console.WriteLine(oListItem["SpaSR"]);
                                    Console.WriteLine(oListItem["PoolSR"]);
                                    Console.WriteLine(oListItem["FitnessRoomSR"]);
                                    Console.WriteLine(oListItem["CasinoSR"]);
                                    Console.WriteLine(oListItem["GreenAreaSR"]);
                                    Console.WriteLine(oListItem["AirConSR"]);
                                    Console.WriteLine(oListItem["CookingSchoolSR"]);

                                    Console.WriteLine(oListItem["GolfSR"]);
                                    Console.WriteLine(oListItem["StartDateTime"]);
                                    Console.WriteLine(oListItem["fldStilling"]);
                                    Console.WriteLine(oListItem["fldAfdeling"]);
                                    Console.WriteLine(oListItem["fldHovedorganisation"]);
                                    Console.WriteLine(oListItem["TurnOffNotification"]);
                                    Console.WriteLine(oListItem["SRMID"]);
                                    Console.WriteLine(oListItem["fldNyKunder"]);
                                    Console.WriteLine(oListItem["Read"]);
                                    Console.WriteLine(oListItem["CentretsKommentarerDKBS"]);

                                    Console.WriteLine(oListItem["BogholdersKommentarerDKBS"]);
                                    Console.WriteLine(oListItem["AngivetAfCenterIAltDKBS"]);
                                    Console.WriteLine(oListItem["EstimeretAfDKBSIAlt"]);
                                    Console.WriteLine(oListItem["DifferenceDKBS"]);
                                    Console.WriteLine(oListItem["PlaceringsdatoDKBS"]);
                                    Console.WriteLine(oListItem["AnkomstDKBS"]);
                                    Console.WriteLine(oListItem["DifferenceIDageDKBS"]);
                                    Console.WriteLine(oListItem["ProvisionssatsDKBS"]);
                                    Console.WriteLine(oListItem["ProvisionForArrangementet"]);
                                    Console.WriteLine(oListItem["Henvisninsgssats"]);
                                    Console.WriteLine(oListItem["HenvisningForArrangement"]);
                                    Console.WriteLine(oListItem["LinkToProvisionItem"]);
                                    Console.WriteLine(oListItem["EvalueringDato"]);

                                    CoursePackage obj = new CoursePackage();
                                    dbContext.Add(obj);

                                    if (oListItem["ProvisionLink"] != null)
                                    {
                                        var childIdField = oListItem["ProvisionLink"] 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 (oListItem["HenvisningsProvisionLink"] != null)
                                    {
                                        var childIdField = oListItem["HenvisningsProvisionLink"] 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 (oListItem["RequestRelationParent"] != null)
                                    {
                                        var childIdField = oListItem["RequestRelationParent"] 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 (oListItem["Emails"] != null)
                                    {
                                        var childIdField = oListItem["Emails"] 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 (oListItem["Communications"] != null)
                                    {
                                        var childIdField = oListItem["Communications"] 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 (oListItem["ActionsTaken"] != null)
                                    {
                                        var childIdField = oListItem["ActionsTaken"] 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 (oListItem["ZipMachingFilter"] != null)
                                    {
                                        var childIdField = oListItem["ZipMachingFilter"] 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 (oListItem["Status"] != null)
                                    {
                                        var childIdField = oListItem["Status"] 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 (oListItem["Placering"] != null)
                                    {
                                        var childIdField = oListItem["Placering"] 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 (oListItem["Henvist_x0020_af"] != null)
                                    {
                                        var childIdField = oListItem["Henvist_x0020_af"] 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 (oListItem["PartnerResponsible"] != null)
                                    {
                                        var childIdField = oListItem["PartnerResponsible"] 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 (oListItem["Origin"] != null)
                                    {
                                        var childIdField = oListItem["Origin"] 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 (oListItem["PartnerType"] != null)
                                    {
                                        var childIdField = oListItem["PartnerType"] 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 (oListItem["Customer2"] != null)
                                    {
                                        var childIdField = oListItem["Customer2"] 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 (oListItem["Requester2"] != null)
                                    {
                                        var childIdField = oListItem["Requester2"] 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 (oListItem["CauseOFRemoval"] != null)
                                    {
                                        var childIdField = oListItem["CauseOFRemoval"] 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());
                                            }
                                        }
                                    }
                                }
                                page++;
                            }while (position != null);
                        }
                        //dbContext.SaveChanges();
                        //return true;
                        // }
                        // catch (Exception ex)
                        //{
                        //  Console.WriteLine(ex);
                        // }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        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}");
        }
Example #12
0
        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);
                }
            }
        }
Example #13
0
        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;
            }
        }
Example #14
0
        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;
            }
        }
Example #15
0
        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;
            }
        }
Example #17
0
 public UserManagementRepository(DKBSDbContext dbContext, IMapper mapper, IAzureAdService azureAdService)
 {
     _dbContext      = dbContext;
     _azureAdService = azureAdService;
     _mapper         = mapper;
 }
        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;
            }
        }
Example #19
0
 public DocumentRepository(DKBSDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
Example #20
0
        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()
        {
            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}");
        }
Example #22
0
        public void InsertData(ClientContext clientContext, DKBSDbContext dbContext)
        {
            try
            {
                Console.WriteLine(" Successfully Connected");

                SP.List oListData = clientContext.Web.Lists.GetByTitle("Procedures");
                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["Predecessors"]);
                        Console.WriteLine(oItem["ParentSR"]);
                        Console.WriteLine(oItem["ParentIM"]);
                        Console.WriteLine(oItem["ITProcedures"]);
                        Console.WriteLine(oItem["RelevantOrderDetails"]);
                        Console.WriteLine(oItem["RelevantOrderDetailsStaticHTML"]);
                        Console.WriteLine(oItem["DKBSReopenComment"]);
                        Console.WriteLine(oItem["Arrangementtype"]);
                        Console.WriteLine(oItem["Antal_x0020_grupperum"]);
                        Console.WriteLine(oItem["AlternativtServices"]);
                        if (oItem["Reason"] != null)
                        {
                            Console.WriteLine(oItem["Reason"]);
                            var childIdField = oItem["Reason"] 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["ItProcResponsible"] != null)
                        {
                            Console.WriteLine(oItem["ItProcResponsible"]);
                            var childIdField = oItem["ItProcResponsible"] 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["RelatedCI"] != null)
                        {
                            Console.WriteLine(oItem["RelatedCI"]);
                            var childIdField = oItem["RelatedCI"] 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["Communications"] != null)
                        {
                            Console.WriteLine(oItem["Communications"]);
                            var childIdField = oItem["Communications"] 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["ITProcContactPerson"] != null)
                        {
                            Console.WriteLine(oItem["ITProcContactPerson"]);
                            var childIdField = oItem["ITProcContactPerson"] 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["ITProcFirma"] != null)
                        {
                            Console.WriteLine(oItem["ITProcFirma"]);
                            var childIdField = oItem["ITProcFirma"] 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["CauseOFProcedureRemoval"] != null)
                        {
                            Console.WriteLine(oItem["CauseOFProcedureRemoval"]);
                            var childIdField = oItem["CauseOFProcedureRemoval"] 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());
                                }
                            }
                        }
                        Console.WriteLine(oItem["MainCase"]);
                        Console.WriteLine(oItem["Responsible"]);
                        Console.WriteLine(oItem["CaseType"]);
                        Console.WriteLine(oItem["Status"]);

                        Console.WriteLine(oItem["Outcome"]);
                        Console.WriteLine(oItem["ResponseTime"]);
                        Console.WriteLine(oItem["BeforeReopenCalculatedTime"]);
                        Console.WriteLine(oItem["CloseOrReopenDate"]);
                        Console.WriteLine(oItem["ResponsibleDKBS"]);
                        Console.WriteLine(oItem["ClosedProcedure"]);
                        Console.WriteLine(oItem["ITProcedureStatus"]);
                        Console.WriteLine(oItem["ITProcAnkomst"]);

                        Console.WriteLine(oItem["ITProcAfrejse"]);
                        Console.WriteLine(oItem["NeedReview"]);
                        Console.WriteLine(oItem["Read"]);
                        Console.WriteLine(oItem["SRMID"]);

                        Console.WriteLine(oItem["FirmaBranchekode"]);
                        Console.WriteLine(oItem["ITProcedureCancelReason"]);
                        Console.WriteLine(oItem["PlannedEnd"]);
                        Console.WriteLine(oItem["NotifWithMail"]);
                        Console.WriteLine(oItem["RelevantProcedureOutcome"]);
                        Console.WriteLine(oItem["TurnOffNotification"]);
                        Console.WriteLine(oItem["ExternalPerson"]);
                        Console.WriteLine(oItem["ResponsibleTeam"]);
                        Console.WriteLine(oItem["PlannedStart"]);
                        Console.WriteLine(oItem["UsedInEmailOffer"]);
                        Procedure procedure = new Procedure();
                        procedure.ProcedureTitle        = "";
                        procedure.BookingId             = 7;
                        procedure.ProcedureReviewTypeId = 1;
                        procedure.CRMPartnerId          = 1;
                        // procedure.ChatCommunicationId = 1;
                        procedure.CustomerId = 3;
                        procedure.ContactId  = 1;
                        procedure.ProcedureCancelReasonId = 1;
                        procedure.CauseOfRemovalId        = 1;
                        procedure.ProcedureReplyId        = 1;
                        procedure.UsedInEmailOffer        = Convert.ToBoolean(oItem["UsedInEmailOffer"]);
                        procedure.TurnOffNotification     = Convert.ToBoolean(oItem["TurnOffNotification"]);
                        procedure.ProcedureSharePointId   = Convert.ToInt32(oItem["ID"]);
                        procedure.IndustryCode            = "";
                        procedure.ProcedureStatusId       = 1;
                        //procedure.TotalPrice =
                        procedure.CreatedBy      = ((SP.FieldUserValue)(oItem["Author"])).LookupValue;
                        procedure.LastModifiedBy = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue;
                        procedure.CreatedDate    = Convert.ToDateTime(oItem["Created"].ToString());
                        procedure.LastModified   = Convert.ToDateTime(oItem["Modified"].ToString());
                        //procedure.SystemPrice =
                    }
                    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("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;
            }
        }
Example #24
0
        public void InsertData(ClientContext clientContext, DKBSDbContext dbContext)
        {
            try
            {
                Console.WriteLine(" Successfully Connected");

                SP.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();

                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["TotalNumberOfRooms"]);
                    Console.WriteLine(oItem["SingleRooms"]);
                    Console.WriteLine(oItem["DoubleRooms"]);
                    Console.WriteLine(oItem["Suite"]);
                    // Console.WriteLine(oItem["PrivateRoom"]);

                    Console.WriteLine(oItem["HandicapRooms"]);
                    Console.WriteLine(oItem["DistanceToAdditionalAccomodation"]);
                    //  Console.WriteLine(oItem["Plenum"]);
                    Console.WriteLine(oItem["TeamRoom"]);
                    Console.WriteLine(oItem["DistanceToAirport"]);

                    Console.WriteLine(oItem["DistanceToTrainStation"]);
                    Console.WriteLine(oItem["DistanceToBusStop"]);
                    Console.WriteLine(oItem["DistanceToMotorway"]);
                    Console.WriteLine(oItem["NumberOfFreeParkingSpace"]);
                    Console.WriteLine(oItem["DistanceToTheFreeParking"]);

                    Console.WriteLine(oItem["NumberOfPaidParkingSpace"]);
                    // Console.WriteLine(oItem["DistanceToThePaidParking"]);
                    // Console.WriteLine(oItem["MaxDiners"]);
                    // Console.WriteLine(oItem["MaximumSeatsInAuditorium"]);
                    Console.WriteLine(oItem["GreenArea"]);
                    Console.WriteLine(oItem["AgreementForEmployees"]);
                    Console.WriteLine(oItem["HandicapFriendly"]);
                    Console.WriteLine(oItem["StateAgreement"]);
                    Console.WriteLine(oItem["Bar"]);
                    Console.WriteLine(oItem["Lounge"]);

                    Console.WriteLine(oItem["NumberOfPaidParkingSpace"]);
                    Console.WriteLine(oItem["Spa"]);
                    Console.WriteLine(oItem["Golf"]);
                    Console.WriteLine(oItem["Pool"]);
                    Console.WriteLine(oItem["AirCon"]);
                    Console.WriteLine(oItem["FitnessRoom"]);
                    Console.WriteLine(oItem["CookingSchool"]);
                    Console.WriteLine(oItem["Casino"]);
                    Console.WriteLine(oItem["Lounge"]);

                    Console.WriteLine(oItem["AreaRestaurant"]);
                    Console.WriteLine(oItem["EnvironmentalCertificate"]);
                    Console.WriteLine(oItem["MinimumAttendees"]);
                    Console.WriteLine(oItem["MaximumTableSeats"]);
                    Console.WriteLine(oItem["MaximumAccommodations"]);
                    Console.WriteLine(oItem["MaximumSeats"]);
                    Console.WriteLine(oItem["DinningArea"]);
                    Console.WriteLine(oItem["NumberOfRooms"]);

                    PartnerCenterInfo partnerCenterInfo = new PartnerCenterInfo();

                    if (oItem["AgreementForEmployees"] != null && oItem["AgreementForEmployees"].ToString() != "")
                    {
                        partnerCenterInfo.AgreementForEmployees = Convert.ToBoolean(oItem["AgreementForEmployees"]);
                    }
                    if (oItem["AirCon"] != null && oItem["AirCon"].ToString() != "")
                    {
                        partnerCenterInfo.AirCondition = Convert.ToBoolean(oItem["AirCon"]);
                    }
                    if (oItem["DistanceToAirport"] != null)
                    {
                        partnerCenterInfo.AirportDistance = Convert.ToInt32(oItem["DistanceToAirport"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.Auditoriums = oItem["Title"].ToString();
                    //}
                    if (oItem["Bar"] != null && oItem["Bar"].ToString() != "")
                    {
                        partnerCenterInfo.Bar = Convert.ToBoolean(oItem["Bar"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.BilliardsDartTableTennis = oItem["Title"].ToString();
                    //}
                    if (oItem["Casino"] != null && oItem["Casino"].ToString() != "")
                    {
                        partnerCenterInfo.Casino = Convert.ToBoolean(oItem["Casino"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.Chamber = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.ContentStatusId = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.ContentStatus = oItem["Title"].ToString();
                    //}
                    if (oItem["CookingSchool"] != null && oItem["CookingSchool"].ToString() != "")
                    {
                        partnerCenterInfo.CookingSchool = Convert.ToBoolean(oItem["CookingSchool"]);
                    }
                    if (oItem["Author"] != null)
                    {
                        partnerCenterInfo.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue;
                    }
                    if (oItem["Created"] != null)
                    {
                        partnerCenterInfo.CreatedDate = Convert.ToDateTime(oItem["Created"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.CRMPartnerId = oItem["Title"].ToString();
                    //}

                    if (oItem["DinningArea"] != null)
                    {
                        partnerCenterInfo.DiningArea = Convert.ToInt32(oItem["DinningArea"]);
                    }
                    if (oItem["DistanceToAdditionalAccomodation"] != null)
                    {
                        partnerCenterInfo.DistanceToAddtiionalAccommodation = Convert.ToInt32(oItem["DistanceToAdditionalAccomodation"]);
                    }
                    if (oItem["DistanceToBusStop"] != null)
                    {
                        partnerCenterInfo.DistanceToBus = Convert.ToInt32(oItem["DistanceToBusStop"]);
                    }
                    if (oItem["DistanceToFreeParking"] != null)
                    {
                        partnerCenterInfo.DistanceToFreeParking = Convert.ToInt32(oItem["DistanceToFreeParking"]);
                    }
                    if (oItem["DistanceToMotorway"] != null)
                    {
                        partnerCenterInfo.DistanceToMotorway = Convert.ToInt32(oItem["DistanceToMotorway"]);
                    }
                    if (oItem["DistanceToThePaidParking"] != null)
                    {
                        partnerCenterInfo.DistanceToPayParking = Convert.ToInt32(oItem["DistanceToThePaidParking"]);
                    }
                    if (oItem["EnvironmentalCertificate"] != null && oItem["EnvironmentalCertificate"].ToString() != "")
                    {
                        partnerCenterInfo.EnvironmentalCertificate = Convert.ToBoolean(oItem["EnvironmentalCertificate"]);
                    }
                    if (oItem["FitnessRoom"] != null && oItem["FitnessRoom"].ToString() != "")
                    {
                        partnerCenterInfo.FitnessRoom = Convert.ToBoolean(oItem["FitnessRoom"]);
                    }
                    if (oItem["Golf"] != null && oItem["Golf"].ToString() != "")
                    {
                        partnerCenterInfo.Golf = Convert.ToBoolean(oItem["Golf"]);
                    }
                    if (oItem["GreenArea"] != null && oItem["GreenArea"].ToString() != "")
                    {
                        partnerCenterInfo.GreenArea = Convert.ToBoolean(oItem["GreenArea"]);
                    }
                    if (oItem["TeamRoom"] != null)
                    {
                        partnerCenterInfo.GroupRooms = Convert.ToInt32(oItem["TeamRoom"]);
                    }
                    if (oItem["HandicapFriendly"] != null && oItem["HandicapFriendly"].ToString() != "")
                    {
                        partnerCenterInfo.Handicapfriendly = Convert.ToBoolean(oItem["HandicapFriendly"]);
                    }
                    if (oItem["HandicapRooms"] != null)
                    {
                        partnerCenterInfo.HandicapRooms = Convert.ToInt32(oItem["HandicapRooms"]);
                    }
                    if (oItem["Modified"] != null)
                    {
                        partnerCenterInfo.LastModified = Convert.ToDateTime(oItem["Modified"]);
                    }
                    if (oItem["Editor"] != null)
                    {
                        partnerCenterInfo.LastModifiedBY = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue;
                    }
                    if (oItem["Lounge"] != null && oItem["Lounge"].ToString() != "")
                    {
                        partnerCenterInfo.Lounge = Convert.ToBoolean(oItem["Lounge"]);
                    }
                    if (oItem["MaximumAccommodations"] != null)
                    {
                        partnerCenterInfo.MaxAccommodation = oItem["MaximumAccommodations"].ToString();
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaxDiningPlacesInRestaurant = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaxDiningPlacesInRoom = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaximumNumberOfVisitors = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaxSpaceAtRowOfChairs = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaxspaceAtTables = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.MaxSpaceInAuditorium = oItem["Title"].ToString();
                    // }
                    if (oItem["MinimumAttendees"] != null)
                    {
                        partnerCenterInfo.MinParticipants = Convert.ToInt32(oItem["MinimumAttendees"]);
                    }
                    if (oItem["NumberOfRooms"] != null)
                    {
                        partnerCenterInfo.NoOfRooms = Convert.ToInt32(oItem["NumberOfRooms"]);
                    }
                    if (oItem["DoubleRooms"] != null)
                    {
                        partnerCenterInfo.NumberOfDoubleRooms = Convert.ToInt32(oItem["DoubleRooms"]);
                    }
                    if (oItem["NumberOfFreeParkingSpace"] != null)
                    {
                        partnerCenterInfo.NumberOfFreeParkingSpaces = Convert.ToInt32(oItem["NumberOfFreeParkingSpace"]);
                    }
                    if (oItem["NumberOfPaidParkingSpace"] != null)
                    {
                        partnerCenterInfo.NumberOfParkingSpaces = Convert.ToInt32(oItem["NumberOfPaidParkingSpace"]);
                    }
                    if (oItem["SingleRooms"] != null)
                    {
                        partnerCenterInfo.NumberOfSingleRooms = Convert.ToInt32(oItem["SingleRooms"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.PartnerCenfoInfoSPId = oItem["Title"].ToString();
                    //}
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.PartnerCentInfoSpId = oItem["Title"].ToString();
                    //}
                    if (oItem["Pool"] != null && oItem["Pool"].ToString() != "")
                    {
                        partnerCenterInfo.Pool = Convert.ToBoolean(oItem["Pool"]);
                    }
                    //if (oItem["Title"] != null)
                    //{
                    //    partnerCenterInfo.RegionsAgreement = oItem["Title"].ToString();
                    //}
                    if (oItem["Spa"] != null && oItem["Spa"].ToString() != "")
                    {
                        partnerCenterInfo.Spa = Convert.ToBoolean(oItem["Spa"]);
                    }
                    if (oItem["StateAgreement"] != null && oItem["StateAgreement"].ToString() != "")
                    {
                        partnerCenterInfo.StateAgreement = Convert.ToBoolean(oItem["StateAgreement"]);
                    }
                    if (oItem["DistanceToTrainStation"] != null)
                    {
                        partnerCenterInfo.StationDdistance = Convert.ToInt32(oItem["DistanceToTrainStation"]);
                    }
                    //if (oItem["Suite"] != null && oItem["Suite"].ToString() != "")
                    //{
                    //    partnerCenterInfo.Suite = Convert.ToBoolean(oItem["Suite"]);
                    //}
                    if (oItem["TotalNumberOfRooms"] != null)
                    {
                        partnerCenterInfo.TotalRooms = Convert.ToInt32(oItem["TotalNumberOfRooms"]);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #25
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)
                {
                    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}");
        }
Example #26
0
 public PictureRepository(DKBSDbContext dbContext, IMapper mapper)
 {
     _dbContext = dbContext;
     _mapper    = mapper;
 }
Example #27
0
        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;
            }
        }