public void AddServerInfo(Classes.Server server, string endpoint) { try { using (var database = new LiteDatabase(Program.databasePath)) { var serversCollection = database.GetCollection <Classes.Server>("servers"); serversCollection.EnsureIndex(x => x.Endpoint); Classes.Server.AddServerInfo(serversCollection, server, endpoint); } } catch (Exception exc) { Program.log.Error(exc, "An error occured for HTTP PUT AddServerInfo"); throw exc; } }
public static void AddServerInfo(LiteCollection <Classes.Server> serversCollection, Classes.Server server, string endpoint) { server.Endpoint = endpoint; if (serversCollection.FindOne(x => x.Endpoint == endpoint) == null) { serversCollection.Insert(server); } else { server.Id = serversCollection.FindOne(x => x.Endpoint == endpoint).Id; serversCollection.Update(server); } }