DocSpace-client/web/ASC.Web.Core/Mobile/MobileAppInstallRegistrator.cs

42 lines
1.3 KiB
C#
Raw Normal View History

using DbContext = ASC.Core.Common.EF.Context.DbContext;
2019-06-07 08:59:07 +00:00
namespace ASC.Web.Core.Mobile
{
[Scope]
2019-06-07 08:59:07 +00:00
public class MobileAppInstallRegistrator : IMobileAppInstallRegistrator
{
2021-07-15 10:07:47 +00:00
private Lazy<DbContext> LazyDbContext { get; }
private DbContext DbContext { get => LazyDbContext.Value; }
2019-10-10 08:52:21 +00:00
2019-12-12 15:24:47 +00:00
public MobileAppInstallRegistrator(DbContextManager<DbContext> dbContext)
2019-10-10 08:52:21 +00:00
{
2021-07-15 10:07:47 +00:00
LazyDbContext = new Lazy<DbContext>(() => dbContext.Value);
2019-10-10 08:52:21 +00:00
}
2019-06-07 08:59:07 +00:00
public void RegisterInstall(string userEmail, MobileAppType appType)
{
2019-12-12 15:24:47 +00:00
var mai = new MobileAppInstall
{
AppType = (int)appType,
UserEmail = userEmail,
RegisteredOn = DateTime.UtcNow,
LastSign = DateTime.UtcNow
};
DbContext.MobileAppInstall.Add(mai);
DbContext.SaveChanges();
2019-06-07 08:59:07 +00:00
}
public bool IsInstallRegistered(string userEmail, MobileAppType? appType)
{
2019-12-12 15:24:47 +00:00
var q = DbContext.MobileAppInstall.Where(r => r.UserEmail == userEmail);
2019-06-07 08:59:07 +00:00
if (appType.HasValue)
2019-12-12 15:24:47 +00:00
{
q = q.Where(r => r.AppType == (int)appType.Value);
}
2019-06-07 08:59:07 +00:00
2022-01-19 09:51:30 +00:00
return q.Any();
2019-06-07 08:59:07 +00:00
}
}
}