mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
50 lines
1.3 KiB
C#
50 lines
1.3 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 GroupService
|
|
{
|
|
private readonly IMongoCollection<Group> _Groups;
|
|
|
|
public GroupService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
|
var database = client.GetDatabase("MyCoreDb");
|
|
_Groups = database.GetCollection<Group>("Groups");
|
|
}
|
|
public List<Group> GetGroups()
|
|
{
|
|
return _Groups.Find(d => true).ToList();
|
|
}
|
|
|
|
public Group GetGroupById(string id)
|
|
{
|
|
return _Groups.Find<Group>(g => g.Id == id).FirstOrDefault();
|
|
}
|
|
|
|
public Group CreateGroup(Group group)
|
|
{
|
|
_Groups.InsertOne(group);
|
|
return group;
|
|
}
|
|
|
|
public Group Update(string id, Group groupIn)
|
|
{
|
|
_Groups.ReplaceOne(group => group.Id == id, groupIn);
|
|
return groupIn;
|
|
}
|
|
|
|
public void Remove(string id)
|
|
{
|
|
_Groups.DeleteOne(group => group.Id == id);
|
|
}
|
|
}
|
|
}
|