Skip to content

Commit

Permalink
Updated TgStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianMorozov committed Nov 2, 2024
1 parent 005d79c commit 4df3ed1
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 107 deletions.
30 changes: 0 additions & 30 deletions Core/TgStorage/Common/TgEfEntityBase.cs

This file was deleted.

32 changes: 16 additions & 16 deletions Core/TgStorage/Domain/Filters/TgEfFilterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public override TgEfStorageResult<TgEfFilterEntity> Get(TgEfFilterEntity item, b
if (storageResult.IsExists)
return storageResult;
TgEfFilterEntity? itemFind = isNoTracking
? EfContext.Filters.AsNoTracking()
.Where(x => x.FilterType == item.FilterType && x.Name == item.Name)
.SingleOrDefault()
: EfContext.Filters.AsTracking()
.Where(x => x.FilterType == item.FilterType && x.Name == item.Name)
.SingleOrDefault();
? EfContext.Filters
.AsNoTracking()
.SingleOrDefault(x => x.FilterType == item.FilterType && x.Name == item.Name)
: EfContext.Filters
.AsTracking()
.SingleOrDefault(x => x.FilterType == item.FilterType && x.Name == item.Name);
return itemFind is not null
? new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -41,7 +41,7 @@ public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetAsync(TgEfFil
.SingleOrDefaultAsync()
.ConfigureAwait(false);
return itemFind is not null
? new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -53,7 +53,7 @@ public override TgEfStorageResult<TgEfFilterEntity> GetFirst(bool isNoTracking)
: EfContext.Filters.AsTracking()
.FirstOrDefault();
return item is null
? new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -65,7 +65,7 @@ public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetFirstAsync(bo
: await EfContext.Filters.AsTracking()
.FirstOrDefaultAsync().ConfigureAwait(false);
return item is null
? new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfFilterEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -88,7 +88,7 @@ public override TgEfStorageResult<TgEfFilterEntity> GetList(int take, int skip,
: EfContext.Filters.AsTracking()
.ToList();
}
return new TgEfStorageResult<TgEfFilterEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetListAsync(int take, int skip, bool isNoTracking)
Expand All @@ -107,7 +107,7 @@ public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetListAsync(int
? EfContext.Filters.AsNoTracking().ToList()
: EfContext.Filters.AsTracking().ToList();
}
return new TgEfStorageResult<TgEfFilterEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override TgEfStorageResult<TgEfFilterEntity> GetList(int take, int skip, Expression<Func<TgEfFilterEntity, bool>> where, bool isNoTracking)
Expand All @@ -133,7 +133,7 @@ public override TgEfStorageResult<TgEfFilterEntity> GetList(int take, int skip,
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfFilterEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetListAsync(int take, int skip, Expression<Func<TgEfFilterEntity, bool>> where, bool isNoTracking)
Expand All @@ -160,7 +160,7 @@ public override async Task<TgEfStorageResult<TgEfFilterEntity>> GetListAsync(int
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfFilterEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override int GetCount() => EfContext.Filters.AsNoTracking().Count();
Expand Down Expand Up @@ -193,7 +193,7 @@ public override TgEfStorageResult<TgEfFilterEntity> DeleteAll()
Delete(item, isSkipFind: true);
}
}
return new TgEfStorageResult<TgEfFilterEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

public override async Task<TgEfStorageResult<TgEfFilterEntity>> DeleteAllAsync()
Expand All @@ -206,7 +206,7 @@ public override async Task<TgEfStorageResult<TgEfFilterEntity>> DeleteAllAsync()
await DeleteAsync(item, isSkipFind: true).ConfigureAwait(false);
}
}
return new TgEfStorageResult<TgEfFilterEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

#endregion
Expand Down
44 changes: 22 additions & 22 deletions Core/TgStorage/Domain/Proxies/TgEfProxyRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public override TgEfStorageResult<TgEfProxyEntity> Get(TgEfProxyEntity item, boo
if (storageResult.IsExists)
return storageResult;
TgEfProxyEntity? itemFind = isNoTracking
? EfContext.Proxies.AsNoTracking()
.Where(x => x.Type == item.Type && x.HostName == item.HostName && x.Port == item.Port)
.SingleOrDefault()
: EfContext.Proxies.AsTracking()
.Where(x => x.Type == item.Type && x.HostName == item.HostName && x.Port == item.Port)
.SingleOrDefault();
? EfContext.Proxies
.AsNoTracking()
.SingleOrDefault(x => x.Type == item.Type && x.HostName == item.HostName && x.Port == item.Port)
: EfContext.Proxies
.AsTracking()
.SingleOrDefault(x => x.Type == item.Type && x.HostName == item.HostName && x.Port == item.Port);
return itemFind is not null
? new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -41,7 +41,7 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetAsync(TgEfProx
.SingleOrDefaultAsync()
.ConfigureAwait(false);
return itemFind is not null
? new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -51,7 +51,7 @@ public override TgEfStorageResult<TgEfProxyEntity> GetFirst(bool isNoTracking)
? EfContext.Proxies.AsNoTracking().FirstOrDefault()
: EfContext.Proxies.AsTracking().FirstOrDefault();
return item is null
? new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -61,7 +61,7 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetFirstAsync(boo
? await EfContext.Proxies.AsNoTracking().FirstOrDefaultAsync().ConfigureAwait(false)
: await EfContext.Proxies.AsTracking().FirstOrDefaultAsync().ConfigureAwait(false);
return item is null
? new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -80,7 +80,7 @@ public override TgEfStorageResult<TgEfProxyEntity> GetList(int take, int skip, b
? EfContext.Proxies.AsNoTracking().ToList()
: EfContext.Proxies.AsTracking().ToList();
}
return new TgEfStorageResult<TgEfProxyEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetListAsync(int take, int skip, bool isNoTracking)
Expand All @@ -99,7 +99,7 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetListAsync(int
? EfContext.Proxies.AsNoTracking().ToList()
: EfContext.Proxies.AsTracking().ToList();
}
return new TgEfStorageResult<TgEfProxyEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override TgEfStorageResult<TgEfProxyEntity> GetList(int take, int skip, Expression<Func<TgEfProxyEntity, bool>> where, bool isNoTracking)
Expand All @@ -125,7 +125,7 @@ public override TgEfStorageResult<TgEfProxyEntity> GetList(int take, int skip, E
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfProxyEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetListAsync(int take, int skip, Expression<Func<TgEfProxyEntity, bool>> where, bool isNoTracking)
Expand All @@ -152,7 +152,7 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> GetListAsync(int
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfProxyEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override int GetCount() => EfContext.Proxies.AsNoTracking().Count();
Expand Down Expand Up @@ -185,7 +185,7 @@ public override TgEfStorageResult<TgEfProxyEntity> DeleteAll()
Delete(item, isSkipFind: true);
}
}
return new TgEfStorageResult<TgEfProxyEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

public override async Task<TgEfStorageResult<TgEfProxyEntity>> DeleteAllAsync()
Expand All @@ -198,7 +198,7 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> DeleteAllAsync()
await DeleteAsync(item, isSkipFind: true).ConfigureAwait(false);
}
}
return new TgEfStorageResult<TgEfProxyEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

#endregion
Expand All @@ -208,21 +208,21 @@ public override async Task<TgEfStorageResult<TgEfProxyEntity>> DeleteAllAsync()
public TgEfStorageResult<TgEfProxyEntity> GetCurrentProxy(TgEfStorageResult<TgEfAppEntity> storageResult)
{
if (!storageResult.IsExists)
return new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists);
return new(TgEnumEntityState.NotExists);

TgEfStorageResult<TgEfProxyEntity> storageResultProxy = Get(
new TgEfProxyEntity { Uid = storageResult.Item.ProxyUid ?? Guid.Empty }, isNoTracking: false);
return storageResultProxy.IsExists ? storageResultProxy : new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists);
new() { Uid = storageResult.Item.ProxyUid ?? Guid.Empty }, isNoTracking: false);
return storageResultProxy.IsExists ? storageResultProxy : new(TgEnumEntityState.NotExists);
}

