public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Department department) { if (id != department.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(department); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Edit(int id, Vote vote) { if (id != vote.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vote); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VoteExists(vote.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FeedbackId"] = new SelectList(_context.Feedbacks, "Id", "Name", vote.FeedbackId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Login", vote.UserId); return(View(vote)); }
public async Task <IActionResult> UpdateVote(int feedback, int vote) { var user = await _context.Users.SingleOrDefaultAsync(u => u.Login == User.Identity.Name); if (user.VotesCounter > 0) { user.VotesCounter--; _context.Update(user); await _context.SaveChangesAsync(); Vote model = new Vote { RatingGiven = vote, UserId = user.Id, FeedbackId = feedback, Time = DateTime.Now, VoteReturned = false }; _context.Votes.Add(model); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, [Bind("ID,EmpName,EmpDept")] Class @class) { if (id != @class.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(@class); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClassExists(@class.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(@class)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReleaseDate,Genre,Price")] Movie movie) { if (id != movie.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,Patronymic,LastName,Login,Password,RoleId,VotesCounter")] User user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Roles, "Id", "Name", user.RoleId); return(View(user)); }
public async Task <ActionResult <Employee> > Put(Employee employee) { _dataContext.Update(employee); await _dataContext.SaveChangesAsync(); return(NoContent()); }
public void Update(Job obj) { if (!_context.Job.Any(x => x.Id == obj.Id)) { } _context.Update(obj); _context.SaveChanges(); }
public async Task EnsureUpdatedAsync(string login) { var user = await _context.Users.SingleOrDefaultAsync(u => u.Login == login); var votes = _context.Votes.Where(m => m.UserId == user.Id && m.VoteReturned == false); var selectedUser = await _context.Users.SingleOrDefaultAsync(u => u.Login == login); foreach (var vote in votes) { var difference = (DateTime.Now - vote.Time).TotalDays; if (difference >= 3) { // updating VoteReturned state vote.VoteReturned = true; _context.Update(vote); // updating VotesCounter of user selectedUser.VotesCounter++; _context.Update(selectedUser); } } _context.SaveChanges(); }
public void Update(Vendedor obj) { if (!_context.Vendedor.Any(x => x.Id == obj.Id)) { throw new NotFoundException("Id não encontrado"); } try { _context.Update(obj); _context.SaveChanges(); } catch (DbUpdateConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }
public async Task UpdateAsync(Seller obj) { bool hasAny = await _context.Seller.AnyAsync(x => x.Id == obj.Id); if (!hasAny) { throw new NotFoundException("Id not found"); } try { _context.Update(obj); await _context.SaveChangesAsync(); } catch (DbConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }