71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Manager.Interfaces.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace Manager.Services
|
|
{
|
|
public class SectionDatabaseService
|
|
{
|
|
private readonly IMongoCollection<Section> _Sections;
|
|
|
|
public SectionDatabaseService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config.GetConnectionString("TabletDbOld"));
|
|
var database = client.GetDatabase("TabletDbOld");
|
|
_Sections = database.GetCollection<Section>("Sections");
|
|
}
|
|
|
|
public List<Section> GetAll()
|
|
{
|
|
return _Sections.Find(s => !s.IsSubSection).ToList();
|
|
}
|
|
|
|
public List<Section> GetAllFromConfiguration(string configurationId)
|
|
{
|
|
return _Sections.Find(s => !s.IsSubSection && s.ConfigurationId == configurationId).ToList();
|
|
}
|
|
|
|
public List<Section> GetAllSubSection(string parentId)
|
|
{
|
|
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
|
}
|
|
|
|
public Section GetById(string id)
|
|
{
|
|
return _Sections.Find<Section>(s => s.Id == id).FirstOrDefault();
|
|
}
|
|
|
|
public bool IsExist(string id)
|
|
{
|
|
return _Sections.Find<Section>(s => s.Id == id).FirstOrDefault() != null ? true : false;
|
|
}
|
|
|
|
public Section Create(Section section)
|
|
{
|
|
_Sections.InsertOne(section);
|
|
return section;
|
|
}
|
|
|
|
public Section Update(string id, Section sectionIn)
|
|
{
|
|
_Sections.ReplaceOne(s => s.Id == id, sectionIn);
|
|
return sectionIn;
|
|
}
|
|
|
|
public void Remove(string id)
|
|
{
|
|
_Sections.DeleteOne(s => s.Id == id);
|
|
}
|
|
|
|
public void DeleteAllFromConfiguration(string configurationId)
|
|
{
|
|
_Sections.DeleteMany(s => s.ConfigurationId == configurationId);
|
|
}
|
|
|
|
}
|
|
}
|