public async Task<TgEfStorageResult<TgEfProxyEntity>> GetCurrentProxyAsync(TgEfStorageResult<TgEfAppEntity> storageResult)
{
if (!storageResult.IsExists)
return new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists);
return new(TgEnumEntityState.NotExists);

TgEfStorageResult<TgEfProxyEntity> storageResultProxy = await GetAsync(
new TgEfProxyEntity { Uid = storageResult.Item.ProxyUid ?? Guid.Empty }, isNoTracking: false);
return storageResultProxy.IsExists ? storageResultProxy : new TgEfStorageResult<TgEfProxyEntity>(TgEnumEntityState.NotExists);
new() { Uid = storageResult.Item.ProxyUid ?? Guid.Empty }, isNoTracking: false);
return storageResultProxy.IsExists ? storageResultProxy : new(TgEnumEntityState.NotExists);
}

public Guid GetCurrentProxyUid(TgEfStorageResult<TgEfAppEntity> storageResult) => GetCurrentProxy(storageResult).Item.Uid;
Expand Down
32 changes: 16 additions & 16 deletions Core/TgStorage/Domain/Sources/TgEfSourceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public override TgEfStorageResult<TgEfSourceEntity> Get(TgEfSourceEntity item, b
if (storageResult.IsExists)
return storageResult;
TgEfSourceEntity? itemFind = isNoTracking
? EfContext.Sources.AsNoTracking()
.Where(x => x.Id == item.Id)
.SingleOrDefault()
: EfContext.Sources.AsTracking()
.Where(x => x.Id == item.Id)
.SingleOrDefault();
? EfContext.Sources
.AsNoTracking()
.SingleOrDefault(x => x.Id == item.Id)
: EfContext.Sources
.AsTracking()
.SingleOrDefault(x => x.Id == item.Id);
return itemFind is not null
? new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -41,7 +41,7 @@ public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetAsync(TgEfSou
.SingleOrDefaultAsync()
.ConfigureAwait(false);
return itemFind is not null
? new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.IsExists, itemFind)
? new(TgEnumEntityState.IsExists, itemFind)
: new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.NotExists, item);
}

