diff --git a/MyCore/Services/MyControlPanel/LocationService.cs b/MyCore/Services/MyControlPanel/LocationService.cs index fc6a81c..d75c8d6 100644 --- a/MyCore/Services/MyControlPanel/LocationService.cs +++ b/MyCore/Services/MyControlPanel/LocationService.cs @@ -2,10 +2,48 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using MyCore.Models; +using Microsoft.Extensions.Configuration; +using MongoDB.Driver; +using MyCore.Models.MyControlPanel; namespace MyCore.Services.MyControlPanel { public class LocationService { + private readonly IMongoCollection _Locations; + + public LocationService(IConfiguration config) + { + var client = new MongoClient(config.GetConnectionString("MyCoreDb")); + var database = client.GetDatabase("MyCoreDb"); + _Locations = database.GetCollection("Locations"); + } + public List GetLocations() + { + return _Locations.Find(l => true).ToList(); + } + + public Location GetLocationById(string id) + { + return _Locations.Find(l => l.Id == id).FirstOrDefault(); + } + + public Location CreateLocation(Location location) + { + _Locations.InsertOne(location); + return location; + } + + public Location Update(string id, Location locationIn) + { + _Locations.ReplaceOne(location => location.Id == id, locationIn); + return locationIn; + } + + public void Remove(string id) + { + _Locations.DeleteOne(location => location.Id == id); + } } }