public SectionResponseDTO Update(UpdateSectionRequestDTO requestDTO) { if (this.FindSectionByUuid(requestDTO.uuid) == null) { throw new EntityNotFoundException($"Section with uuid: {requestDTO.uuid} does not exist!", GeneralConsts.MICROSERVICE_NAME); } CourseDTO course = this._httpClientService.SendRequest <CourseDTO>(HttpMethod.Get, "http://localhost:40005/api/courses/" + requestDTO.courseUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result; if (course == null) { throw new EntityNotFoundException($"Course with uuid {requestDTO.courseUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME); } Section section = new Section() { uuid = requestDTO.uuid, name = requestDTO.name, description = requestDTO.description, visible = requestDTO.visible, creationDate = requestDTO.creationDate, course = new Course() { uuid = requestDTO.courseUUID } }; CreateSectionArchiveRequestDTO archive = new CreateSectionArchiveRequestDTO() { sectionUUID = section.uuid, name = section.name, description = section.description, visible = section.visible, creationDate = section.creationDate, courseUUID = section.course.uuid, moderatorUUID = new UserPrincipal(_httpContextAccessor.HttpContext).uuid, changeDate = DateTime.Now }; section = this._queryExecutor.Execute <Section>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_SECTION(section), this._modelMapper.MapToSection); SectionResponseDTO response = this._autoMapper.Map <SectionResponseDTO>(section); response.course = course; _ = this._archiveService.Create(archive); return(response); }
public SectionResponseDTO DeleteSection(string uuid) { if (this.FindSectionByUuid(uuid) == null) { throw new EntityNotFoundException($"Section with uuid: {uuid} does not exist!", GeneralConsts.MICROSERVICE_NAME); } this._archiveService.Delete(uuid); SectionResponseDTO old = this.GetSectionByUuid(uuid); this._queryExecutor.Execute <Section>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.DELETE_SECTION(uuid), this._modelMapper.MapToSection); SectionResponseDTO response = this._autoMapper.Map <SectionResponseDTO>(old); return(response); }