コード例 #1
0
ファイル: CategoryController.cs プロジェクト: jjosipa404/PMA
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Category category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CatExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
ファイル: CommentsController.cs プロジェクト: jjosipa404/PMA
        public async Task <IActionResult> Edit(int id, [Bind("Id,CommContent,PostId,UserId")] Comment comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    comment.DateCreated = DateTime.Now;
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("PostDetailsPage", "PostDetailsPage", new { id = comment.PostId }));
            }
            ViewData["PostId"] = new SelectList(_context.Set <Post>(), "Id", "Id", comment.PostId);
            ViewData["UserId"] = new SelectList(_context.Set <ApplicationUser>(), "Id", "Id", comment.UserId);
            return(View(comment));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Content,AuthorId,CategoryId,ApprovedId")] Post post)
        {
            if (IsInRank("admin") | IsInRank("editor") | IsInRank("author"))
            {
                if (id != post.Id)
                {
                    return(NotFound());
                }
                var             userId   = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var             userName = User.FindFirstValue(ClaimTypes.Name);
                ApplicationUser appUser  = await _userManager.GetUserAsync(User);

                post.DateUpdated = DateTime.Now;
                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(post);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!PostExists(post.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    if (IsInRank("author"))
                    {
                        return(RedirectToAction("MyPosts", "Posts"));
                    }
                    else if (IsInRank("editor"))
                    {
                        return(RedirectToAction("AllPosts", "Posts"));
                    }
                }
                ViewData["CategoryId"] = new SelectList(_context.Set <Category>(), "Id", "Name", post.Category.Name);
                ViewData["AuthorId"]   = new SelectList(_context.Set <ApplicationUser>().Where(u => u.Rank.Name == "author"), "Id", "UserName", post.Author.UserName);
                ViewData["ApprovedId"] = new SelectList(_context.Set <Approved>(), "Id", "Name", post.Approved.Name);
                return(View(post));
            }
            return(RedirectToAction(nameof(Index)));
        }