Beispiel #1
0
        public async Task <DepartmentProjection> CreateDepartment([FromBody] CreateDepartmentDTO input)
        {
            var command = new CreateDepartmentCommand(input);
            var result  = await _commandDispatcher.Execute(command);

            return(result);
        }
        public async Task <IActionResult> Create([FromBody] CreateDepartmentDTO dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            var department = _mapper.Map <Department>(dto);

            await _departmentRepo.AddAsync(department);

            await _departmentRepo.SaveChangesAsync();

            return(CreatedAtRoute("GetDepartment", new { id = department.ID }, _mapper.Map <DepartmentDTO>(department)));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([FromBody] CreateDepartmentDTO dto)
        {
            // check if instructor exists
            if (!_instructorRepo.Get(dto.InstructorID).Any())
            {
                ModelState.AddModelError("InstructorID", "InstructorID does not exist.");
                return(BadRequest(ModelState));
            }

            var department = _mapper.Map <Department>(dto);
            await _departmentRepo.AddAsync(department);

            await _departmentRepo.SaveChangesAsync();

            return(CreatedAtRoute("GetDepartment", new { id = department.ID }, _mapper.Map <DepartmentDTO>(department)));
        }
Beispiel #4
0
        public async void given_create_department_command_command_dispatcher_should_get_same_command_created_in_controller()
        {
            var mockAgg = new DepartmentControllerMockAggregate();

            var controller = mockAgg.DepartmentControllerFactory();

            var input = new CreateDepartmentDTO
            {
                Name = "testName",
            };

            var command = new CreateDepartmentCommand(input);

            mockAgg.setup_dispatcher_to_verify_createDepartmentCommands_are_the_same(command);

            var result = await controller.CreateDepartment(input);

            //Assert
            Assert.IsType <DepartmentProjection>(result);
            Assert.Equal(result.Name, input.Name);
        }
Beispiel #5
0
 public CreateDepartmentCommand(CreateDepartmentDTO input)
 {
     Input = input;
 }