public async Task PutDepartmentAsync(DepartmentV1DTO departmentDTO) { var department = await _context.Department .Where(d => d.DepartmentId == departmentDTO.DepartmentId) .SingleOrDefaultAsync(); _context.Entry(department).CurrentValues.SetValues(departmentDTO); await _context.SaveChangesAsync(); }
public void Department_should_not_have_errors() { var dept = new DepartmentV1DTO(); dept.DepartmentCode = 1; dept.DepartmentName = "some name"; var deptResult = DepartmentVal.TestValidate(dept); deptResult.ShouldNotHaveValidationErrorFor(x => x.DepartmentName); deptResult.ShouldNotHaveValidationErrorFor(x => x.DepartmentCode); }
public async Task <IActionResult> PutDepartment(int departmentId, [FromBody] DepartmentV1DTO departmentDTO) { try { // Check to ensure service exists before calling contextmanager method. var department = await _contextManager.GetDepartmentByIdAsync(departmentId); if (department == null) { return(NotFound()); } departmentDTO.DepartmentId = departmentId; await _contextManager.PutDepartmentAsync(departmentDTO); return(NoContent()); } catch (Exception e) { throw e; } }