Update API
This commit is contained in:
@@ -7,21 +7,25 @@ using System;
|
||||
using WebAPI.Logics.Core;
|
||||
using WebAPI.Logics.Interface;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class CellGroupLogic
|
||||
{
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly ICrudDAL<CellGroupRoutineEvent> eventCrudDAL;
|
||||
private readonly ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL;
|
||||
private readonly ICrudDAL<FamilyMember> memberCrudDAL;
|
||||
|
||||
public CellGroupLogic(
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
ICrudDAL<CellGroupRoutineEvent> eventCrudDAL,
|
||||
ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL,
|
||||
ICrudDAL<FamilyMember> memberCrudDAL
|
||||
)
|
||||
{
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
this.eventCrudDAL = eventCrudDAL;
|
||||
this.attendeeCrudDAL = attendeeCrudDAL;
|
||||
this.memberCrudDAL = memberCrudDAL;
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace WebAPI.Logics.Core
|
||||
{
|
||||
public class LogicBase<T> : ICrudLogic<T> where T : class, Church.Net.Entity.Interface.IEntity, new()
|
||||
{
|
||||
private readonly LogicService logicService;
|
||||
private readonly ICrudDAL<T> crudDAL;
|
||||
protected readonly LogicService logicService;
|
||||
protected readonly ICrudDAL<T> crudDAL;
|
||||
|
||||
public LogicBase(
|
||||
LogicService logicService,
|
||||
@@ -46,15 +46,15 @@ namespace WebAPI.Logics.Core
|
||||
|
||||
public int CreateOrUpdate(T entity, out string id)
|
||||
{
|
||||
var result= this.crudDAL.CreateOrUpdate(entity, out string _id);
|
||||
id = _id;
|
||||
var result= this.crudDAL.CreateOrUpdate(entity);
|
||||
id = entity.Id;
|
||||
return result;
|
||||
}
|
||||
|
||||
public string CreateReturnId(T entity)
|
||||
{
|
||||
return this.crudDAL.CreateReturnId(entity);
|
||||
}
|
||||
//public string CreateReturnId(T entity)
|
||||
//{
|
||||
// return this.crudDAL.CreateReturnId(entity);
|
||||
//}
|
||||
|
||||
public int Delete(T obj)
|
||||
{
|
||||
@@ -75,10 +75,10 @@ namespace WebAPI.Logics.Core
|
||||
return this.crudDAL.GetAll(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAllById(IEnumerable<string> Ids)
|
||||
{
|
||||
return this.crudDAL.GetAllById(Ids);
|
||||
}
|
||||
//public IEnumerable<T> GetAllById(IEnumerable<string> Ids)
|
||||
//{
|
||||
// return this.crudDAL.GetAllById(Ids);
|
||||
//}
|
||||
|
||||
public T GetById(string Id)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
using Church.Net.DAL.EF;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WebAPI.Services;
|
||||
|
||||
namespace WebAPI.Logics.Core
|
||||
{
|
||||
public class LogicService
|
||||
{
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
|
||||
public LogicService(
|
||||
ChurchNetContext dbContext
|
||||
//ChurchNetContext dbContext
|
||||
IServiceScopeFactory serviceScopeFactory
|
||||
)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
this.serviceScopeFactory = serviceScopeFactory;
|
||||
//DbContext = dbContext;
|
||||
}
|
||||
|
||||
public ChurchNetContext DbContext { get; }
|
||||
//public ChurchNetContext DbContext { get; }
|
||||
public string CurrentUserId
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
var service = scope.ServiceProvider.GetService<IdentityService>();
|
||||
return service.UserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace WebAPI.Logics
|
||||
{
|
||||
var week = GetHappinessWeek(group, i);
|
||||
group.Weeks.Add(week);
|
||||
weekCrudDAL.CreateOrUpdate(week, out string weekId);
|
||||
weekCrudDAL.CreateOrUpdate(week);
|
||||
}
|
||||
}
|
||||
group.Weeks = group.Weeks.OrderBy(w => w.SEQ).ToList();
|
||||
@@ -66,7 +66,7 @@ namespace WebAPI.Logics
|
||||
}
|
||||
return weekCrudDAL.UpdateRange(list);
|
||||
}
|
||||
return weekCrudDAL.CreateOrUpdate(value, out string id);
|
||||
return weekCrudDAL.CreateOrUpdate(value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ namespace WebAPI.Logics.Interface
|
||||
|
||||
T GetById(string Id);
|
||||
IEnumerable<T> GetAll(Func<T, bool> filter = null);
|
||||
IEnumerable<T> GetAllById(IEnumerable<string> Ids);
|
||||
//IEnumerable<T> GetAllById(IEnumerable<string> Ids);
|
||||
int Create(T entity);
|
||||
Task<int> CreateAsync(T entity);
|
||||
string CreateReturnId(T entity);
|
||||
//string CreateReturnId(T entity);
|
||||
|
||||
int CreateOrUpdate(T entity, out string id);
|
||||
int Update(T entity);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Entity.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics.Core;
|
||||
using WebAPI.Logics.Interface;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class LineMessagingAccountLogic : LogicBase<LineMessagingAccount>, ICrudLogic<LineMessagingAccount>
|
||||
{
|
||||
private readonly ICrudDAL<HappinessGroup> happinessGroupDAL;
|
||||
private readonly ICrudDAL<PastoralDomain> cellGroupDAL;
|
||||
|
||||
public LineMessagingAccountLogic(
|
||||
LogicService logicService,
|
||||
ICrudDAL<LineMessagingAccount> crudDAL,
|
||||
ICrudDAL<HappinessGroup> happinessGroupDAL,
|
||||
ICrudDAL<PastoralDomain> cellGroupDAL
|
||||
) : base(logicService, crudDAL)
|
||||
{
|
||||
this.happinessGroupDAL = happinessGroupDAL;
|
||||
this.cellGroupDAL = cellGroupDAL;
|
||||
}
|
||||
|
||||
public HappinessGroup GetHappinessGroup(string lineGroupId)
|
||||
{
|
||||
var group= happinessGroupDAL.First(c => c.CommunityAppId == lineGroupId);
|
||||
GetLineMessagingAccount(group);
|
||||
return group;
|
||||
}
|
||||
public PastoralDomain GetCellGroup(string lineGroupId)
|
||||
{
|
||||
var group = cellGroupDAL.First(c => c.CommunityAppId == lineGroupId);
|
||||
GetLineMessagingAccount(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
private void GetLineMessagingAccount(IMessengerClient messengerClient)
|
||||
{
|
||||
if (messengerClient != null)
|
||||
{
|
||||
messengerClient.LineMessagingAccount = crudDAL.GetById(messengerClient.LineAccountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user