mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
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<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);
|
|
}
|
|
}
|
|
}
|