I am using ASP.NET MVC5 Identity. I want to create a user and at the same time user can upload profile picture.
In Identity Model i add this property
public string ImagePath { set; get; }
So I create user using this code
var adminresult = await UserManager.CreateAsync(user,cvm.Password);
So now i want to save the image in directory using user id folder .like this code
string fileName = Path.GetFileName(imagePath.FileName);
string fullDirectoryPath = "~/Content/Images/Users/" + user.Id + "/Thumb";
if (!Directory.Exists(Server.MapPath(fullDirectoryPath)))
{
Directory.CreateDirectory(Server.MapPath(fullDirectoryPath));
}
var path = Path.Combine(Server.MapPath(fullDirectoryPath), fileName);
imagePath.SaveAs(path);
var photopath = "~/Content/Images/Users/" + user.Id + "/Thumb/" + fileName;
user.ImagePath = photopath;
but problem is now i need to save this directory in database . So i need to update the user table again .
My Question is,How can i save database at one time. I don't want to run create and again update query for image column.