Example #1
0
        public async Task <PageList <User> > GetUsers(UserParams userParams, int userId)
        {
            var currentUser = await _dataAccess.GetUser(userId, true);

            userParams.UserId = currentUser.Id;

            var users = await _dataAccess.GetUsers(userParams);

            if (string.IsNullOrEmpty(userParams.Gender))
            {
                userParams.Gender = currentUser.Gender == "male" ? "female" : "male";
            }

            return(await _dataAccess.GetUsers(userParams));
        }
Example #2
0
        public async Task <PhotoForReturnDto> AddPhotoUser(int userId, PhotoForCreationDto photoForCreationDto)
        {
            var user = await _dataContext.GetUser(userId, true);

            var uploadResult = new ImageUploadResult();
            var file         = photoForCreationDto.File;

            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 (!user.Photos.Any(u => u.IsMain))
            {
                photo.IsMain = true;
            }

            user.Photos.Add(photo);

            if (await _dataContext.SaveAll())
            {
                return(_mapper.Map <PhotoForReturnDto>(photo));
            }

            return(null);
        }