public static OneNewsViewModel Initialize(this OneNewsViewModel model, News news, ITagTranslator tagTranslator, ITimestampFormatter timestampFormatter)
        {
            model.Key       = news.Id;
            model.Title     = news.Title;
            model.Tag       = tagTranslator.ToTag(news.Tag);
            model.TagInfo   = news.Tag;
            model.Timestamp = timestampFormatter.Format(news.Timestamp);
            model.ImageSrc  = news.ImageSrc;
            model.Text      = news.Text;

            return(model);
        }
示例#2
0
        public async Task <IActionResult> Show(int year, int month, int day, string url)
        {
            long dateStart;
            long dateEnd;

            try
            {
                dateStart = new DateTimeOffset(new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Utc))
                            .ToUnixTimeSeconds();
                dateEnd = new DateTimeOffset(new DateTime(year, month, day, 23, 59, 59, DateTimeKind.Utc))
                          .ToUnixTimeSeconds();
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Bad date creation: {ex.Message}");
                return(new BadRequestResult());
            }

            var news = await Mediator.Send(
                new GetOneNewsQuery(url)
            {
                WithUnPublishedNews = await HasRight(UserRights.News),
                DateStart           = dateStart,
                DateEnd             = dateEnd
            });

            if (news == null)
            {
                return(StatusCode(404));
            }

            var viewModel = new OneNewsViewModel(ViewModelConfig, news);

            viewModel.BreadCrumbs.Add(new BreadCrumbsItem(Url.News().IndexUrl(), "Новости"));
            viewModel.BreadCrumbs.Add(new BreadCrumbsItem(Url.News().ParentNewsUrl(news), news.Parent.DisplayTitle));
            return(View(viewModel));
        }