Exemplo n.º 1
0
        public async Task Solutions(string ids)
        {
            var intIds = (ids ?? "").Split(",").Where(s => int.TryParse(s.Trim(), out var _))
                         .Select(s => int.Parse(s.Trim())).ToList();
            var solutions = await _solutionRepository.GetAll().ToListAsync();

            var translations = await _itemTranslationRepository.GetAllSolutions();

            for (var i = 0; i < intIds.Count; i++)
            {
                var solution = solutions.FirstOrDefault(s => s.Id == intIds[i]);
                if (solution == null)
                {
                    continue;
                }

                solution.HomepageOrder = i;
                await _solutionRepository.Update(solution);

                var translation = translations.First(t => t.IdNl == intIds[i]);
                if (translation.IdEn != 0)
                {
                    var translatedSolution = solutions.First(s => s.Id == translation.IdEn);
                    if (translatedSolution == null)
                    {
                        continue;
                    }
                    translatedSolution.HomepageOrder = i;
                    await _solutionRepository.Update(translatedSolution);
                }
            }
        }
        public async Task <IActionResult> Details(string id)
        {
            // Parse everything till the first '-' as integer into `solutionId`
            int.TryParse(id.Split('-', 2)[0], out int solutionId);

            var solutionItem = await _solutionRepository.Get(solutionId, false);

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

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

            if (solutionItem.Language != language)
            {
                int itemTranslationId;
                itemTranslationId = language == "nl" ?
                                    (await _itemTranslationRepository.GetAllSolutions()).FirstOrDefault(s => s.IdEn == solutionItem.Id).IdNl :
                                    (await _itemTranslationRepository.GetAllSolutions()).FirstOrDefault(s => s.IdNl == solutionItem.Id).IdEn;
                solutionItem = await _solutionRepository.Get(itemTranslationId);
            }
            if (solutionItem == null || solutionItem.Deleted || !solutionItem.Enabled)
            {
                return(NotFound());
            }

            if (id != solutionItem.Slug)
            {
                return(RedirectToAction("Details", new { id = solutionItem.Slug }));
            }

            var relatedItems =
                await _relatedItemsRepository.GetRelatedItems(solutionItem.Id, Enumeration.ContentItemType.Solution, language);

            var relatedCustomers = solutionItem.CustomerSolutions.Select(cs => cs.Customer).Where(c => !c.Deleted && c.Enabled).Take(12).ToList();

            return(View(new SolutionDetailViewModel
            {
                Solution = solutionItem,
                ContentItems = relatedItems,
                Customers = relatedCustomers
            }));
        }