bitwarden-android/src/App/Services/FolderService.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2016-05-02 09:52:09 +03:00
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Models;
using Bit.App.Models.Data;
namespace Bit.App.Services
{
public class FolderService : Repository<FolderData, int>, IFolderService
{
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 FolderService(
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<Folder>> GetAllAsync()
{
var data = Connection.Table<FolderData>().Where(f => f.UserId == _authService.UserId).Cast<FolderData>();
return Task.FromResult(data.Select(f => new Folder(f)));
2016-05-02 09:52:09 +03:00
}
public async Task SaveAsync(Folder folder)
{
2016-05-03 00:50:16 +03:00
var data = new FolderData(folder, _authService.UserId);
2016-05-02 09:52:09 +03:00
data.RevisionDateTime = DateTime.UtcNow;
if(folder.Id == 0)
{
await CreateAsync(data);
}
else
{
await ReplaceAsync(data);
}
folder.Id = data.Id;
}
}
}