public DepartmentResponseDTO Create(CreateDepartmentRequestDTO requestDTO) { if (this._facultyService.GetOneByUuid(requestDTO.facultyUUID) == null) { throw new EntityNotFoundException($"Faculty with uuid {requestDTO.facultyUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME); } if (this.FindOneByNameAndfaculty(requestDTO.name, requestDTO.facultyUUID) != null) { throw new EntityNotFoundException($"Department with name {requestDTO.name} with facultyUUID {requestDTO.facultyUUID} already exists!", GeneralConsts.MICROSERVICE_NAME); } Faculty faculty = this._autoMapper.Map <Faculty>(this._facultyService.GetOneByUuid(requestDTO.facultyUUID)); Department department = new Department() { name = requestDTO.name, faculty = faculty }; department = this._queryExecutor.Execute <Department>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.CREATE_DEPARTMENT(department), this._modelMapper.MapToDepartmentAfterInsert); department = this._queryExecutor.Execute <Department>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_DEPARTMENT_BY_UUID(department.uuid), this._modelMapper.MapToDepartment); return(this._autoMapper.Map <DepartmentResponseDTO>(department)); }
public ActionResult <DepartmentResponseDTO> HandleCreateDepartment(CreateDepartmentRequestDTO requestDTO) { return(Ok(this._departmentService.Create(requestDTO))); }