コード例 #1
0
ファイル: HomeController.cs プロジェクト: zokaan/News-Project
 public IActionResult Update(NewsUpdateDTO news)
 {
     if (ModelState.IsValid)
     {
         News updatedNews = _newsRepository.Update(news);
         return(RedirectToAction("details", new { id = updatedNews.Id }));
     }
     else
     {
         return(View());
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: zokaan/News-Project
        public ViewResult Update(int id)
        {
            NewsUpdateDTO news = _newsRepository.GetUpdate(id);

            return(View(news));
        }