2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Bit.App.Abstractions;
|
|
|
|
|
using Bit.App.Models;
|
|
|
|
|
using Bit.App.Models.Data;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Services
|
|
|
|
|
{
|
|
|
|
|
public class SiteService : Repository<SiteData, int>, ISiteService
|
|
|
|
|
{
|
2016-05-03 00:50:16 +03:00
|
|
|
|
private readonly IAuthService _authService;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-03 00:50:16 +03:00
|
|
|
|
public SiteService(
|
|
|
|
|
ISqlService sqlService,
|
|
|
|
|
IAuthService authService)
|
|
|
|
|
: base(sqlService)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-05-03 00:50:16 +03:00
|
|
|
|
_authService = authService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new Task<IEnumerable<Site>> GetAllAsync()
|
|
|
|
|
{
|
|
|
|
|
var data = Connection.Table<SiteData>().Where(f => f.UserId == _authService.UserId).Cast<SiteData>();
|
|
|
|
|
return Task.FromResult(data.Select(s => new Site(s)));
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task SaveAsync(Site site)
|
|
|
|
|
{
|
2016-05-03 00:50:16 +03:00
|
|
|
|
var data = new SiteData(site, _authService.UserId);
|
2016-05-02 09:52:09 +03:00
|
|
|
|
data.RevisionDateTime = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
if(site.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
await CreateAsync(data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await ReplaceAsync(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
site.Id = data.Id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|