public async Task <IHttpActionResult> PutProfessor(ProfessorUpdateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var professor = await _professors.Find(model.Id);

                professor.SSN          = model.SSN;
                professor.Name         = model.Name;
                professor.UserName     = professor.Email = model.Email;
                professor.PhoneNumber  = model.PhoneNumber;
                professor.DepartmentId = model.DepartmentId;

                await _professors.Update(professor);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_professors.Exists(model.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public async Task Update_ShouldReturnInstanceOfProfessorDetailsDto()
        {
            // Arrange
            _mockProfessorMapper.Setup(mapper => mapper.Map(_professor1.Id, _professorCreatingDto)).Returns(_professorDetailsDto1);
            _mockReadRepository.Setup(repo => repo.GetByIdAsync <Professor>(_professor1.Id)).ReturnsAsync(_professor1);
            // Act
            ProfessorDetailsDto actualProfessor = await _professorService.Update(_professor1.Id, _professorCreatingDto);

            // Assert
            actualProfessor.Should().BeEquivalentTo(_professorDetailsDto1);
        }