public MaterialResponseDTO Create(CreateMaterialRequestDTO requestDTO) { if (this.FindOneBySectionAndFile(requestDTO.sectionUUID, requestDTO.fileUUID) != null) { throw new EntityNotFoundException($"Section with uuid: {requestDTO.sectionUUID} and file with uuid: {requestDTO.fileUUID} already exists!", GeneralConsts.MICROSERVICE_NAME); } FileDTO file = this._httpClientService.SendRequest <FileDTO>(HttpMethod.Get, "http://localhost:40003/api/files/" + requestDTO.fileUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result; if (file == null) { throw new EntityAlreadyExistsException($"File with uuid {requestDTO.fileUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME); } Material material = new Material() { section = new Section() { uuid = requestDTO.sectionUUID }, file = new File() { uuid = requestDTO.fileUUID, filePath = file.filePath }, visible = requestDTO.visible }; material = this._queryExecutor.Execute <Material>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.ADD_FILE_TO_SECTION(material), this._modelMapper.MapToMaterial); MaterialResponseDTO response = this._autoMapper.Map <MaterialResponseDTO>(material); response.file = file; response.section = this._sectionService.GetSectionByUuid(requestDTO.sectionUUID); return(response); }
public ActionResult <MaterialResponseDTO> HandleCreateMaterial(CreateMaterialRequestDTO requestDTO) { return(Ok(this._materialService.Create(requestDTO))); }