Esempio n. 1
0
        public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file)
        {
            var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername());

            var result = await _photoService.AddMemberPhotoAsync(file);

            if (result.Error != null)
            {
                return(BadRequest(result.Error.Message));
            }

            var photo = new Photo
            {
                Url      = result.SecureUrl.AbsoluteUri,
                PublicId = result.PublicId
            };

            if (user.Photo != null)
            {
                photo.IsMain = true;
            }

            user.Photo = photo;

            if (await _userRepository.SaveAllAsync())
            {
                return(CreatedAtRoute("GetUser", new { username = user.UserName }, _mapper.Map <PhotoDto>(photo)));
            }


            return(BadRequest("Problem addding photo"));
        }