Пример #1
0
        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);
        }
Пример #2
0
        public SectionArchiveResponseDTO Create(CreateSectionArchiveRequestDTO requestDTO)
        {
            SectionArchive sectionArchive = new SectionArchive()
            {
                sectionUUID  = requestDTO.sectionUUID,
                name         = requestDTO.name,
                description  = requestDTO.description,
                visible      = requestDTO.visible,
                creationDate = requestDTO.creationDate,
                course       = new Course()
                {
                    uuid = requestDTO.courseUUID
                },
                moderator = new User()
                {
                    uuid = requestDTO.moderatorUUID
                },
                changeDate = requestDTO.changeDate
            };

            sectionArchive = this._queryExecutor.Execute <SectionArchive>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.CREATE_ARCHIVE(sectionArchive), this._modelMapper.MapToSectionArchive);

            return(this._autoMapper.Map <SectionArchiveResponseDTO>(sectionArchive));
        }