public async Task <IActionResult> UpdateUserJob(int id, UserJobUpdateDto userJobUpdateDto) { try { var user = await UserRepo.GetUser(id); var performance = await PerformanceRepo.GetPerformance(id); if (performance != null) { if (user.JobLevel != userJobUpdateDto.JobLevel) { performance.LastPromotionUpdate = DateTime.Now; await PerformanceRepo.SubmitUserPerformance(performance); } if (user.JobRole != userJobUpdateDto.JobRole) { performance.LastRoleUpdate = DateTime.Now; await PerformanceRepo.SubmitUserPerformance(performance); } if (user.ManagerId != userJobUpdateDto.ManagerId) { performance.LastManagerUpdate = DateTime.Now; await PerformanceRepo.SubmitUserPerformance(performance); } } else { performance = new UserPerformance { LastManagerUpdate = DateTime.Now, LastRoleUpdate = DateTime.Now, LastPromotionUpdate = DateTime.Now, UserId = id }; await PerformanceRepo.SubmitUserPerformance(performance); } await UserRepo.UpdateUserJob(id, userJobUpdateDto); return(Ok( new { id, userJobUpdateDto } )); } catch (Exception) { return(StatusCode(500, "Could not send feedback. Please try again later!")); } }
public async Task <bool> UpdateUserJob(int userId, UserJobUpdateDto userJobUpdateDto) { try { var user = await Context.Users.Where(u => u.Id == userId).FirstOrDefaultAsync(); user.JobRole = userJobUpdateDto.JobRole; user.JobLevel = userJobUpdateDto.JobLevel; user.Department = userJobUpdateDto.Department; user.ManagerId = userJobUpdateDto.ManagerId; await SaveAll(); return(true); } catch (Exception) { return(false); } }