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}");
 }
Пример #2
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("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;
            }
        }
Пример #4
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}");
        }
Пример #6
0
        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;
            }
        }
Пример #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;
            }
        }
Пример #8
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}");
        }
Пример #9
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;
            }
        }
Пример #10
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;
            }
        }
Пример #11
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;
            }
        }
Пример #12
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;
            }
        }
Пример #13
0
        public void InsertData(ClientContext clientContext, DKBSDbContext dbContext)
        {
            try
            {
                Console.WriteLine(" Successfully Connected");

                SP.List   oListData = clientContext.Web.Lists.GetByTitle("Service katalog");
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query></View>";
                ListItemCollection oListDataItem   = oListData.GetItems(camlQuery);
                SharedFunctions    sharedFunctions = new SharedFunctions();

                clientContext.Load(oListDataItem);

                clientContext.ExecuteQuery();

                foreach (ListItem oItem in oListDataItem)
                {
                    Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]);
                    Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue);
                    Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue);
                    Console.WriteLine(oItem["Created"].ToString());
                    Console.WriteLine(oItem["Modified"].ToString());
                    Console.WriteLine(oItem["KursuspakkeUK"]);
                    Console.WriteLine(oItem["Offered"]);
                    Console.WriteLine(oItem["Price"]);
                    Console.WriteLine(oItem["KursuspakkeID"]);
                    Console.WriteLine(oItem["IncludedInPriceDefault"]);
                    Console.WriteLine(oItem["IncludedInPriceAdditional"]);
                    Console.WriteLine(oItem["OptionalPurchases"]);
                    var coursepack = new CoursePackage();
                    coursepack.CoursePackageName = oItem["Title"].ToString();
                    coursepack.CreatedDate       = Convert.ToDateTime(oItem["Created"].ToString());
                    coursepack.LastModified      = Convert.ToDateTime(oItem["Modified"].ToString());
                    //coursepack.Offered = oItem["Offered"].ToString();
                    coursepack.Price = Convert.ToDecimal(oItem["Price"]);
                    //coursepack.CreatedBy = oItem["Author"].ToString();
                    // coursepack.LastModifiedBy = oItem["Editor"].ToString();
                    coursepack.CreatedBy      = (((SP.FieldUserValue)(oItem["Author"])).LookupValue).ToString();
                    coursepack.LastModifiedBy = (((SP.FieldUserValue)(oItem["Editor"])).LookupValue).ToString();
                    ArrayList parsedData = new ArrayList();
                    coursepack.PackageIncludedItems = new List <PackageIncludedItem>();
                    if (oItem["IncludedInPriceDefault"] != null)
                    {
                        parsedData = sharedFunctions.ParseFunction(oItem["IncludedInPriceDefault"].ToString());
                        if (parsedData.Count > 0)
                        {
                            foreach (List <String> pacakageData in parsedData)
                            {
                                Console.WriteLine(pacakageData);
                                Array pacakageDataArray = pacakageData.ToArray();
                                coursepack.PackageIncludedItems.Add(new PackageIncludedItem()
                                {
                                    CoursePackageId = Convert.ToInt32(oItem["ID"]), DK = pacakageData[0].ToString()
                                });
                            }
                        }
                    }
                    else
                    {
                        coursepack.PackageIncludedItems.Add(new PackageIncludedItem()
                        {
                            CoursePackageId = Convert.ToInt32(oItem["ID"])
                        });
                    }
                    dbContext.Add(coursepack);
                    dbContext.SaveChanges();
                    //if (oItem["KursuspakkeTypen"] != null)
                    //{
                    //    Console.WriteLine(oItem["KursuspakkeTypen"]);
                    //    var childIdField = oItem["KursuspakkeTypen"] as FieldLookupValue[];

                    //    if (childIdField != null)
                    //    {
                    //        foreach (var lookupValue in childIdField)
                    //        {
                    //            var childId_Value = lookupValue.LookupValue;
                    //            var childId_Id = lookupValue.LookupId;

                    //            Console.WriteLine("LookupID: " + childId_Id.ToString());
                    //            Console.WriteLine("LookupValue: " + childId_Value.ToString());
                    //        }
                    //    }
                    //}
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public 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;
            }
        }