Esempio n. 1
0
        public async Task <IActionResult> Edit(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                var article = await articlesRepository.FindByIdAsync(id);

                var user = await userManager.GetUserAsync(User);

                if ((article.User != null && article.User.Id == user.Id) || User.IsInRole(UserRole.Administrator))
                {
                    return(View("Create", new ArticleViewModel
                    {
                        Article = article,
                        Categories = categoriesRepository.FindAll().Select(c => new SelectListItem
                        {
                            Value = c.Id.ToString(),
                            Text = c.Title
                        }),
                        Tags = tagsRepository.FindAll().Select(t => new SelectListItem
                        {
                            Value = t.Id.ToString(),
                            Text = t.Title
                        }),
                        SelectedTags = string.Join(", ", article.ArticleTags.Select(t => t.Tag.Title))
                    }));
                }
            }

            TempData.AddErrorMessage("Nemáte dostatečná oprávnění pro úpravu tohoto článku.");
            return(RedirectToAction("Detail", new { id }));
        }