Beispiel #1
0
        public SubjectResponseDTO Delete(string uuid)
        {
            if (this.FindOneByUUID(uuid) == null)
            {
                throw new EntityNotFoundException($"Subject with uuid {uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            this._subjectArchiveService.Delete(uuid);

            Subject old = this.FindOneByUUID(uuid);

            this._queryExecutor.Execute <Subject>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.DELETE_SUBJECT(uuid), this._modelMapper.MapToSubject);

            SubjectResponseDTO response = this._autoMapper.Map <SubjectResponseDTO>(old);

            try {
                response.department = this._httpClientService.SendRequest <DepartmentDTO>(HttpMethod.Get, "http://localhost:40007/api/departments/" + response.department.uuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityNotFoundException($"Department with uuid {response.department.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            try {
                response.creator = this._httpClientService.SendRequest <UserDTO>(HttpMethod.Get, "http://localhost:40001/api/users/" + response.creator.uuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityNotFoundException($"User with uuid {response.creator.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }
            return(response);
        }
Beispiel #2
0
        public SubjectResponseDTO Update(UpdateSubjectRequestDTO requestDTO)
        {
            if (this.FindOneByUUID(requestDTO.uuid) == null)
            {
                throw new EntityNotFoundException($"Subject with uuid {requestDTO.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            DepartmentDTO department;
            UserDTO       creator;

            try {
                department = this._httpClientService.SendRequest <DepartmentDTO>(HttpMethod.Get, "http://localhost:40007/api/departments/" + requestDTO.departmentUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityAlreadyExistsException($"Department with uuid {requestDTO.departmentUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            try {
                creator = this._httpClientService.SendRequest <UserDTO>(HttpMethod.Get, "http://localhost:40001/api/users/" + requestDTO.creatorUUID, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityAlreadyExistsException($"User with uuid {requestDTO.creatorUUID} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            Subject subject = new Subject()
            {
                uuid         = requestDTO.uuid,
                name         = requestDTO.name,
                description  = requestDTO.description,
                creationDate = requestDTO.creationDate,
                department   = new Department()
                {
                    uuid = requestDTO.departmentUUID
                },
                creator = new User()
                {
                    uuid = requestDTO.creatorUUID
                }
            };

            CreateSubjectArchiveRequestDTO archiveDTO = new CreateSubjectArchiveRequestDTO()
            {
                subjectUUID    = subject.uuid,
                name           = subject.name,
                description    = subject.description,
                creationDate   = subject.creationDate,
                departmentUUID = subject.department.uuid,
                creatorUUID    = subject.creator.uuid,
                moderatorUUID  = new UserPrincipal(_httpContextAccessor.HttpContext).uuid,
                changeDate     = DateTime.Now
            };

            _ = _subjectArchiveService.Create(archiveDTO);

            subject = this._queryExecutor.Execute <Subject>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_SUBJECT(subject), this._modelMapper.MapToSubject);

            SubjectResponseDTO response = this._autoMapper.Map <SubjectResponseDTO>(subject);

            response.department = department;
            response.creator    = creator;
            return(response);
        }
Beispiel #3
0
        public SubjectResponseDTO GetOneByUuid(string uuid)
        {
            SubjectResponseDTO response = this._autoMapper.Map <SubjectResponseDTO>(this.FindOneByUUID(uuid));

            if (response == null)
            {
                throw new EntityNotFoundException($"Subject with uuid {uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }
            try {
                response.department = this._httpClientService.SendRequest <DepartmentDTO>(HttpMethod.Get, "http://localhost:40007/api/departments/" + response.department.uuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityNotFoundException($"Department with uuid {response.department.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }
            try {
                response.creator = this._httpClientService.SendRequest <UserDTO>(HttpMethod.Get, "http://localhost:40001/api/users/" + response.creator.uuid, new UserPrincipal(_httpContextAccessor.HttpContext).token).Result;
            } catch {
                throw new EntityNotFoundException($"User with uuid {response.creator.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }
            return(response);
        }