public async Task <IActionResult> SendPost([FromRoute] int id, [FromForm, Bind(nameof(PostsSendViewModel.ChannelId), nameof(PostsSendViewModel.Schedule), nameof(PostsSendViewModel.ScheduleDate))] PostsSendViewModel model)
        {
            if (model.Schedule && model.ScheduleDate.HasValue)
            {
                model.ScheduleDate = TimezoneHelper.ConvertTimeToUtcByIanaTimeZoneId(
                    DateTime.SpecifyKind(model.ScheduleDate.Value, DateTimeKind.Unspecified),
                    TimezoneHelper.WindowsToIana(
                        await SettingManager.GetSettingValueAsync(TimingSettingNames.TimeZone)));

                await _scheduleService.Create(new ScheduleItemDto {
                    PostId       = id,
                    ChannelId    = model.ChannelId,
                    ScheduleDate = model.ScheduleDate.Value
                });

                return(RedirectToAction(nameof(Index)));
            }
            var post = await _postApplicationService.GetById(id);

            if (post == null)
            {
                return(NotFound());
            }
            var channel = await _channelApplicationService.Get(new EntityDto <long>(model.ChannelId));

            if (channel == null)
            {
                return(NotFound());
            }
            await _bot.Client.SendTextMessageAsync(new ChatId(channel.Id), post.Body);

            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        protected override void DoWork()
        {
            var items = _scheduleService.GetItems(Clock.Now, 20);

            foreach (var item in items)
            {
                var post    = _postService.GetById(item.PostId).Result;
                var channel = _channelService.Get(new EntityDto <long>(item.ChannelId)).Result;
                if (post != null && (channel?.Own ?? false))
                {
                    _bot.Client.SendTextMessageAsync(new ChatId(channel.Id), post.Body).Wait();
                }
                item.Done = true;
                _scheduleService.Update(item).Wait();
            }
        }
        public async Task <IActionResult> Edit(long id)
        {
            var model = await _channelService.Get(new EntityDto <long>(id));

            return(View(model));
        }