public Task <ISchedule> GetScheduleForAsync(IScheduleGroup @group, ScheduleRequiredFor period) { if (period != ScheduleRequiredFor.Week) { return(GetScheduleForAsync(new[] { group }, DayOfWeekFromPeriod(period))); } else { return(GetWeekScheduleForAsync(new[] { group })); } }
private DayOfWeek DayOfWeekFromPeriod(ScheduleRequiredFor period) { switch (period) { case ScheduleRequiredFor.Today: return(DateTime.Now.DayOfWeek); case ScheduleRequiredFor.Tomorrow: return(DateTime.UtcNow.AddDays(1).ToLocalTime().DayOfWeek); } throw new ArgumentOutOfRangeException(); }
protected async Task <UpdateHandlingResult> HandleCommandForPeriod(Update update, DefaultCommandArgs args, ScheduleRequiredFor period) { if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday && period == ScheduleRequiredFor.Today || DateTime.Today.DayOfWeek == DayOfWeek.Saturday && period == ScheduleRequiredFor.Tomorrow) { await Bot.Client.SendTextMessageAsync(update.Message.Chat.Id, "Выходной день 😃"); return(UpdateHandlingResult.Handled); } var userGroups = await Storage.GetGroupsForChatAsync(update.Message.Chat); if (userGroups != null) { var schedule = await Scheduler.GetScheduleForAsync(userGroups, period); if (schedule.ScheduleRoot.Level == ScheduleElemLevel.Undefined) { await Bot.Client.SendTextMessageAsync(update.Message.Chat.Id, "Пар нет 😃"); return(UpdateHandlingResult.Handled); } var answer = CustomSerializator.ProcessSchedule(schedule.ScheduleRoot.Elems.Cast <Lesson>(), ((Day)schedule.ScheduleRoot).DayOfWeek); await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, answer, ParseMode.Html); } else { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "А группа?"); } return(UpdateHandlingResult.Handled); }
public Task <ISchedule> GetScheduleForAsync(IEnumerable <IScheduleGroup> groups, ScheduleRequiredFor period) { if (period != ScheduleRequiredFor.Week) { return(GetScheduleForAsync(groups, DayOfWeekFromPeriod(period))); } else { return(GetWeekScheduleForAsync(groups)); } }