Expand All @@ -51,7 +51,7 @@ public override TgEfStorageResult<TgEfSourceEntity> GetFirst(bool isNoTracking)
? EfContext.Sources.AsNoTracking().FirstOrDefault()
: EfContext.Sources.AsTracking().FirstOrDefault();
return item is null
? new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -61,7 +61,7 @@ public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetFirstAsync(bo
? await EfContext.Sources.AsNoTracking().FirstOrDefaultAsync().ConfigureAwait(false)
: await EfContext.Sources.AsTracking().FirstOrDefaultAsync().ConfigureAwait(false);
return item is null
? new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.NotExists)
? new(TgEnumEntityState.NotExists)
: new TgEfStorageResult<TgEfSourceEntity>(TgEnumEntityState.IsExists, item);
}

Expand All @@ -80,7 +80,7 @@ public override TgEfStorageResult<TgEfSourceEntity> GetList(int take, int skip,
? EfContext.Sources.AsNoTracking().ToList()
: EfContext.Sources.AsTracking().ToList();
}
return new TgEfStorageResult<TgEfSourceEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetListAsync(int take, int skip, bool isNoTracking)
Expand All @@ -99,7 +99,7 @@ public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetListAsync(int
? EfContext.Sources.AsNoTracking().ToList()
: EfContext.Sources.AsTracking().ToList();
}
return new TgEfStorageResult<TgEfSourceEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override TgEfStorageResult<TgEfSourceEntity> GetList(int take, int skip, Expression<Func<TgEfSourceEntity, bool>> where, bool isNoTracking)
Expand All @@ -125,7 +125,7 @@ public override TgEfStorageResult<TgEfSourceEntity> GetList(int take, int skip,
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfSourceEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetListAsync(int take, int skip, Expression<Func<TgEfSourceEntity, bool>> where, bool isNoTracking)
Expand All @@ -152,7 +152,7 @@ public override async Task<TgEfStorageResult<TgEfSourceEntity>> GetListAsync(int
.Where(where)
.ToList();
}
return new TgEfStorageResult<TgEfSourceEntity>(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
return new(items.Any() ? TgEnumEntityState.IsExists : TgEnumEntityState.NotExists, items);
}

public override int GetCount() => EfContext.Sources.AsNoTracking().Count();
Expand Down Expand Up @@ -185,7 +185,7 @@ public override TgEfStorageResult<TgEfSourceEntity> DeleteAll()
Delete(item, isSkipFind: true);
}
}
return new TgEfStorageResult<TgEfSourceEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

public override async Task<TgEfStorageResult<TgEfSourceEntity>> DeleteAllAsync()
Expand All @@ -198,7 +198,7 @@ public override async Task<TgEfStorageResult<TgEfSourceEntity>> DeleteAllAsync()
await DeleteAsync(item, isSkipFind: true).ConfigureAwait(false);
}
}
return new TgEfStorageResult<TgEfSourceEntity>(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
return new(storageResult.IsExists ? TgEnumEntityState.IsDeleted : TgEnumEntityState.NotDeleted);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Core/TgStorage/Domain/Sources/TgEfSourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Guid SourceUid
set
{
TgEfStorageResult<TgEfSourceEntity> storageResult = SourceRepository.Get(
new TgEfSourceEntity { Uid = value }, isNoTracking: false);
new() { Uid = value }, isNoTracking: false);
Item = storageResult.IsExists
? storageResult.Item
: SourceRepository.GetNew(isNoTracking: false).Item;
Expand Down
Loading

0 comments on commit 4df3ed1

Please sign in to comment.