Ejemplo n.º 1
0
        // GET: Articles/Edit/5
        public async Task <IActionResult> Edit(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                var article = await _context.Articles
                              .Include(a => a.Author)
                              .Include(a => a.Category)
                              .FirstOrDefaultAsync(m => m.Id == id);

                if (article == null)
                {
                    return(NotFound());
                }

                //ovde je Tag objekat ocitan
                var articleTags = _articleRepository.GetArticleTagsForArticleId((long)id);
                var tags        = articleTags.Select(at => at.Tag.Name).ToList();

                CreateArticleViewModel model = _articleFactory.CreateArticleViewModel_Edit(article);

                ViewData["Tags"] = new SelectList(model.Tags, "Name");
                //selected value je ok
                ViewData["Category"] = new SelectList(_context.Categories, "Id", "Name");

                return(View("Edit", model));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(RedirectToAction("Index", "Error"));
            }
        }