Add "Image" context to add images for the users

This commit is contained in:
Sébastien André
2020-05-26 17:26:04 +02:00
parent 8367927046
commit f21bda7d7b
18 changed files with 250 additions and 10 deletions

View File

@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Linq;
using LiteDB;
using skydiveLogs_api.Data.Interface;
using skydiveLogs_api.Model;
namespace skydiveLogs_api.Data
{
public class ImageRepository : IImageRepository
{
public ImageRepository(IDataProvider dataProvider)
{
_dataProvider = dataProvider;
_col = _dataProvider.CollOfImage;
}
public IEnumerable<Image> GetAll()
{
return _col.FindAll().ToList();
}
public Image GetById(int id)
{
return _col.FindById(new BsonValue(id));
}
public bool Update(Image image)
{
return _col.Update(image);
}
public bool Add(Image newImage)
{
var result = true;
try
{
_col.Insert(newImage);
}
catch
{
result = false;
}
return result;
}
private readonly IDataProvider _dataProvider;
private readonly ILiteCollection<Image> _col;
}
}