Exemplo n.º 1
0
        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)));
        }