예제 #1
0
        public async Task <IActionResult> AddPatient(PatientToAddDto patientToAddDto)
        {
            var patientToCreate = _mapper.Map <Patient>(patientToAddDto);

            if (patientToCreate != null)
            {
                _repo.add(patientToCreate);
            }

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

            return(BadRequest("Ajout du patient impossible"));
        }
예제 #2
0
        public async Task <IActionResult> AddDocteur(DocteurToAddDto docteurToAddDto)
        {
            var docteurToCreate = _mapper.Map <Docteur>(docteurToAddDto);

            if (docteurToCreate != null)
            {
                _repo.add(docteurToCreate);
            }

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

            return(BadRequest("Ajout du docteur impossible"));
        }
예제 #3
0
        public async Task <IActionResult> AddPhotoForPatient(int patientId, [FromForm] PhotoForCreationDto photoForCreationDto)
        {
            var patientFromRepo = await _repo.GetPatient(patientId);

            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(500).Height(500).Crop("fill").Gravity("face")
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

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

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

            if (!patientFromRepo.Photos.Any(u => u.IsMain))
            {
                photo.IsMain = true;
            }

            patientFromRepo.Photos.Add(photo);

            if (await _repo.SaveAll())
            {
                var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo);
                return(CreatedAtRoute("GetPhoto", new { id = photo.Id }, photoToReturn));
            }

            return(BadRequest("Il n'a pas été possible d'ajouter la photo"));
        }