示例#1
0
        public IActionResult Edit(int id)
        {
            var entity = _newsItemRepository.Get(id);

            CheckIfNotNull(entity);

            var model = _mapper.Map <EditNewsItemVM>(entity);

            return(View(model));
        }
        public async Task <IActionResult> Details(string id)
        {
            // Parse everything till the first '-' as integer into `caseId`
            int.TryParse(id.Split('-', 2)[0], out int newsItemId);

            var newsItem = await _newsItemRepository.Get(newsItemId);

            if (newsItem == null || newsItem.Deleted || !newsItem.Enabled)
            {
                return(NotFound());
            }

            var language = HttpContext?.Features?.Get <IRequestCultureFeature>()?.RequestCulture?.Culture
                           ?.TwoLetterISOLanguageName ?? "nl";

            if (newsItem.Language != language)
            {
                int itemTranslationId;
                itemTranslationId = language == "nl" ?
                                    (await _itemTranslationRepository.GetAllNewsitems()).FirstOrDefault(n => n.IdEn == newsItem.Id).IdNl :
                                    (await _itemTranslationRepository.GetAllNewsitems()).FirstOrDefault(n => n.IdNl == newsItem.Id).IdEn;
                newsItem = await _newsItemRepository.Get(itemTranslationId);
            }
            if (newsItem == null || newsItem.Deleted || !newsItem.Enabled)
            {
                return(NotFound());
            }

            // Force the right slug
            if (id != newsItem.Slug)
            {
                return(RedirectToAction("Details", new { id = newsItem.Slug }));
            }

            var relatedItems = await _relatedItemsRepository.GetRelatedItems(newsItem.Id, Enumeration.ContentItemType.NewsItem, language);

            return(View(new NewsItemDetailViewModel
            {
                NewsItem = newsItem,
                ContentItems = relatedItems,
            }));
        }
示例#3
0
        public async Task <IActionResult> NewsItems(string ids)
        {
            var intIds       = (ids ?? "").Split(",").Where(s => int.TryParse(s.Trim(), out var _)).Select(s => int.Parse(s.Trim())).ToList();
            var currentItems = await _newsItemRepository.GetHomepageItems("nl");

            var newsItems = new List <NewsItem>();

            for (var i = 0; i < intIds.Count; i++)
            {
                var newsItem = currentItems.FirstOrDefault(n => n.Id == intIds[i]) ?? await _newsItemRepository.Get(intIds[i]);

                newsItem.HomepageOrder = i;
                await _newsItemRepository.Update(newsItem);

                newsItems.Add(new NewsItem
                {
                    Id            = newsItem.Id,
                    Title         = newsItem.Title,
                    Date          = newsItem.Date,
                    PhotoPath     = newsItem.PhotoPath,
                    HomepageOrder = newsItem.HomepageOrder
                });
            }

            foreach (var newsItem in currentItems.Where(n => !intIds.Contains(n.Id)))
            {
                newsItem.HomepageOrder = null;
                await _newsItemRepository.Update(newsItem);
            }

            foreach (var item in await _newsItemRepository.GetHomepageItems("en"))
            {
                item.HomepageOrder = null;
                await _newsItemRepository.Update(item);
            }

            var newsItemIds         = newsItems.Select(n => n.Id);
            var translatedNewsItems = (await _itemTranslationRepository.GetAllNewsitems())
                                      .Where(n => newsItemIds.Contains(n.IdNl));

            foreach (var translation in translatedNewsItems)
            {
                var translatedNewsItem = await _newsItemRepository.Get(translation.IdEn);

                if (translatedNewsItem == null)
                {
                    continue;
                }
                translatedNewsItem.HomepageOrder = newsItems.First(n => n.Id == translation.IdNl).HomepageOrder;
                await _newsItemRepository.Update(translatedNewsItem);
            }

            return(View(newsItems));
        }
示例#4
0
 public async Task <IActionResult> TranslationEdit(int id)
 {
     return(View(await _newsItemRepository.Get(id)));
 }