Test Creation DesktopApp

This commit is contained in:
2019-03-09 14:03:25 +01:00
parent e8fd116eab
commit ac9614a70a
34 changed files with 1131 additions and 189 deletions

View File

@@ -3,10 +3,11 @@ using System.Linq;
using LaDOSE.Business.Interface;
using LaDOSE.Entity.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace LaDOSE.Business.Service
{
public class BaseService<T> : IBaseService<T> where T : class
public class BaseService<T> : IBaseService<T> where T : Entity.Context.Entity
{
protected LaDOSEDbContext _context;
@@ -43,5 +44,21 @@ namespace LaDOSE.Business.Service
_context.Remove(find);
return _context.Entry(find).State == EntityState.Deleted;
}
public virtual T AddOrUpdate(T entity)
{
EntityEntry<T> entityEntry;
if (entity.Id == 0)
{
entityEntry = this._context.Add(entity);
}
else
{
entityEntry = this._context.Update(entity);
}
this._context.SaveChanges();
return entityEntry.Entity;
}
}
}