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 (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,CommentId,DateOfAddition")] Point point) { if (id != point.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(point); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PointExists(point.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CommentId"] = new SelectList(_context.Comment, "Id", "Title", point.CommentId); ViewData["UserId"] = new SelectList(_context.User, "Id", "Nick", point.UserId); return(View(point)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TagId,PostId")] PostTag postTag) { if (id != postTag.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(postTag); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostTagExists(postTag.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PostId"] = new SelectList(_context.Post, "Id", "Title", postTag.PostId); ViewData["TagId"] = new SelectList(_context.Tag, "Id", "Name", postTag.TagId); return(View(postTag)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Login,Password,Nick,LastPasswordChangedDate,RegistrationDate")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { User u = new User(); u = user; user = await _context.User .FirstOrDefaultAsync(m => m.Id == id); if (u.Password != user.Password) { u.LastPasswordChangedDate = DateTime.Now; } if (!u.LastPasswordChangedDate.ToString().Equals("01.01.0001 00:00:00")) { user.LastPasswordChangedDate = u.LastPasswordChangedDate; } user.Login = u.Login; user.Nick = u.Nick; _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Content,PostId,CreatorId,CreationDate,LastEditionDate")] Comment comment) { if (id != comment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { comment.LastEditionDate = DateTime.Now; Comment c = new Comment(); c = comment; comment = await _context.Comment .Include(c => c.Creator) .Include(c => c.Post) .FirstOrDefaultAsync(m => m.Id == id); comment.LastEditionDate = c.LastEditionDate; comment.Content = c.Content; System.Diagnostics.Debug.WriteLine(comment.LastEditionDate.ToString() + " " + comment.CreationDate.ToString() + " " + c.LastEditionDate.ToString() + " " + c.CreationDate.ToString()); _context.Update(comment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(comment.Id)) { return(NotFound()); } else { throw; } } return(Redirect("/Posts/Details/" + comment.PostId)); } ViewData["CreatorId"] = new SelectList(_context.User, "Id", "Nick", comment.CreatorId); ViewData["PostId"] = new SelectList(_context.Post, "Id", "Title", comment.PostId); return(View(comment)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Content,CreatorId,CategoryId,LastEditionDate")] Post post) { if (id != post.Id) { return(NotFound()); } if (ModelState.IsValid) { try { post.LastEditionDate = DateTime.Now; Post p = new Post(); p = post; post = await _context.Post .Include(p => p.Category) .Include(p => p.Creator) .FirstOrDefaultAsync(m => m.Id == id); post.Content = p.Content; post.Title = p.Title; post.LastEditionDate = p.LastEditionDate; _context.Update(post); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(post.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", post.CategoryId); ViewData["CreatorId"] = new SelectList(_context.User, "Id", "Nick", post.CreatorId); return(View(post)); }