Update Happiness Task
This commit is contained in:
@@ -30,23 +30,37 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.CheckExist(obj);
|
||||
}
|
||||
|
||||
public virtual void BeforeCreate(T entity)
|
||||
{
|
||||
}
|
||||
public virtual int Create(T entity)
|
||||
{
|
||||
return this.crudDAL.Create(entity);
|
||||
BeforeCreate(entity);
|
||||
return this.crudDAL.Create(entity) + CreateDone(entity);
|
||||
}
|
||||
|
||||
public virtual Task<int> CreateAsync(T entity)
|
||||
{
|
||||
BeforeCreate(entity);
|
||||
return this.crudDAL.CreateAsync(entity);
|
||||
}
|
||||
|
||||
public void CreateDone(T entity)
|
||||
public virtual int CreateDone(T entity)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int CreateOrUpdate(T entity, out string id)
|
||||
public virtual int CreateOrUpdate(T entity, out string id)
|
||||
{
|
||||
var result= this.crudDAL.CreateOrUpdate(entity);
|
||||
int result = 0;
|
||||
if (this.crudDAL.CheckExist(entity))
|
||||
{
|
||||
result = this.Update(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = this.Create(entity);
|
||||
}
|
||||
id = entity.Id;
|
||||
return result;
|
||||
}
|
||||
@@ -56,7 +70,7 @@ namespace WebAPI.Logics.Core
|
||||
// return this.crudDAL.CreateReturnId(entity);
|
||||
//}
|
||||
|
||||
public int Delete(T obj)
|
||||
public virtual int Delete(T obj)
|
||||
{
|
||||
return this.crudDAL.Delete(obj);
|
||||
}
|
||||
@@ -70,7 +84,7 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.First(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
public virtual IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.GetAll(filter);
|
||||
}
|
||||
@@ -85,18 +99,39 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.GetById(Id);
|
||||
}
|
||||
|
||||
public int Update(T entity)
|
||||
public virtual void BeforeUpdate(T entity)
|
||||
{
|
||||
return this.crudDAL.Update(entity);
|
||||
}
|
||||
|
||||
public void UpdateDone(T entity)
|
||||
public virtual int Update(T entity)
|
||||
{
|
||||
BeforeUpdate(entity);
|
||||
return this.crudDAL.Update(entity)+ UpdateDone(entity);
|
||||
}
|
||||
|
||||
public virtual int UpdateDone(T entity)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int UpdateRange(IEnumerable<T> entities)
|
||||
{
|
||||
return this.crudDAL.UpdateRange(entities);
|
||||
int result = 0;
|
||||
foreach (var item in entities)
|
||||
{
|
||||
result += Update(item);
|
||||
}
|
||||
return result;// this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
|
||||
public int CreateOrUpdateAll(IEnumerable<T> entities)
|
||||
{
|
||||
int result = 0;
|
||||
foreach (var item in entities)
|
||||
{
|
||||
result += CreateOrUpdate(item,out string id);
|
||||
}
|
||||
return result;// this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,16 @@ namespace WebAPI.Logics.Core
|
||||
public class LogicService
|
||||
{
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly IdentityService identityService;
|
||||
|
||||
public LogicService(
|
||||
//ChurchNetContext dbContext
|
||||
IServiceScopeFactory serviceScopeFactory
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
IdentityService identityService
|
||||
)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
this.identityService = identityService;
|
||||
//DbContext = dbContext;
|
||||
}
|
||||
|
||||
@@ -22,11 +25,7 @@ namespace WebAPI.Logics.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService<IdentityService>();
|
||||
return service.UserId;
|
||||
}
|
||||
return identityService.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user