public static void RequirementInventoryUpdate(ClientContext context, ReqItemcollection reqItemcollection, SubscriptionItem subscriptionItem, NetworkCredential networkCredential)
        {
            try
            {
                context.Credentials = networkCredential;
                List olistReq     = context.Web.Lists.GetByTitle(CommonVariables.RequirementListTitle);
                var  count        = reqItemcollection.reqitems.Count;
                var  maxChunkSize = 100;
                var  shouldRun    = true;
                var  start        = 0;
                var  chunkSize    = count < maxChunkSize ? count : maxChunkSize;
                var  end          = start + chunkSize < count ? start + chunkSize : count;
                context.RequestTimeout = -1;
                while (shouldRun)
                {
                    shouldRun = end == count ? false : true;
                    for (int i = start; i < end; i++)
                    {
                        ListItem oListItem = olistReq.GetItemById(reqItemcollection.reqitems[i].reqID);
                        oListItem["inventory"]         = reqItemcollection.reqitems[i].invID;
                        oListItem["_ModerationStatus"] = 0; // Approved:0,Denied:1,Pending:2,Draft:3,Shceduled:4
                        oListItem.Update();
                        context.Load(oListItem);
                    }

                    context.ExecuteQuery();
                    start = end;
                    end   = start + chunkSize < count ? start + chunkSize : count;
                }
                subscriptionItem.IsSuccess = 1;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Version conflict"))
                {
                    for (int i = 0; i < noOfAttempts; i++)
                    {
                        Thread.Sleep(1000);
                        Requirement.RequirementInventoryUpdate(context, reqItemcollection, subscriptionItem, networkCredential);
                        if (subscriptionItem.IsSuccess == 1)
                        {
                            break;
                        }
                    }
                }
                Errorlogs.Log(context, new ErrorLogItem
                {
                    ErrorMessage   = ex.Message,
                    MethodName     = "Requirement.RequirementInventoryUpdate",
                    StackTrace     = ex.StackTrace,
                    SubscriptionID = subscriptionItem.ID
                });
            }
        }
        public static void DocumentInventoryUpdate(ClientContext context, int documentID, SubscriptionItem subscriptionItem, NetworkCredential networkCredential, bool isRemoveCall)
        {
            try
            {
                List     olistDocs     = context.Web.Lists.GetByTitle(CommonVariables.DocumentListTitle);
                ListItem oListItem     = olistDocs.GetItemById(documentID);
                string   inventorycoll = GetDocumentInventory(context, oListItem);
                subscriptionItem.DocumentTitle = Convert.ToString(oListItem["Title"]);

                if (!string.IsNullOrWhiteSpace(inventorycoll))
                {
                    if (!inventorycoll.Contains("-" + subscriptionItem.InvID + "-"))
                    {
                        inventorycoll += "-" + subscriptionItem.InvID + "-";
                    }

                    oListItem["inventory"] = inventorycoll;
                }
                else
                {
                    oListItem["inventory"] = "-" + subscriptionItem.InvID + "-";
                }
                oListItem["_ModerationStatus"] = 0;
                oListItem.Update();
                context.Load(oListItem);
                context.ExecuteQuery();
                if (isRemoveCall)
                {
                    RemoveInventoryIdsDocuments(context, oListItem, documentID, olistDocs, "-" + subscriptionItem.InvID + "-", subscriptionItem);
                }

                subscriptionItem.IsSuccess = 1;
            }
            catch (Exception ex)
            {
                Errorlogs.Log(context, new ErrorLogItem
                {
                    ErrorMessage   = ex.Message,
                    MethodName     = "DocumentItem.DocumentInventoryUpdate",
                    StackTrace     = ex.StackTrace,
                    SubscriptionID = subscriptionItem.ID
                });
            }
        }
        public static async Task UpdateClientLogItems(ClientContext parentContext, ClientContext rootcontext, ReqItemcollection reqItemcollection, NetworkCredential networkCredential, SubscriptionItem subscriptionItem)
        {
            try
            {
                string folder_RelativeUrl = "/Lists/ClientLogs/" + subscriptionItem.InvID;

                List olistClientLog = rootcontext.Web.Lists.GetByTitle(CommonVariables.ClientLogListTitle);
                var  count          = reqItemcollection.reqitems.Count;
                var  maxChunkSize   = 100;
                var  shouldRun      = true;
                var  start          = 0;
                var  chunkSize      = count < maxChunkSize ? count : maxChunkSize;
                var  end            = start + chunkSize < count ? start + chunkSize : count;
                rootcontext.RequestTimeout = -1;
                while (shouldRun)
                {
                    shouldRun = end == count ? false : true;
                    for (int i = start; i < end; i++)
                    {
                        string        reqID         = reqItemcollection.reqitems[i].reqID;
                        ClientLogItem clientLogItem = await ReadDataCollection(networkCredential, subscriptionItem.WebApplicationURL, Convert.ToInt32(reqID), subscriptionItem.DocumentID);

                        ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
                        listItemCreationInformation.FolderUrl = folder_RelativeUrl;

                        var listItem = olistClientLog.AddItem(listItemCreationInformation);
                        listItem["Title"]              = "Log entry";
                        listItem["Action"]             = reqItemcollection.reqitems[i].Isselected ? "Add" : "Remove";
                        listItem["Heading1"]           = clientLogItem.heading1;
                        listItem["Heading2"]           = clientLogItem.heading2;
                        listItem["Heading3"]           = clientLogItem.heading3;
                        listItem["Header4"]            = clientLogItem.heading4;
                        listItem["Header5"]            = clientLogItem.heading5;
                        listItem["RequirementType"]    = clientLogItem.requirementType;
                        listItem["ListURL"]            = clientLogItem.listURL;
                        listItem["ItemID"]             = reqID;
                        listItem["ItemURL"]            = clientLogItem.itemURL;
                        listItem["RESTItemProperties"] = clientLogItem.itemRESTURL;
                        listItem["Client"]             = subscriptionItem.InvID;
                        listItem["Note"]         = reqItemcollection.reqitems[i].Isselected ? "" : subscriptionItem.Notes;
                        listItem["Jurisdiction"] = subscriptionItem.Jurisdiction;
                        listItem["Author0"]      = subscriptionItem.DocumentAuthor;
                        listItem["Author"]       = subscriptionItem.CreatedBy;
                        listItem["Editor"]       = subscriptionItem.CreatedBy;
                        listItem["Documentname"] = subscriptionItem.DocumentTitle;

                        listItem.Update();
                        rootcontext.Load(listItem);
                    }

                    rootcontext.ExecuteQuery();
                    start = end;
                    end   = start + chunkSize < count ? start + chunkSize : count;
                }
                subscriptionItem.IsSuccess = 1;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Version conflict"))
                {
                    for (int i = 0; i < noOfAttempts; i++)
                    {
                        Thread.Sleep(1000);
                        await UpdateClientLogItems(parentContext, rootcontext, reqItemcollection, networkCredential, subscriptionItem);

                        if (subscriptionItem.IsSuccess == 1)
                        {
                            break;
                        }
                    }
                }

                Errorlogs.Log(parentContext, new ErrorLogItem
                {
                    ErrorMessage   = ex.Message,
                    MethodName     = "ClientLogFolder.UpdateClientLogItems",
                    StackTrace     = ex.StackTrace,
                    SubscriptionID = subscriptionItem.ID
                });
            }
        }