public void InsertData()
 {
     try
     {
         List      oListData = ClientContext.Web.Lists.GetByTitle("Centrets lokaler i tal");
         CamlQuery camlQuery = new CamlQuery();
         camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='MaxPeopleAtTable' /><FieldRef Name='MaxPeopleAtUTable' /><FieldRef Name='MaxPeopleAtSchoolBoard' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='MaxPeopleByIsland' /><FieldRef Name='MaxPeopleInOneRoom' /><FieldRef Name='DivideRoom' /><FieldRef Name='Remarks' /><FieldRef Name='SiteCIIDLookup' /></ViewFields></View>";
         ListItemCollection oListDataItem = oListData.GetItems(camlQuery);
         ClientContext.Load(oListDataItem);
         ClientContext.ExecuteQuery();
         var contentStatusId = Extension.GetApprovedConentStatusId(DKBSDbContext);
         foreach (ListItem oItem in oListDataItem)
         {
             CRMPartner partner = DKBSDbContext.CRMPartner.FirstOrDefault(p => p.AccountId == oItem.GetLookupId("SiteCIIDLookup"));
             if (partner == null)
             {
                 ErrorCount += 1;
                 log.Error($"Partner not found SharepointId:{oItem.Id}");
                 continue;
             }
             try
             {
                 log.Info($"Partner room info started. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}");
                 PartnerCenterRoomInfo pRoom = new PartnerCenterRoomInfo()
                 {
                     RoomName                 = oItem["Title"].ToSharepointString(),
                     SharepointId             = oItem.GetId(),
                     MaxPersonsAtMeetingTable = oItem["MaxPeopleAtTable"].ToInt(),
                     MaxPersonsAtRowOfChairs  = oItem["MaxPeopleInOneRoom"].ToInt(),
                     MaxPersonsAtSchoolTable  = oItem["MaxPeopleAtSchoolBoard"].ToInt(),
                     MaxPersonsAtUTable       = oItem["MaxPeopleAtUTable"].ToInt(),
                     MaxPersonsAtIslands      = oItem["MaxPeopleByIsland"].ToInt(),
                     IsRoomdividetosmallroom  = oItem["DivideRoom"].ToBoolean(),
                     Remark          = oItem["Remarks"].ToSharepointString(),
                     CreatedDate     = oItem.GetCreateDate(),
                     LastModifiedBY  = oItem.GetEditor(),
                     CreatedBy       = oItem.GetAuthor(),
                     LastModified    = oItem.GetModifiedDate(),
                     ContentStatusId = contentStatusId,
                     CRMPartnerId    = partner.CRMPartnerId
                 };
                 DKBSDbContext.Add(pRoom);
                 DKBSDbContext.SaveChanges();
                 log.Info($"Partner room info completed. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}");
             }
             catch (Exception ex)
             {
                 ErrorCount += 1;
                 log.Error($"Partner room info unable to process. Partner Id: {partner.AccountId} SharepointId:{oItem.Id}", ex);
             }
         }
     }
     catch (Exception)
     {
         log.Error($"Unable to load Centrets lokaler i tal");
     }
     log.Info($"Total ErrorCount:{ErrorCount}");
 }
