Example #1
0
        public async Task <bool> ApprovePhoto(int id)
        {
            var photo = await _dataAccess.GetPhoto(id);

            photo.IsApproved = true;

            if (await _dataAccess.SaveAll())
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        public async Task <UserForUpdateDto> UpdateUser(int id, UserForUpdateDto userForUpdateDto)
        {
            var userFromContext = await _dataAccess.GetUser(id, true);

            _mapper.Map(userForUpdateDto, userFromContext);

            if (await _dataAccess.SaveAll())
            {
                return(userForUpdateDto);
            }

            return(null);
        }
Example #3
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);
        }
Example #4
0
        public async Task <Message> CreateMessage(int userid, MessageForCreactionDto messageForCreaction)
        {
            messageForCreaction.SenderId = userid;
            var recipient = await _business.GetUser(userid, userid);

            if (recipient == null)
            {
                return(null);
            }

            var message = _mapper.Map <Message>(messageForCreaction);

            _dataAccess.Add(message);

            if (await _dataAccess.SaveAll())
            {
                return(message);
            }
            else
            {
                throw new Exception("Creating the message failed on save");
            }
        }