mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-08 10:31:19 +00:00
MC Add location service
This commit is contained in:
parent
3f8a519adb
commit
fb21254805
@ -2,10 +2,48 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
|
||||||
namespace MyCore.Services.MyControlPanel
|
namespace MyCore.Services.MyControlPanel
|
||||||
{
|
{
|
||||||
public class LocationService
|
public class LocationService
|
||||||
{
|
{
|
||||||
|
private readonly IMongoCollection<Location> _Locations;
|
||||||
|
|
||||||
|
public LocationService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_Locations = database.GetCollection<Location>("Locations");
|
||||||
|
}
|
||||||
|
public List<Location> GetLocations()
|
||||||
|
{
|
||||||
|
return _Locations.Find(l => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location GetLocationById(string id)
|
||||||
|
{
|
||||||
|
return _Locations.Find<Location>(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user