public async Task <IActionResult> SelectUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var select = await _repo.GetSelect(id, recipientId);

            if (select != null)
            {
                return(BadRequest("You've already selected this user"));
            }

            if (await _repo.getUser(recipientId) == null)
            {
                return(NotFound());
            }

            var checkIfPatientFirstSelect = await _repo.GetSelect(recipientId, id);

            var SelectorUser = await _repo.getUser(id);

            var SelecteeUser = await _repo.getUser(recipientId);

            // Check if a patient is trying to select a patient
            if (SelectorUser.UserRole.RoleId.Equals(1) && SelecteeUser.UserRole.RoleId.Equals(1))
            {
                return(BadRequest("You can't select another patient"));
            }

            // Check if a doctor is trying to select a patient
            if (SelectorUser.UserRole.RoleId.Equals(3) && SelecteeUser.UserRole.RoleId.Equals(1))
            {
                // Check if patient has selected the doctor first
                // If patient has not selected the doctor, then the doctor cannot select the patient
                if (checkIfPatientFirstSelect == null)
                {
                    return(BadRequest("You can't select a patient first"));
                }
            }

            select = new Select
            {
                SelectorId = id,
                SelecteeId = recipientId
            };

            _repo.Add <Select>(select);

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

            return(BadRequest("Failed to select user"));
        }
        public async Task <IActionResult> AddDocumentForUser(int userId,
                                                             [FromForm] DocumentForCreationDto docForCreationDto)
        {
            // [FromForm]PhotoForCreationDto = PhotoForCreationDto)

            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                int DocumentUploadeeId = userId;
                int DocumentUploaderId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
                var checkIfUploaderSelectedUploadee = await _repo.GetSelect(DocumentUploaderId, DocumentUploadeeId);

                var checkIfUploadeeSelectedUploader = await _repo.GetSelect(DocumentUploadeeId, DocumentUploaderId);

                if (checkIfUploadeeSelectedUploader != null && checkIfUploaderSelectedUploadee == null)
                {
                    return(BadRequest("You cannot upload photos until you accept user's request"));
                }
                else if (checkIfUploadeeSelectedUploader == null && checkIfUploaderSelectedUploadee == null)
                {
                    return(Unauthorized());
                }
            }

            var userFromRepo = await _repo.getUser(userId);

            var file = docForCreationDto.File;

            var imageUploadResult = new ImageUploadResult();
            var videoUploadResult = new VideoUploadResult();

            // var uploadResult = new RawUploadResult();


            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    if (file.ContentType.Contains("image"))
                    {
                        var uploadParams = new ImageUploadParams()
                        {
                            File           = new FileDescription(file.Name, stream),
                            Transformation = new Transformation()
                                             .Width(500).Height(500).Crop("fill").Gravity("face")
                        };
                        imageUploadResult          = _cloudinary.Upload(uploadParams);
                        docForCreationDto.Url      = imageUploadResult.Uri.ToString();
                        docForCreationDto.PublicId = imageUploadResult.PublicId;
                    }
                    if (file.ContentType.Contains("video"))
                    {
                        var uploadParams = new VideoUploadParams()
                        {
                            File            = new FileDescription(file.Name, stream),
                            EagerTransforms = new List <Transformation>()
                            {
                                new Transformation().Width(300).Height(300)
                                .Crop("pad").AudioCodec("none"),
                                new Transformation().Width(160).Height(100)
                                .Crop("crop").Gravity("south").AudioCodec("none")
                            }
                        };
                        videoUploadResult          = _cloudinary.Upload(uploadParams);
                        docForCreationDto.Url      = videoUploadResult.Uri.ToString();
                        docForCreationDto.PublicId = videoUploadResult.PublicId;
                    }

                    // var uploadParams = new RawUploadParams() {
                    //     File = new FileDescription(file.Name, stream),
                    //     // Transformation = new Transformation()
                    //     //   .Width(500).Height(500).Crop("fill").Gravity("face")
                    // };

                    // uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            // docForCreationDto.Url = uploadResult.Uri.ToString();
            // docForCreationDto.PublicId = uploadResult.PublicId;
            docForCreationDto.Type = file.ContentType;

            var document = _mapper.Map <Document>(docForCreationDto);

            // if (!userFromRepo.Documents.Any(u => u.IsMain))
            //     photo.IsMain = true;

            userFromRepo.Documents.Add(document);

            //var photoToReturn = _mapper.Map<PhotosForReturnDto>(photo);

            if (await _repo.SaveAll())
            {
                var docToReturn = _mapper.Map <DocumentForReturnDto>(document);
                return(CreatedAtRoute("GetDocument", new { id = document.id }, docToReturn));
            }

            return(BadRequest("Could not add the photo"));
        }