Example #2
0
        public ActionResult PartnerCenterRoomInfo([FromBody] PartnerCenterRoomInfoDTO partnerCenterRoomInfoDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (partnerCenterRoomInfoDTO == null)
            {
                return(BadRequest());
            }

            var checkPartnerCenterRoomInfoIdinDb = _choiceRepoistory.GetPartnerCenterRoomInfo().Find(c => c.PartnerCenterRoomInfoId == partnerCenterRoomInfoDTO.PartnerCenterRoomInfoId);

            if (checkPartnerCenterRoomInfoIdinDb != null)
            {
                return(BadRequest());
            }

            PartnerCenterRoomInfo newlyCreatedPartnerCenterRoomInfo = new PartnerCenterRoomInfo()
            {
                PartnerCenterRoomInfoId  = partnerCenterRoomInfoDTO.PartnerCenterRoomInfoId,
                CRMPartnerId             = partnerCenterRoomInfoDTO.CRMPartnerId,
                MaxPersonsAtMeetingTable = partnerCenterRoomInfoDTO.MaxPersonsAtMeetingTable,
                MaxPersonsAtSchoolTable  = partnerCenterRoomInfoDTO.MaxPersonsAtSchoolTable,
                MaxPersonsAtRowOfChairs  = partnerCenterRoomInfoDTO.MaxPersonsAtRowOfChairs,
                MaxPersonsAtIslands      = partnerCenterRoomInfoDTO.MaxPersonsAtIslands,
                MaxPersonsAtUTable       = partnerCenterRoomInfoDTO.MaxPersonsAtUTable,
                RoomName = partnerCenterRoomInfoDTO.RoomName,
                IsRoomdividetosmallroom = partnerCenterRoomInfoDTO.IsRoomdividetosmallroom,
                Remark         = partnerCenterRoomInfoDTO.Remark,
                CreatedDate    = partnerCenterRoomInfoDTO.CreatedDate,
                CreatedBy      = partnerCenterRoomInfoDTO.CreatedBy,
                LastModified   = partnerCenterRoomInfoDTO.LastModified,
                LastModifiedBY = partnerCenterRoomInfoDTO.LastModifiedBY
            };

            _choiceRepoistory.SetpartnerCenterRoomInfo(newlyCreatedPartnerCenterRoomInfo);
            _choiceRepoistory.Complete();
            return(CreatedAtRoute("GetByPartnerCenterRoomInfo", new { newlyCreatedPartnerCenterRoomInfo.PartnerCenterRoomInfoId }, newlyCreatedPartnerCenterRoomInfo));
        }
        public void InsertData(ClientContext clientContext, DKBSDbContext dbContext)
        {
            try
            {
                Console.WriteLine(" Successfully Connected");

                SP.List   oListData = clientContext.Web.Lists.GetByTitle("Centrets lokaler i tal");
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='MaxPeopleAtTable' /><FieldRef Name='MaxPeopleAtUTable' /><FieldRef Name='MaxPeopleAtSchoolBoard' /><FieldRef Name='Created' /><FieldRef Name='Modified' /><FieldRef Name='MaxPeopleByIsland' /><FieldRef Name='MaxPeopleInOneRoom' /><FieldRef Name='DivideRoom' /><FieldRef Name='Remarks' /><FieldRef Name='SiteCIIDLookup' /></ViewFields></View>";
                ListItemCollection oListDataItem = oListData.GetItems(camlQuery);

                clientContext.Load(oListDataItem);

                clientContext.ExecuteQuery();

                foreach (ListItem oItem in oListDataItem)
                {
                    Console.WriteLine("ID: {0} \nTitle: {1}", oItem["ID"], oItem["Title"]);
                    Console.WriteLine(((SP.FieldUserValue)(oItem["Author"])).LookupValue);
                    Console.WriteLine(((SP.FieldUserValue)(oItem["Editor"])).LookupValue);
                    //  Console.WriteLine(((SP.FieldUserValue)(oItem["SiteCIDLookup"])).LookupValue);
                    Console.WriteLine(oItem["Created"].ToString());
                    Console.WriteLine(oItem["Modified"].ToString());
                    Console.WriteLine(oItem["MaxPeopleAtTable"]);
                    Console.WriteLine(oItem["MaxPeopleAtUTable"]);
                    Console.WriteLine(oItem["MaxPeopleAtSchoolBoard"]);
                    Console.WriteLine(oItem["MaxPeopleByIsland"]);
                    Console.WriteLine(oItem["MaxPeopleInOneRoom"]);
                    Console.WriteLine(oItem["DivideRoom"]);
                    Console.WriteLine(oItem["Remarks"]);



                    PartnerCenterRoomInfo partnerCenterRoomInfo = new PartnerCenterRoomInfo();


                    if (oItem["Title"] != null)
                    {
                        partnerCenterRoomInfo.RoomName = oItem["Title"].ToString();
                    }
                    if (oItem["ID"] != null)
                    {
                        partnerCenterRoomInfo.SharepointId = oItem.Id;
                        //  partnerCenterRoomInfo.PartnerCenterRoomInfoSpId = oItem.Id;
                    }
                    if (oItem["MaxPeopleAtTable"] != null)
                    {
                        partnerCenterRoomInfo.MaxPersonsAtMeetingTable = Convert.ToInt32(oItem["MaxPeopleAtTable"]);
                    }
                    if (oItem["MaxPeopleInOneRoom"] != null)
                    {
                        partnerCenterRoomInfo.MaxPersonsAtRowOfChairs = Convert.ToInt32(oItem["MaxPeopleInOneRoom"]);
                    }
                    if (oItem["MaxPeopleAtSchoolBoard"] != null)
                    {
                        partnerCenterRoomInfo.MaxPersonsAtSchoolTable = Convert.ToInt32(oItem["MaxPeopleAtSchoolBoard"]);
                    }
                    if (oItem["MaxPeopleAtUTable"] != null)
                    {
                        partnerCenterRoomInfo.MaxPersonsAtUTable = Convert.ToInt32(oItem["MaxPeopleAtUTable"]);
                    }
                    if (oItem["MaxPeopleByIsland"] != null)
                    {
                        partnerCenterRoomInfo.MaxPersonsAtIslands = Convert.ToInt32(oItem["MaxPeopleByIsland"]);
                    }
                    if (oItem["DivideRoom"] != null && oItem["DivideRoom"].ToString() != "")
                    {
                        partnerCenterRoomInfo.IsRoomdividetosmallroom = Convert.ToBoolean(oItem["DivideRoom"]);
                    }

                    if (oItem["Remarks"] != null)
                    {
                        partnerCenterRoomInfo.Remark = oItem["Remarks"].ToString();
                    }
                    if (oItem["Created"] != null)
                    {
                        partnerCenterRoomInfo.CreatedDate = Convert.ToDateTime(oItem["Created"]);
                    }

                    if (oItem["Editor"] != null)
                    {
                        partnerCenterRoomInfo.LastModifiedBY = ((SP.FieldUserValue)(oItem["Editor"])).LookupValue;
                    }
                    if (oItem["Author"] != null)
                    {
                        partnerCenterRoomInfo.CreatedBy = ((SP.FieldUserValue)(oItem["Author"])).LookupValue;
                    }
                    if (oItem["Modified"] != null)
                    {
                        partnerCenterRoomInfo.LastModified = Convert.ToDateTime(oItem["Modified"]);
                    }

                    //partnerCenterRoomInfo.CRMPartnerId = 1;
                    if (oItem["SiteCIIDLookup"] != null)
                    {
                        Console.WriteLine(oItem["SiteCIIDLookup"]);
                        var childIdField = oItem["SiteCIIDLookup"] as FieldLookupValue;
                        if (childIdField != null)
                        {
                            Console.WriteLine("LookupID: " + childIdField.LookupId.ToString());
                            Console.WriteLine("LookupValue: " + childIdField.LookupValue.ToString());

                            partnerCenterRoomInfo.CRMPartnerId = childIdField.LookupId;
                        }
                    }

                    dbContext.Add(partnerCenterRoomInfo);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
 public void SetpartnerCenterRoomInfo(PartnerCenterRoomInfo partnerCenterRoomInfo)
 {
     _dbContext.PartnerCenterRoomInfo.Add(partnerCenterRoomInfo);
 }