2022-09-08 08:04:32 -07:00

242 lines
8.9 KiB
C#

using Church.Net.DAL.EF;
using Church.Net.Entity;
using Church.Net.Utility;
using LineMessaging;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebAPI.Logics;
using WebAPI.Services.Interfaces;
namespace WebAPI.Services.AutoReplyCommands
{
public class ArArkCellGroupDinner : IAutoReplyCommand
{
public ArArkCellGroupDinner(ChurchNetContext context,
CellGroupLogic logic)
{
this._context = context;
this.logic = logic;
}
private static readonly string[] COMMANDS = { "晚餐", "dinner" };
private static readonly LineGroup[] GROUPS = {
LineGroup.Ark,
LineGroup.Chris,
};
private readonly ChurchNetContext _context;
private readonly CellGroupLogic logic;
public string Description => "顯示方舟小組聚會晚餐";
public IEnumerable<string> Commands => COMMANDS;
public IEnumerable<LineGroup> SupportGroups => GROUPS;
public IEnumerable<string> ReplyMessage
{
get
{
StringBuilder sb = new StringBuilder();
StringBuilder comments = new StringBuilder();
sb.AppendLine("又到了令人期待的小組日~~~");
var _event = _context.CellGroupRoutineEvents.Where(e => e.Time >= DateTime.Today)
.Include(e => e.Attendees).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>()
};
_context.Add(_event);
_context.SaveChanges();
}
sb.AppendLine($"{_event.Time.ToString("MM/dd HH:mm tt")} 開飯~");
sb.AppendLine("======= 晚宴清單 =======");
foreach (var a in _event.Attendees)
{
sb.AppendLine($"{a.Name} - {string.Join(", ", a.PotluckItem.Split('|'))}");
if (!string.IsNullOrWhiteSpace(a.Comment))
{
comments.AppendLine($"{a.Name}:{a.Comment}");
}
}
if (comments.Length > 0)
{
sb.AppendLine("========= 備註 =========");
sb.Append(comments.ToString());
}
return new string[] { sb.ToString() };
}
}
public IEnumerable<ILineMessage> LineMessage
{
get
{
var random = new Random();
List<ILineMessage> list = new List<ILineMessage>();
var _event = logic.GetComingEvent();
string title = "小組晚宴,吃飯皇帝大";
string imageUrl = "https://happiness.tours/assets/images/dinner.jpg";
var flexMessage = new LineFlexMessage();
flexMessage.AltText = title;
#region Header
var headerContent = flexMessage.Contents.InitHeader();
headerContent.Add(
new LineFlexText(title)
{
Size = FlexObjectSize.lg,
Weight = FlexObjectTextWeidht.Bold,
Align = "center"
});
#endregion
#region Hero
flexMessage.Contents.InitHero()
.Add(
new LineFlexImage(imageUrl)
{
Size = FlexObjectSize.full,
AspectRatio = "1.38:1"
}
);
#endregion
#region Body
var bodyContent = flexMessage.Contents.InitBody();
TimeSpan ts = _event.Time - DateTime.Now;
Console.WriteLine("No. of Minutes (Difference) = {0}", ts.TotalMinutes);
bodyContent.Add(
new LineFlexText($"再過 {ts.TotalMinutes.ToString("N0")} 分鐘,就是萬眾期待的小組晚宴啦!!!")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Regular,
OffsetBottom = FlexObjectSize.xxl,
Wrap = true
});
bodyContent.Add(
new LineFlexText($"{_event.Time.ToString("MM/dd HH:mm tt")} 準時開飯唷!!")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Regular,
OffsetBottom = FlexObjectSize.xl,
Wrap = true
});
bodyContent.Add(
new LineFlexText("晚宴菜單")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Bold,
OffsetBottom = FlexObjectSize.md
});
//$"目前暫無禱告事項唷, 趕快來新增代禱事項吧!!"
List<LineFlexBox> comments = new List<LineFlexBox>();
foreach (var a in _event.Attendees)
{
var name = a.Name;// logic.GetMemberFirstNameById(a.MemberId);
var baseLineBox = new LineFlexBox()
{
Layout = FlexObjectBoxLayout.Baseline,
};
baseLineBox.Contents.Add(
new LineFlexText(name)
{
Size = FlexObjectSize.sm,
Color = "#aaaaaa",
Flex = 1
});
baseLineBox.Contents.Add(
new LineFlexText(
string.Join(", ", a.PotluckItem.Split('|')
.Where(s => !String.IsNullOrWhiteSpace(s))
)
)
{
Size = FlexObjectSize.sm,
Color = "#666666",
Flex = 5,
Wrap = true
});
if (!string.IsNullOrWhiteSpace(a.Comment))
{
var commentLineBox = new LineFlexBox()
{
Layout = FlexObjectBoxLayout.Baseline,
};
commentLineBox.Contents.Add(
new LineFlexText(name)
{
Size = FlexObjectSize.sm,
Color = "#aaaaaa",
Flex = 1
});
commentLineBox.Contents.Add(
new LineFlexText(a.Comment)
{
Size = FlexObjectSize.sm,
Color = "#666666",
Flex = 5
});
comments.Add(commentLineBox);
}
bodyContent.Add(baseLineBox);
}
if (comments.Count > 0)
{
bodyContent.Add(
new LineFlexText("備註")
{
Size = FlexObjectSize.md,
Weight = FlexObjectTextWeidht.Bold,
//Style = "Italic"
});
foreach (var item in comments)
{
bodyContent.Add(item);
}
}
bodyContent.Add(new LineFlexSeparator());
#endregion
#region Footer
flexMessage.Contents.InitFooter()
.Add(
new LineFlexButton()
{
Action = new UriAction()
{
Uri = "https://happiness.tours/CellGroup/dinner?openExternalBrowser=1",
Label = "我的菜單"
}
}
);
#endregion
list.Insert(0, flexMessage);
return list;
}
}
}
}