Пример #1
0
        public async Task <ObjectResult> EditTranslationPost(int?id)
        {
            var newsItem = await _newsItemRepository.Get(id ?? 0, true);

            if (newsItem == null)
            {
                return(new NotFoundObjectResult(null));
            }

            // Bind POST variables Title, CustomerId, Image and TagIds to the model.
            await TryUpdateModelAsync(newsItem, string.Empty, n => n.Title, n => n.SharingDescription);

            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(ModelState));
            }

            try
            {
                newsItem.LastModified = DateTime.UtcNow;
                await _newsItemRepository.Update(newsItem);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await NewsItemExists(newsItem.Id))
                {
                    return(new NotFoundObjectResult(null));
                }

                throw;
            }

            return(new ObjectResult(newsItem.Id));
        }
Пример #2
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));
        }
Пример #3
0
        public ValidationDictionary <ViewModelNewsItem> DeleteNewsItem(int clientId, int newsId)
        {
            var raw = _newsRepository.FindBy(o => o.NewsId == newsId && o.ClientId == clientId);

            var validator = new ValidationDictionary <ViewModelNewsItem>();

            if (raw != null)
            {
                raw.IsDeleted = true;

                _newsRepository.Update(raw);

                validator.IsValid = true;
            }
            else
            {
                validator.IsValid = false;
                validator.AddError("", "The News is not available in the database");
            }

            return(validator);
        }
Пример #4
0
        public IActionResult Edit(EditNewsItemVM model)
        {
            if (ModelState.IsValid)
            {
                var entity = _newsItemRepository.Get(model.Id);
                CheckIfNotNull(entity);

                entity = _mapper.Map(model, entity);
                _imageService.Upload(entity, model.File, EImageType.NewsItem);
                _newsItemRepository.Update(entity);
                _unitOfWork.Commit();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }