Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AssemblyInfo.General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

[assembly: AssemblyCompany("Национальный Исследовательский Ядерный Университет МИФИ")]
[assembly: AssemblyProduct("GraphLabs")]
[assembly: AssemblyCopyright("Copyright © 2012-2016")]
[assembly: AssemblyCopyright("Copyright © 2012-2018")]
[assembly: AssemblyTrademark("")]
4 changes: 4 additions & 0 deletions GraphLabs.Dal.Ef/GraphLabs.Dal.Ef.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
<Project>{3e515720-d0a1-4b01-a3e0-c82412b2d663}</Project>
<Name>GraphLabs.DomainModel</Name>
</ProjectReference>
<ProjectReference Include="..\GraphLabs.Guard\GraphLabs.Guard.csproj">
<Project>{d0a05aef-dc7e-4b2b-a82a-9a23eaa0af95}</Project>
<Name>GraphLabs.Guard</Name>
</ProjectReference>
<ProjectReference Include="..\GraphLabs.Site.Core\GraphLabs.Site.Core.csproj">
<Project>{d62cc3f4-3ea1-44ff-b9e2-492582788b3b}</Project>
<Name>GraphLabs.Site.Core</Name>
Expand Down
4 changes: 3 additions & 1 deletion GraphLabs.Dal.Ef/GraphLabsContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using GraphLabs.DomainModel;
using GraphLabs.DomainModel.Contexts;
using GraphLabs.DomainModel.Infrastructure;
using GraphLabs.Guard;


namespace GraphLabs.Dal.Ef
{
Expand Down Expand Up @@ -34,7 +36,7 @@ public GraphLabsContextImpl(GraphLabsContext ctx)

private Type GetEntityTypeFor(Type type)
{
Contract.Assert(typeof(AbstractEntity).IsAssignableFrom(type));
Guard.AreAssignedTypes(typeof(AbstractEntity), type);

var baseType = type.BaseType;
if (baseType == typeof(AbstractEntity))
Expand Down
2 changes: 1 addition & 1 deletion GraphLabs.Dal.Ef/Infrastructure/ChangesTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChangesTracker : IChangesTracker
/// <summary> Менеджер изменений </summary>
public ChangesTracker(GraphLabsContext context)
{
Contract.Requires(context != null);
Guard.IsNotNull(nameof(context), context );

_context = context;
}
Expand Down
12 changes: 10 additions & 2 deletions GraphLabs.Dal.Ef/Infrastructure/EntityChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ public EntityChange(DbEntityEntry entry)
/// <summary> Изменилось ли свойство? </summary>
public bool PropertyChanged(string propertyName)
{
Guard.IsNotNullOrWhiteSpace(propertyName);
return _entry.CurrentValues[propertyName] != _entry.OriginalValues[propertyName];
}

public IReadOnlyDictionary<string, object> OriginalValues
{
get { return _originalValues.Value; }

get
{
return _originalValues.Value;
}
}

public IReadOnlyDictionary<string, object> CurrentValues
{
get { return _currentValues.Value; }
get
{
return _currentValues.Value;
}
}
}
}
5 changes: 3 additions & 2 deletions GraphLabs.Dal.Ef/Infrastructure/EntitySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public TEntity Find(params object[] keyValues)
/// <exception cref="EntityNotFoundException">Не удалось найти сущность с заданным ключом</exception>
public TEntity Get(params object[] keyValues)
{
Guard.IsPositive(keyValues.Length, nameof(keyValues));
var entity = _ctx.Set<TEntity>().Find(keyValues);
if (entity == null)
throw new EntityNotFoundException(typeof(TEntity), keyValues);
Expand All @@ -42,7 +43,7 @@ public TDerivedEntity CreateNew<TDerivedEntity>() where TDerivedEntity : TEntity
var set = _ctx.Set<TEntity>();
var entity = set.Create<TDerivedEntity>();
set.Add(entity);

Guard.IsNotNull(entity);
return entity;
}

Expand All @@ -52,7 +53,7 @@ public TEntity CreateNew()
var set = _ctx.Set<TEntity>();
var entity = set.Create();
set.Add(entity);

Guard.IsNotNull(entity, "entity");
return entity;
}
}
Expand Down
1 change: 1 addition & 0 deletions GraphLabs.Dal.Ef/IoC/DalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed class DalConfiguration : IUnityRegistry
/// <summary> Сконфигурировать </summary>
public void ConfigureContainer(IUnityContainer container)
{
Guard.IsNotNull(nameof(container), container);
// Сам EF-контекст
container.RegisterType<GraphLabsContext>(new HierarchicalLifetimeManager());

Expand Down
14 changes: 10 additions & 4 deletions GraphLabs.Dal.Ef/Repositories/CategoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ public CategoryRepository(GraphLabsContext context)
/// <summary> Получить категорию по id </summary>
public Category GetById(long id)
{
Guard.IsPositive(id, nameof(id) );
CheckNotDisposed();

return Context.Categories.Single(c => c.Id == id);
var result = Context.Categories.Single(c => c.Id == id);
Guard.IsNotNull(result);
return (result);
}

///<summary> Получить все категории </summary>
public Category[] GetAllCategories()
{
CheckNotDisposed();

return Context.Categories.ToArray();
var result = Context.Categories.ToArray();
Guard.IsNotNull(result);
return result;
}

///<summary> Сохранение категории </summary>
public void SaveCategory(Category category)
{
Guard.IsNotNull(nameof(category), category);
CheckNotDisposed();

Context.Categories.Add(category);
Expand All @@ -42,7 +47,8 @@ public void SaveCategory(Category category)
///<summary> Редактирование категории </summary>
public void EditCategory(Category category)
{
CheckNotDisposed();
Guard.IsNotNull(nameof(category), category);
CheckNotDisposed();

Context.Entry(category).State = EntityState.Modified;
Context.SaveChanges();
Expand Down
16 changes: 10 additions & 6 deletions GraphLabs.Dal.Ef/Repositories/GroupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ public GroupRepository(GraphLabsContext context)
public Group[] GetAllGroups()
{
CheckNotDisposed();

return Context.Groups.ToArray();
var result = Context.Groups.ToArray();
Guard.IsNotNull(result);
return result;
}

/// <summary> Получить группы, открытые для регистрации </summary>
public Group[] GetOpenGroups()
{
CheckNotDisposed();

return Context.Groups.Where(g => g.IsOpen).ToArray();
var result = Context.Groups.Where(g => g.IsOpen).ToArray();
Guard.IsNotNull(result);
return result;
}

/// <summary> Получить группу по id </summary>
public Group GetGroupById(long id)
{
Guard.IsPositive(id, "id");
CheckNotDisposed();

return Context.Groups.Where(g => g.Id == id).Single();
var result = Context.Groups.Where(g => g.Id == id).Single();
Guard.IsNotNull(result);
return result;
}
}
}
Loading