public IActionResult Update(NewsUpdateDTO news) { if (ModelState.IsValid) { News updatedNews = _newsRepository.Update(news); return(RedirectToAction("details", new { id = updatedNews.Id })); } else { return(View()); } }
public NewsUpdateDTO GetUpdate(int id) { News news = _dbContext.News.Where(n => n.Id == id).FirstOrDefault(); NewsUpdateDTO updateNews = new NewsUpdateDTO { Id = news.Id, Title = news.Title, ShortDescription = news.ShortDescription, Content = news.Content, }; return(updateNews); }
public News Update(NewsUpdateDTO news) { News editNews = _dbContext.News.Where(n => n.Id == news.Id).FirstOrDefault(); if (editNews != null) { editNews.Title = news.Title; editNews.ShortDescription = news.ShortDescription; editNews.Content = news.Content; if (news.ImageFile != null) { editNews.Image = UploadedImage(news); } _dbContext.SaveChanges(); } return(editNews); }
public async Task <ActionResult <NewsUpdateDTO> > PutGet(int id) { var model = await Get(id); if (model.Result is NotFoundResult) { return(NotFound()); } var modelDetailDTO = model.Value; var selectedCategoriesIds = modelDetailDTO.Categories.Select(o => o.Id).ToList(); var notSelectedCategories = await _context.Categories.Where(o => !selectedCategoriesIds.Contains(o.Id)).ToListAsync(); var newsModel = new NewsUpdateDTO(); newsModel.News = modelDetailDTO.News; newsModel.SelectedCategories = modelDetailDTO.Categories; newsModel.NotSelectedCategories = notSelectedCategories; newsModel.Managers = modelDetailDTO.Managers; newsModel.Images = modelDetailDTO.Images; return(newsModel); }
public ViewResult Update(int id) { NewsUpdateDTO news = _newsRepository.GetUpdate(id); return(View(news)); }