private void BackgroundThread_DoWork(object sender, DoWorkEventArgs e)
        {
            MongoClient MongoServer;
            List<Collab> total = new List<Collab>();
            do
            {
                List<string> temp = UserAddedContents.Keys.ToList();
                foreach (string key in temp)
                {
                    total.AddRange(UserAddedContents[key]);
                }
            } while (false);

            List<Collab> UserContent = total.FindAll(x => x.MainContent == true);

            List<BsonDocument> NewBson = ConvertToBson(UserContent);

            if (ProjectTabs.ServerConnected)
            {
                MongoServer = ProjectTabs.Mongo;
            }
            else
            {
                MongoServer = new MongoClient("mongodb://192.168.43.179:27017");
            }

            var ProjectDatabase = MongoServer.GetDatabase(_projectName);
            var collabentry = ProjectDatabase.GetCollection<BsonDocument>("UserEntry");

            ReplaceOptions replaceOptions = new ReplaceOptions() { IsUpsert = true };

            foreach (int value in DeletedID)
            {
                try
                {
                    var filter = Builders<BsonDocument>.Filter.Eq("ContentID", value);
                    collabentry.DeleteOne(filter);
                }
                catch { }
            }

            int UserContentIndex = 0;
            foreach (BsonDocument value in NewBson)
            {
                var filter = Builders<BsonDocument>.Filter.Eq("ContentID", UserContent[UserContentIndex].Id);
                collabentry.ReplaceOne(filter, value, replaceOptions);
                UserContentIndex++;
            }

            DatabaseMisc misc = new DatabaseMisc() { ID = 0, LastAllocatedID = identity, LastDeletedList = DeletedID, ProjectStartDate = _startdatevalueMW.ToLongDateString() };
            var GetMisc = ProjectDatabase.GetCollection<DatabaseMisc>("DataBaseMisc");
            GetMisc.ReplaceOne(x => x.ID == 0, misc, replaceOptions);

            e.Result = e.Argument;
        }
        public void LoadContentDatabase(string DatabaseName)
        {
            _projectName = DatabaseName;
            var ProjectDatabase = ProjectTabs.Mongo.GetDatabase(DatabaseName);
            var GetMisc = ProjectDatabase.GetCollection<DatabaseMisc>("DataBaseMisc");
            var filter = Builders<DatabaseMisc>.Filter.Eq("ID", 0);
            var TempList = GetMisc.Find(filter).FirstOrDefault(); 
            DatabaseMisc StartupFile = TempList as DatabaseMisc;
            
            _startdatevalueMW = DateTime.Parse(StartupFile.ProjectStartDate);
            identity = StartupFile.LastAllocatedID;
            DeletedID = StartupFile.LastDeletedList;

            DatePopulate();
            AddColorsToProject();

            var collabentry = ProjectDatabase.GetCollection<BsonDocument>("UserEntry");
            var filter2 = Builders<BsonDocument>.Filter.Empty;
            var TempEntry = collabentry.Find(filter2).ToList();

            UserContent DatabaseInput = new UserContent();

            foreach (var item in TempEntry)
            {
                DatabaseInput.ReturnDiscipline = item["ContentDiscipline"].AsString;
                DatabaseInput.ReturnContent = item["Content"].AsString;
                DatabaseInput.ReturnStartDate = DateTime.Parse(item["ContentStartDate"].AsString);
                DatabaseInput.ReturnEndDate = DateTime.Parse(item["ContentEndDate"].AsString);
                DatabaseInput.ReturnDiscColor = new KeyValuePair<string, System.Windows.Media.SolidColorBrush>(item["ContentColor"].AsString,
                    ProjectColorSelection[item["ContentColor"].AsString]);
                DatabaseInput.MileCheck = item["ContentMilestone"].ToBoolean();

                AddUserContentFromServer(DatabaseInput, item["ContentID"].ToInt32(), item["ContentCompletedState"].ToInt32());
            }

        }