public async Task <IActionResult> PutTask(int id, Task task) { /*if (id != task.Id) * { * return BadRequest(); * }*/ var editTask = await _context.Task.FindAsync(id); if (editTask == null) { return(BadRequest()); } if (task.Assignee != null && editTask.Assignee != task.Assignee) { var tasks = _context.Task.Where(t => t.Assignee == task.Assignee); if (tasks.Count() == 3) { return(BadRequest("Selected developer already have 3 tasks!")); } } editTask.Description = task.Description; editTask.Deadline = task.Deadline; editTask.Assignee = task.Assignee; editTask.ProjectId = task.ProjectId; editTask.Status = task.Status; editTask.Progress = task.Progress; _context.Entry(editTask).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutUser(string id, User user) { /*if (id != user.Username) * { * return BadRequest(); * }*/ var editUser = await _context.User.FindAsync(id); if (editUser == null) { return(BadRequest()); } editUser.Email = user.Email; editUser.Name = user.Name; editUser.Surname = user.Surname; editUser.Role = user.Role; _context.Entry(editUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProject(Guid id, Project project) { /*if (id != project.Code) * { * return BadRequest(); * }*/ var editProject = await _context.Project.FindAsync(id); if (editProject == null) { return(BadRequest()); } editProject.Assignee = project.Assignee; editProject.Name = project.Name; _context.Entry(editProject).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <bool> > ChangePassword(ChangePasswordDTO user) { if (user == null) { return(BadRequest("User not found!")); } var editUser = await _context.User.FindAsync(user.Username); if (editUser == null) { return(NotFound("User not found!")); } if (!VerifyPassword(editUser.Password, user.OldPassword)) { return(BadRequest("Wrong Old Password!")); } _context.Entry(editUser).State = EntityState.Modified; editUser.Password = HashPassword(user.NewPassword); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Username)) { return(NotFound()); } else { throw; } } return(true); }