コード例 #1
0
        public async Task <IActionResult> AssignProgramme(int clientId, ProgrammeForListDto programmeForListDto)
        {
            // if (clientId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //     return Unauthorized();

            var clientFromRepo = await _repo.GetClient(clientId);

            var programmeForReturn = new Programme
            {
                ProgrammeName = programmeForListDto.ProgrammeName,
                ProgrammeType = programmeForListDto.ProgrammeType,
                Description   = programmeForListDto.Description,
                RelatedLink   = programmeForListDto.RelatedLink,
                SessionTime   = programmeForListDto.SessionTime,
                ClientId      = clientId
            };

            clientFromRepo.Programmes.Add(programmeForReturn);

            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }
            return(BadRequest("프로그램 등록에 실패하였습니다"));
        }
コード例 #2
0
        public async Task <IActionResult> AddPhotoForClient(int clientId
                                                            , [FromForm] PhotoForCreationDto photoForCreationDto)
        {
            if (clientId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var clientFromRepo = await _repo.GetClient(clientId);

            var file = photoForCreationDto.File;

            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File           = new FileDescription(file.Name, stream),
                        Transformation = new Transformation().Width(350).Height(350).Crop("fill")
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            photoForCreationDto.Url      = uploadResult.Uri.ToString();
            photoForCreationDto.PublicId = uploadResult.PublicId;

            var photo = _mapper.Map <ClientImage>(photoForCreationDto);

            clientFromRepo.ClientImages.Add(photo);

            if (await _repo.SaveAll())
            {
                var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoToReturn));
            }
            return(BadRequest("사진 업로드에 실패하였습니다."));
        }
コード例 #3
0
        public async Task <IActionResult> UpdateUser(int id, UserForUpdateDto UserForUpdateDto)
        {
            // FindFirst method to check if the user is the current user that's passed to the token to our server
            // That's attempting to access this route and doing an HttpPut
            // And If the id of the path the user is trying to access doesn't match what's in the token,
            // Then we're going to return Unauthorized()
            // if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //     return Unauthorized();

            var clientFromRepo = await _repo.GetClient(id);

            _mapper.Map(UserForUpdateDto, clientFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("업데이트에 실패하였습니다");
        }
コード例 #4
0
        public async Task <IActionResult> AssignSymptom(int clientId, SymptomForListDto symptomForListDto)
        {
            // if (clientId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //     return Unauthorized();

            var clientFromRepo = await _repo.GetClient(clientId);

            var symptomForReturn = new Symptom
            {
                SymptomName = symptomForListDto.SymptomName,
                Details     = symptomForListDto.Details,
                ClientId    = clientId
            };

            clientFromRepo.Symptoms.Add(symptomForReturn);

            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }
            return(BadRequest("프로그램 등록에 실패하였습니다"));
        }
コード例 #5
0
        public async Task <IActionResult> AddInstructorExperience(int instructorId, ExperienceForListDto experienceForListDto)
        {
            if (instructorId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var instructorFromRepo = await _repo.GetInstructor(instructorId);

            var experienceForReturn = new Experience
            {
                Description  = experienceForListDto.Description,
                InstructorId = instructorId
            };

            instructorFromRepo.Experiences.Add(experienceForReturn);

            if (await _repo.SaveAll())
            {
                return(StatusCode(201));
            }
            return(BadRequest("프로그램 등록에 실패하였습니다"));
        }