Add "Image" context to add images for the users
This commit is contained in:
55
Back/skydiveLogs-api.Data/ImageRepository.cs
Normal file
55
Back/skydiveLogs-api.Data/ImageRepository.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,7 @@ namespace skydiveLogs_api.Data.Interface
|
||||
ILiteCollection<Jump> CollOfJump { get; }
|
||||
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
|
||||
ILiteCollection<Image> CollOfImage { get; }
|
||||
}
|
||||
}
|
||||
|
||||
9
Back/skydiveLogs-api.Data/Interface/IImageRepository.cs
Normal file
9
Back/skydiveLogs-api.Data/Interface/IImageRepository.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IImageRepository : IRepository<Image>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ namespace skydiveLogs_api.Data
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
|
||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Gear, "Gear");
|
||||
|
||||
BsonMapper.Global.Entity<Image>().DbRef(x => x.UserId, "User");
|
||||
}
|
||||
|
||||
public ILiteCollection<T> GetCollection<T>()
|
||||
@@ -39,5 +41,7 @@ namespace skydiveLogs_api.Data
|
||||
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
|
||||
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
|
||||
public ILiteCollection<Image> CollOfImage => _db.GetCollection<Image>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.7" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user