Exemplo n.º 1
0
        public NewsItemViewModel GetNewsItemViewModel(NewsItem newsItem)
        {
            if (newsItem == null)
            {
                return(null);
            }

            var filesResult = new List <FileViewModel>();
            var files       = _uploadService.GetFilesByNewsId(newsItem.Id).ToList();

            foreach (var newsItemFile in files)
            {
                filesResult.Add(GetDownloadedFileViewModel(newsItemFile));
            }

            string categoryName = "";

            if (newsItem.Category != null)
            {
                var cat = _menuService.Get(newsItem.Category);
                categoryName = cat == null ? "" : cat.Name;
            }

            return(new NewsItemViewModel()
            {
                Id = newsItem.Id,
                Header = string.IsNullOrWhiteSpace(newsItem.Header) ? "" : newsItem.Header,
                Description = string.IsNullOrWhiteSpace(newsItem.Description) ? "" : newsItem.Description,
                CategoryId = newsItem.Category,
                Category = categoryName,
                Author = newsItem.AutorFio,
                CreatedDate = newsItem.CreatedDate,
                LastChangeDate = newsItem.LastChangeDate,
                Files = filesResult,
                IsMessage = !filesResult.Any()
            });
        }