public ActionResult Create(SellerCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.PhotoPath != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.PhotoPath.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder model.PhotoPath.CopyTo(new FileStream(filePath, FileMode.Create)); } Seller newseller = new Seller { Username = model.Username, Email = model.Email, Companyname = model.Companyname, Password = model.Password, GSTIN = model.GSTIN, AboutCompany = model.AboutCompany, Address = model.Address, Website = model.Website, Mobileno = model.Mobileno, // Store the file name in PhotoPath property of the employee object // which gets saved to the Employees database table PhotoPath = uniqueFileName }; _context.Add(newseller); _context.SaveChanges(); return(RedirectToAction("Details", new { id = newseller.SId })); } return(View()); }
public ActionResult S_SignUp(SellerCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.Photpath != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photpath.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder model.Photpath.CopyTo(new FileStream(filePath, FileMode.Create)); } Seller newseller = new Seller { s_name = model.s_name, s_pwd = model.s_pwd, s_emailid = model.s_emailid, gstin = model.gstin, bank_details = model.bank_details, // Store the file name in PhotoPath property of the employee object // which gets saved to the Employees database table Photpath = uniqueFileName }; _context.Add(newseller); _context.SaveChanges(); return(RedirectToAction("S_Login", new { id = newseller.s_id })); } return(View()); }