Пример #1
0
        public async Task <IActionResult> UpdateDistrictSchool([FromQuery] Guid id, [FromBody] DistrictSchoolDto districtSchoolDto)
        {
            try
            {
                if (districtSchoolDto == null)
                {
                    _loggerManager.LogError("DistrictSchoolDto object sent from client is null.");
                    return(BadRequest("DistrictSchoolDto object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _loggerManager.LogError("Invalid DistrictSchoolDto object sent from client.");
                    return(BadRequest("Invalid DistrictSchoolDto model object"));
                }
                var dbDistrictSchoolDto = await _repositoryWrapper.DistrictSchool.GetDistrictSchoolById(id);

                if (dbDistrictSchoolDto.IsEmptyObject())
                {
                    _loggerManager.LogError($"School with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }
                var districtSchool = _mapper.Map <DistrictSchool>(districtSchoolDto);
                await _repositoryWrapper.DistrictSchool.UpdateDistrictSchool(dbDistrictSchoolDto, districtSchool);

                return(NoContent());
            }
            catch (Exception ex)
            {
                _loggerManager.LogError($"Something went wrong inside UpdateDistrictSchool action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Пример #2
0
        public async Task <IActionResult> CreateDistrictSchool([FromBody] DistrictSchoolDto districtSchoolDto)
        {
            try
            {
                if (districtSchoolDto == null)
                {
                    _loggerManager.LogError("DistrictSchoolDto sent from client is null.");
                    return(BadRequest("DistrictSchoolDto object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _loggerManager.LogError("Invalid DistrictSchoolDto sent from client.");
                    return(BadRequest("Invalid DistrictSchoolDto model object"));
                }
                var districtSchool = _mapper.Map <DistrictSchool>(districtSchoolDto);
                await _repositoryWrapper.DistrictSchool.CreateDistrictSchool(districtSchool);

                if (districtSchool.IsEmptyObject())
                {
                    _loggerManager.LogError($"Save operation failed inside CreateDistrictSchool action");
                    return(StatusCode(500, "Internal server error while saving School "));
                }
                var dbObject = await _repositoryWrapper.DistrictSchool.GetDistrictSchoolById(districtSchool.Id);

                return(Ok(dbObject));
            }
            catch (Exception ex)
            {
                _loggerManager.LogError($"Something went wrong inside CreateDistrictSchool action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public void UpdateDistrictSchool()
        {
            // Arrange
            var schoolStudentDto = new DistrictSchoolDto
            {
                EndDate    = DateTime.UtcNow,
                StartDate  = DateTime.UtcNow,
                SchoolId   = DataSeeder.SchoolSeeder.Objects[0].Id,
                DistrictId = _districtSeeder.Objects[0].Id
            };
            var schoolStudent = _mapper.Map <DistrictSchool>(schoolStudentDto);

            Mock.Get(_repositoryWrapper.DistrictSchool).Setup(x => x.UpdateDistrictSchool(schoolStudent, schoolStudent));
            Mock.Get(_repositoryWrapper.DistrictSchool).Setup(x => x.GetDistrictSchoolById(schoolStudent.Id)).ReturnsAsync(schoolStudent);
            var controller = new DistrictSchoolController(_loggerManager, _mapper, _repositoryWrapper);
            // Act
            var actionResult = controller.UpdateDistrictSchool(schoolStudent.Id, schoolStudentDto).Result;
            // Assert
            var noContentResult = actionResult as NoContentResult;

            Assert.IsNotNull(noContentResult);
        }
        public void CreateDistrictSchool()
        {
            // Arrange
            var districtSchoolDto = new DistrictSchoolDto
            {
                EndDate    = DateTime.UtcNow,
                StartDate  = DateTime.UtcNow,
                SchoolId   = DataSeeder.SchoolSeeder.Objects[0].Id,
                DistrictId = _districtSeeder.Objects[0].Id
            };
            var districtSchool = _mapper.Map <DistrictSchool>(districtSchoolDto);

            Mock.Get(_repositoryWrapper.DistrictSchool).Setup(x => x.CreateDistrictSchool(districtSchool));
            Mock.Get(_repositoryWrapper.DistrictSchool).Setup(x => x.GetDistrictSchoolById(districtSchool.Id)).ReturnsAsync(districtSchool);
            var controller = new DistrictSchoolController(_loggerManager, _mapper, _repositoryWrapper);
            // Act
            var actionResult = controller.CreateDistrictSchool(districtSchoolDto).Result;
            // Assert
            var okObjectResult = actionResult as OkObjectResult;

            Assert.IsNotNull(okObjectResult);
        }