/// <summary> /// Adding a one time event /// </summary> /// <param name="commandContext">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task AddOneTimeEvent(CommandContextContainer commandContext) { var data = await DialogHandler.RunForm <CreateOneTimeEventFormData>(commandContext, false) .ConfigureAwait(false); if (data != null) { using (var dbFactory = RepositoryFactory.CreateInstance()) { var appointmentTime = dbFactory.GetRepository <CalendarAppointmentTemplateRepository>() .GetQuery() .Where(obj => obj.Id == data.TemplateId) .Select(obj => obj.AppointmentTime) .First(); if (dbFactory.GetRepository <CalendarAppointmentRepository>() .Add(new CalendarAppointmentEntity { CalendarAppointmentScheduleId = null, CalendarAppointmentTemplateId = data.TemplateId, TimeStamp = data.Day.Add(appointmentTime) })) { await _messageBuilder.RefreshMessages(commandContext.Guild.Id) .ConfigureAwait(false); } } } }
/// <summary> /// Setting up the calendar /// </summary> /// <param name="commandContext">Command context</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task SetupCalendar(CommandContextContainer commandContext) { var data = await DialogHandler.RunForm <SetGuildCalendarFormData>(commandContext, true) .ConfigureAwait(false); if (data != null) { var message = await commandContext.Channel .SendMessageAsync(LocalizationGroup.GetText("CalendarBuilding", "The calendar will be build with the next refresh.")) .ConfigureAwait(false); using (var dbFactory = RepositoryFactory.CreateInstance()) { var guildId = dbFactory.GetRepository <GuildRepository>() .GetQuery() .Where(obj => obj.DiscordServerId == commandContext.Guild.Id) .Select(obj => obj.Id) .FirstOrDefault(); if (guildId > 0) { if (dbFactory.GetRepository <GuildChannelConfigurationRepository>() .AddOrRefresh(obj => obj.GuildId == guildId && obj.Type == GuildChannelConfigurationType.CalendarOverview, obj => { obj.DiscordChannelId = commandContext.Channel.Id; obj.DiscordMessageId = message.Id; obj.AdditionalData = JsonConvert.SerializeObject(new AdditionalCalendarChannelData { Title = data.Title, Description = data.Description }); })) { await _calendarScheduleService.CreateAppointments(commandContext.Guild.Id) .ConfigureAwait(false); await _calendarMessageBuilderService.RefreshMessages(commandContext.Guild.Id) .ConfigureAwait(false); await _calendarMessageBuilderService.RefreshMotds(commandContext.Guild.Id) .ConfigureAwait(false); } } } } }