public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file) { var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername()); var result = await _photoService.AddphotoAsync(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 _mapper.Map<PhotoDto>(photo); return(CreatedAtRoute("GetUser", new{ Username = user.UserName }, _mapper.Map <PhotoDto>(photo))); } return(BadRequest("Problem adding photo")); }