public async Task UpdateUserPhoto(User user, IFormFile file) { var profilePhoto = await profilePhotoRepository.GetForUser(user.Id); byte[] array; using (var stream = new MemoryStream()) { await file.CopyToAsync(stream); array = stream.ToArray(); } if (profilePhoto == null) { profilePhoto = new ProfilePhoto { UserId = user.Id, Image = array }; await profilePhotoRepository.Create(profilePhoto); } else { profilePhoto.Image = array; await profilePhotoRepository.Update(profilePhoto); } }