86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using Church.Net.DAL.EFCoreDBF;
|
|
using Church.Net.Entity;
|
|
using Church.Net.Utility;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Metrics;
|
|
using System.Linq;
|
|
|
|
namespace WebAPI.Logics
|
|
{
|
|
public class HappinessGroupLogic
|
|
{
|
|
private readonly ICrudDAL<HappinessGroup> groupCrudDAL;
|
|
private readonly ICrudDAL<HappinessWeek> weekCrudDAL;
|
|
string[] weekTitles = new string[] { "真幸福", "真相大白", "萬世巨星", "幸福連線", "當上帝來敲門", "十字架的勝利", "釋放與自由", "幸福的教會" };
|
|
|
|
public HappinessGroupLogic(
|
|
ICrudDAL<HappinessGroup> groupCrudDAL,
|
|
ICrudDAL<HappinessWeek> weekCrudDAL
|
|
)
|
|
{
|
|
this.groupCrudDAL = groupCrudDAL;
|
|
this.weekCrudDAL = weekCrudDAL;
|
|
}
|
|
|
|
public List<HappinessGroup> GetAllGroups()
|
|
{
|
|
var list = groupCrudDAL.GetDbSet().Include(g => g.BestList).Include(g => g.Weeks).ToList();
|
|
|
|
foreach (var group in list)
|
|
{
|
|
if (group.Weeks == null || group.Weeks.Count() == 0)
|
|
{
|
|
group.Weeks = new List<HappinessWeek>();
|
|
for (int i = 1; i <= 8; i++)
|
|
{
|
|
var week = GetHappinessWeek(group, i);
|
|
group.Weeks.Add(week);
|
|
weekCrudDAL.CreateOrUpdate(week);
|
|
}
|
|
}
|
|
group.Weeks = group.Weeks.OrderBy(w => w.SEQ).ToList();
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
public int UpdateWeekInfo(HappinessWeek value)
|
|
{
|
|
if (value.UpdateRestWeekDate)
|
|
{
|
|
var list = weekCrudDAL.GetAll(week => week.SEQ >= value.SEQ && week.GroupId == value.GroupId).OrderBy(w => w.SEQ).ToList();
|
|
var tempDate = new DateTime(value.Date.Year, value.Date.Month, value.Date.Day, value.Date.Hour, value.Date.Minute, value.Date.Second);
|
|
int count = 0;
|
|
foreach (var week in list)
|
|
{
|
|
week.Date = tempDate.AddDays(count * 7);
|
|
week.Address = value.Address;
|
|
week.CityAndZipCode = value.CityAndZipCode;
|
|
week.InvitationText = value.InvitationText;
|
|
count++;
|
|
}
|
|
return weekCrudDAL.UpdateRange(list);
|
|
}
|
|
return weekCrudDAL.CreateOrUpdate(value);
|
|
|
|
}
|
|
|
|
private HappinessWeek GetHappinessWeek(HappinessGroup group, int weekNo)
|
|
{
|
|
return new HappinessWeek()
|
|
{
|
|
GroupId = group.Id,
|
|
Address = group.Address,
|
|
CityAndZipCode = group.CityAndZipCode,
|
|
Date = group.BeginTime.AddDays(7 * (weekNo - 1)),
|
|
SEQ = weekNo
|
|
};
|
|
}
|
|
}
|
|
}
|