public async Task <ObjectResult> SolutionAdvantages(Enumeration.ContentItemType contentType, int contentId, int id, List <string> advantages) { var block = await _blockRepository.Get(id); if (!(block is SolutionAdvantagesBlock saBlock)) { return(new NotFoundObjectResult(null)); } saBlock.Advantages = advantages; await TryUpdateModelAsync(saBlock, string.Empty, s => s.Order, s => s.Image); ValidateImageExtension(saBlock.Image, nameof(saBlock.Image)); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } if (saBlock.Image != null) { if (saBlock.PhotoPath != null) { await _uploadService.Delete(saBlock.PhotoPath); } saBlock.PhotoPath = await _uploadService.Upload(saBlock.Image, "/images/uploads"); } SetTypeId(block, contentType, contentId); saBlock.Active = true; saBlock.LastModified = DateTime.UtcNow; await _blockRepository.Update(saBlock); return(new OkObjectResult(null)); }
public async Task <List <ContentItem> > GetRelatedItems(int id, Enumeration.ContentItemType type, string language) { var contentItems = new List <ContentItem>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { command.CommandText = string.Format(RelatedItemQuery, type.ToString()); command.Parameters.Add(new SqlParameter("id", id)); command.Parameters.Add(new SqlParameter("language", language)); await _context.Database.OpenConnectionAsync(); using (var result = await command.ExecuteReaderAsync()) { while (await result.ReadAsync()) { contentItems.Add(new ContentItem { Type = Enum.Parse <Enumeration.ContentItemType>(result["type"] as string), Id = (int)result["Id"], Title = result["Title"] as string, PhotoPath = result["PhotoPath"] as string, Score = decimal.ToDouble(result["Score"] as decimal? ?? 0), }); } } } return(contentItems); }
public async Task <IActionResult> Text(Enumeration.ContentItemType contentType, int contentId) { var block = new TextBlock(); SetTypeId(block, contentType, contentId); block.LastModified = block.Date = DateTime.UtcNow; await _blockRepository.Create(block); return(ViewComponent("Block", block)); }
public async Task <ObjectResult> Carousel(Enumeration.ContentItemType contentType, int contentId, int id, List <SlideViewModel> slides) { var block = await _blockRepository.Get(id); if (!(block is CarouselBlock carousel)) { return(new NotFoundObjectResult(null)); } List <string> photoPaths = carousel.Slides.Select(s => s.PhotoPath).ToList(); await TryUpdateModelAsync(carousel, string.Empty, c => c.Order, c => c.LinkText, c => c.LinkPath); UpdateCarouselSlides(carousel, slides); for (var i = 0; i < slides.Count; i++) { ValidateImageExtension(slides[i].Image, $"Slides[{i}].Image"); } if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } foreach (var slide in carousel.Slides) { if (slide.Image != null) { if (slide.PhotoPath != null) { await _uploadService.Delete(slide.PhotoPath); } slide.PhotoPath = await _uploadService.Upload(slide.Image, "/images/uploads"); } } SetTypeId(block, contentType, contentId); carousel.Active = true; carousel.LastModified = DateTime.UtcNow; await _blockRepository.Update(carousel); var newPaths = carousel.Slides.Select(s => s.PhotoPath).ToList(); foreach (var photoPath in photoPaths) { if (!newPaths.Contains(photoPath)) { await _uploadService.Delete(photoPath); } } return(new OkObjectResult(null)); }
private void SetTypeId(Block block, Enumeration.ContentItemType type, int id) { switch (type) { case Enumeration.ContentItemType.Case: block.CaseId = id; break; case Enumeration.ContentItemType.NewsItem: block.NewsItemId = id; break; case Enumeration.ContentItemType.Solution: block.SolutionId = id; break; } }
public async Task <ObjectResult> Text(Enumeration.ContentItemType contentType, int contentId, int id) { var block = await _blockRepository.Get(id); if (!(block is TextBlock text)) { return(new NotFoundObjectResult(null)); } await TryUpdateModelAsync(text, string.Empty, t => t.Order, t => t.Text); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } SetTypeId(text, contentType, contentId); text.Active = true; text.LastModified = DateTime.UtcNow; await _blockRepository.Update(text); return(new OkObjectResult(null)); }
public async Task <ObjectResult> Quote(Enumeration.ContentItemType contentType, int contentId, int id) { var block = await _blockRepository.Get(id); if (!(block is QuoteBlock quote)) { return(new NotFoundObjectResult(null)); } await TryUpdateModelAsync(quote, string.Empty, q => q.Order, q => q.Author, q => q.Text); if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } SetTypeId(quote, contentType, contentId); quote.Active = true; quote.LastModified = DateTime.UtcNow; await _blockRepository.Update(quote); return(new OkObjectResult(null)); }