예제 #1
0
        public async Task <IActionResult> EditRecurringReminder(ulong guildId, EditRecurringReminderMessageViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (vm.Id == default(long))
            {
                var newReminder = new RecurringReminderMessage
                {
                    ChannelId      = vm.ChannelId,
                    Enabled        = vm.Enabled,
                    Message        = vm.Message,
                    CronExpression = vm.CronExpression,
                    GuildId        = guildId
                };

                await _reminderService.Create(newReminder);

                return(RedirectToAction("RemembotSettings", "Settings"));
            }

            var reminder = await _reminderService.Find(vm.Id);

            reminder.ChannelId      = vm.ChannelId;
            reminder.Enabled        = vm.Enabled;
            reminder.Message        = vm.Message;
            reminder.CronExpression = vm.CronExpression;

            await _reminderService.Update(reminder);

            return(RedirectToAction("RemembotSettings", "Settings"));
        }
예제 #2
0
        public async Task <IActionResult> EditRecurringReminder(ulong guildId, [FromQuery] long rid)
        {
            var channels = await _guildService.GetChannels(guildId);

            var textChannels = channels.Where(x => x.Type == 0);

            if (rid == default(long))
            {
                var newVm = new EditRecurringReminderMessageViewModel
                {
                    Channels       = new SelectList(textChannels, "Id", "Name"),
                    Enabled        = true,
                    GuildId        = guildId,
                    CronExpression = Cron.Minutely()
                };

                return(View(newVm));
            }

            var reminder = await _reminderService.Find(rid);

            if (reminder is null)
            {
                return(RedirectToAction("RemembotSettings", "Settings"));
            }

            var selectedChannel = channels.Find(x => x.Id == reminder.ChannelId);
            var editVm          = new EditRecurringReminderMessageViewModel
            {
                GuildId        = guildId,
                Channels       = new SelectList(textChannels, "Id", "Name", selectedChannel),
                CronExpression = reminder.CronExpression,
                Enabled        = reminder.Enabled,
                Message        = reminder.Message,
                FaultMessage   = reminder.GetFaultLongMessage(),
                ChannelId      = reminder.ChannelId,
                ChannelName    = selectedChannel.Name,
                FaultType      = (int)reminder.Fault,
                Id             = reminder.Id
            };

            return(View(editVm));
        }