public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file) { var user = await _userRepository.GetUserByNameAsync(User.GetUserName()); var result = await _photoService.AddPhontoAsync(file); if (result.Error != null) { return(BadRequest(result.Error.Message)); } var photo = new Photo { Url = result.SecureUrl.AbsoluteUri, PublicId = result.PublicId }; if (user.Photos.Count == 0) { photo.IsMain = true; } user.Photos.Add(photo); if (await _userRepository.SaveAllAsync()) { return(CreatedAtRoute("GetUser", new { username = user.UserName }, _mapper.Map <PhotoDto>(photo))); } return(BadRequest("Problem adding photo")); }