Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
using Church.Net.Entity;
|
||||
using Church.Net.Utility;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using WebAPI.Logics.Core;
|
||||
using WebAPI.Logics.Interface;
|
||||
using System.Linq;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class CellGroupLogic
|
||||
{
|
||||
private readonly ICrudDAL<CellGroupRoutineEvent> eventCrudDAL;
|
||||
private readonly ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL;
|
||||
private readonly ICrudDAL<FamilyMember> memberCrudDAL;
|
||||
|
||||
public CellGroupLogic(
|
||||
ICrudDAL<CellGroupRoutineEvent> eventCrudDAL,
|
||||
ICombinedKeyCrudDAL<CellGroupRoutineEventAttendee> attendeeCrudDAL,
|
||||
ICrudDAL<FamilyMember> memberCrudDAL
|
||||
)
|
||||
{
|
||||
this.eventCrudDAL = eventCrudDAL;
|
||||
this.attendeeCrudDAL = attendeeCrudDAL;
|
||||
this.memberCrudDAL = memberCrudDAL;
|
||||
}
|
||||
|
||||
public CellGroupRoutineEvent GetComingEvent()
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().Where(e => e.Time >= DateTime.UtcNow)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault();
|
||||
if (_event == null)
|
||||
{
|
||||
_event = new CellGroupRoutineEvent()
|
||||
{
|
||||
Id = Format.Get33BaseGuid(),
|
||||
Time = DateTimeHelper.GetNextWeekday(DateTime.Today, DayOfWeek.Friday).AddHours(19).AddMinutes(30),
|
||||
Address = "1881 Forest Dr., Azusa, CA 91702",
|
||||
Attendees = new List<CellGroupRoutineEventAttendee>()
|
||||
};
|
||||
eventCrudDAL.Create(_event);
|
||||
}
|
||||
|
||||
return _event;
|
||||
}
|
||||
public CellGroupRoutineEvent GetLastEvent()
|
||||
{
|
||||
var _event = eventCrudDAL.GetDbSet().OrderByDescending(e=>e.Time)
|
||||
.Include(e => e.Attendees).Include(e => e.Prayers).FirstOrDefault();
|
||||
return _event;
|
||||
}
|
||||
|
||||
public string GetMemberFirstNameById(string memberId)
|
||||
{
|
||||
return memberCrudDAL.GetById(memberId)?.FirstName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Transactions;
|
||||
using System;
|
||||
using Church.Net.DAL.EF;
|
||||
using System.Linq;
|
||||
using Church.Net.Utility;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics.Interface;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
|
||||
namespace WebAPI.Logics.Core
|
||||
{
|
||||
public class CombinedKeyLogicBase<T> : ICombinedKeyCrudLogic<T> where T : class, Church.Net.Entity.Interface.ICombinedKeyEntity, new()
|
||||
{
|
||||
private readonly LogicService logicService;
|
||||
private readonly ICombinedKeyCrudDAL<T> crudDAL;
|
||||
|
||||
public CombinedKeyLogicBase(
|
||||
LogicService logicService,
|
||||
ICombinedKeyCrudDAL<T> crudDAL
|
||||
)
|
||||
{
|
||||
this.logicService = logicService;
|
||||
this.crudDAL = crudDAL;
|
||||
}
|
||||
|
||||
public virtual bool CheckExist(T obj)
|
||||
{
|
||||
return this.crudDAL.CheckExist(obj);
|
||||
}
|
||||
|
||||
public virtual int Create(T entity)
|
||||
{
|
||||
return this.crudDAL.Create(entity);
|
||||
}
|
||||
|
||||
public virtual Task<int> CreateAsync(T entity)
|
||||
{
|
||||
return this.crudDAL.CreateAsync(entity);
|
||||
}
|
||||
|
||||
public void CreateDone(T entity)
|
||||
{
|
||||
}
|
||||
|
||||
public int CreateOrUpdate(T entity)
|
||||
{
|
||||
var result= this.crudDAL.CreateOrUpdate(entity);
|
||||
return result;
|
||||
}
|
||||
|
||||
public int Delete(T obj)
|
||||
{
|
||||
return this.crudDAL.Delete(obj);
|
||||
}
|
||||
public int Delete(IEnumerable<string> combinedKeyIds)
|
||||
{
|
||||
return this.crudDAL.Delete(combinedKeyIds);
|
||||
}
|
||||
public int Delete(Func<T, bool> filter)
|
||||
{
|
||||
|
||||
return this.crudDAL.Delete(filter);
|
||||
}
|
||||
|
||||
public T First(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.First(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.GetAll(filter);
|
||||
}
|
||||
|
||||
|
||||
public T GetById(IEnumerable<string> combinedKeyIds)
|
||||
{
|
||||
return this.crudDAL.GetById(combinedKeyIds);
|
||||
}
|
||||
|
||||
public int Update(T entity)
|
||||
{
|
||||
return this.crudDAL.Update(entity);
|
||||
}
|
||||
|
||||
public void UpdateDone(T entity)
|
||||
{
|
||||
}
|
||||
|
||||
public int UpdateRange(IEnumerable<T> entities)
|
||||
{
|
||||
return this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Transactions;
|
||||
using System;
|
||||
using Church.Net.DAL.EF;
|
||||
using System.Linq;
|
||||
using Church.Net.Utility;
|
||||
using System.Threading.Tasks;
|
||||
using WebAPI.Logics.Interface;
|
||||
using Church.Net.DAL.EFCoreDBF;
|
||||
|
||||
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;
|
||||
|
||||
public LogicBase(
|
||||
LogicService logicService,
|
||||
ICrudDAL<T> crudDAL
|
||||
)
|
||||
{
|
||||
this.logicService = logicService;
|
||||
this.crudDAL = crudDAL;
|
||||
}
|
||||
|
||||
public virtual bool CheckExist(T obj)
|
||||
{
|
||||
return this.crudDAL.CheckExist(obj);
|
||||
}
|
||||
|
||||
public virtual int Create(T entity)
|
||||
{
|
||||
return this.crudDAL.Create(entity);
|
||||
}
|
||||
|
||||
public virtual Task<int> CreateAsync(T entity)
|
||||
{
|
||||
return this.crudDAL.CreateAsync(entity);
|
||||
}
|
||||
|
||||
public void CreateDone(T entity)
|
||||
{
|
||||
}
|
||||
|
||||
public int CreateOrUpdate(T entity, out string id)
|
||||
{
|
||||
var result= this.crudDAL.CreateOrUpdate(entity, out string _id);
|
||||
id = _id;
|
||||
return result;
|
||||
}
|
||||
|
||||
public string CreateReturnId(T entity)
|
||||
{
|
||||
return this.crudDAL.CreateReturnId(entity);
|
||||
}
|
||||
|
||||
public int Delete(T obj)
|
||||
{
|
||||
return this.crudDAL.Delete(obj);
|
||||
}
|
||||
|
||||
public int Delete(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.Delete(filter);
|
||||
}
|
||||
public T First(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.First(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll(Func<T, bool> filter = null)
|
||||
{
|
||||
return this.crudDAL.GetAll(filter);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAllById(IEnumerable<string> Ids)
|
||||
{
|
||||
return this.crudDAL.GetAllById(Ids);
|
||||
}
|
||||
|
||||
public T GetById(string Id)
|
||||
{
|
||||
return this.crudDAL.GetById(Id);
|
||||
}
|
||||
|
||||
public int Update(T entity)
|
||||
{
|
||||
return this.crudDAL.Update(entity);
|
||||
}
|
||||
|
||||
public void UpdateDone(T entity)
|
||||
{
|
||||
}
|
||||
|
||||
public int UpdateRange(IEnumerable<T> entities)
|
||||
{
|
||||
return this.crudDAL.UpdateRange(entities);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Church.Net.DAL.EF;
|
||||
|
||||
namespace WebAPI.Logics.Core
|
||||
{
|
||||
public class LogicService
|
||||
{
|
||||
public LogicService(
|
||||
ChurchNetContext dbContext
|
||||
)
|
||||
{
|
||||
DbContext = dbContext;
|
||||
}
|
||||
|
||||
public ChurchNetContext DbContext { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
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, out string weekId);
|
||||
}
|
||||
}
|
||||
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, out string id);
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Church.Net.DAL.EF;
|
||||
using Church.Net.Utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace WebAPI.Logics.Interface
|
||||
{
|
||||
public interface ICrudLogic<T>
|
||||
{
|
||||
|
||||
T First(Func<T, bool> filter = null);
|
||||
|
||||
T GetById(string Id);
|
||||
IEnumerable<T> GetAll(Func<T, bool> filter = null);
|
||||
IEnumerable<T> GetAllById(IEnumerable<string> Ids);
|
||||
int Create(T entity);
|
||||
Task<int> CreateAsync(T entity);
|
||||
string CreateReturnId(T entity);
|
||||
|
||||
int CreateOrUpdate(T entity, out string id);
|
||||
int Update(T entity);
|
||||
void CreateDone(T entity);
|
||||
void UpdateDone(T entity);
|
||||
int UpdateRange(IEnumerable<T> entities);
|
||||
int Delete(T obj);
|
||||
int Delete(Func<T, bool> filter = null);
|
||||
bool CheckExist(T obj);
|
||||
|
||||
}
|
||||
public interface ICombinedKeyCrudLogic<T>
|
||||
{
|
||||
T First(Func<T, bool> filter = null);
|
||||
T GetById(IEnumerable<string> combinedKeyIds);
|
||||
IEnumerable<T> GetAll(Func<T, bool> filter = null);
|
||||
int Create(T entity);
|
||||
Task<int> CreateAsync(T entity);
|
||||
int CreateOrUpdate(T entity);
|
||||
int Update(T entity);
|
||||
void CreateDone(T entity);
|
||||
void UpdateDone(T entity);
|
||||
int UpdateRange(IEnumerable<T> entities);
|
||||
int Delete(T obj);
|
||||
int Delete(IEnumerable<string> combinedKeyIds);
|
||||
int Delete(Func<T, bool> filter);
|
||||
bool CheckExist(T obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using DotNetTools.SharpGrabber;
|
||||
using DotNetTools.SharpGrabber.Grabbed;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebAPI.Logics
|
||||
{
|
||||
public class VideoDownloadLogic
|
||||
{
|
||||
public async void Download(string youtubeUrl, string filePath)
|
||||
{
|
||||
var grabber = GrabberBuilder.New()
|
||||
.UseDefaultServices()
|
||||
.AddYouTube()
|
||||
.Build();
|
||||
var result = await grabber.GrabAsync(new Uri(youtubeUrl));
|
||||
|
||||
var info = result.Resource<GrabbedInfo>();
|
||||
Console.WriteLine("Time Length: {0}", info.Length);
|
||||
var videos = result.Resources<GrabbedMedia>();
|
||||
|
||||
foreach (var video in videos)
|
||||
{
|
||||
if ("mp4" == video.Format.Extension)
|
||||
{
|
||||
if (video.Resolution == "1080p")
|
||||
{
|
||||
await DownloadMedia(video, result, $"{filePath}/{video.Title}.mp4");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public async void DownloadWorship(string youtubeUrl)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Download(youtubeUrl, ServerUtils.MapPath("WorshipVideos"));//ServerUtils.MapPath("Church/Test.mp4")
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static async Task<string> DownloadMedia(GrabbedMedia media, IGrabResult grabResult, string path)
|
||||
{
|
||||
HttpClient Client = new HttpClient();
|
||||
Client.Timeout = TimeSpan.FromMinutes(30);
|
||||
Console.WriteLine("Downloading {0}...", media.Title ?? media.FormatTitle ?? media.Resolution);
|
||||
using var response = await Client.GetAsync(media.ResourceUri);
|
||||
response.EnsureSuccessStatusCode();
|
||||
using var downloadStream = await response.Content.ReadAsStreamAsync();
|
||||
using var resourceStream = await grabResult.WrapStreamAsync(downloadStream);
|
||||
|
||||
using var fileStream = new FileStream(path, FileMode.Create);
|
||||
await resourceStream.CopyToAsync(fileStream);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user