Refacto
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using LiteDB;
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
@@ -5,7 +6,7 @@ using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class StatsByYearRepository : IStatsRepository<StatsByYear>
|
||||
public class StatsByYearRepository : IStatsByYearRepository
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
@@ -19,14 +20,17 @@ namespace skydiveLogs_api.Infrastructure
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public int Add(StatsByYear newStats)
|
||||
public int Add(IEnumerable<StatsByYear> newStats)
|
||||
{
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp.AsInt32;
|
||||
foreach (var newStat in newStats)
|
||||
{
|
||||
var tmp = _col.Insert(newStats);
|
||||
result = tmp;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -36,17 +40,26 @@ namespace skydiveLogs_api.Infrastructure
|
||||
return result;
|
||||
}
|
||||
|
||||
public StatsByYear GetAll(User user)
|
||||
public IEnumerable<StatsByYear> GetAll(User user)
|
||||
{
|
||||
return _col.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.SingleOrDefault();
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Update(StatsByYear stats)
|
||||
public bool Update(IEnumerable<StatsByYear> updatedStats, User user)
|
||||
{
|
||||
return _col.Update(stats);
|
||||
Delete(user);
|
||||
var tmp = Add(updatedStats);
|
||||
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
public bool Delete(User user)
|
||||
{
|
||||
var tmp = _col.DeleteMany(s => s.User.Id == user.Id);
|
||||
return tmp != 0;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
Reference in New Issue
Block a user