//The private method below helps to Extract the FullPath of the image uploaded... private string UploadFileMethod(NewBranchViewModel model) { string UniqueFilePath = null; if (model.ImageUrl != null) { //this provides us with the physical path to WWWroot folder //then we combine the path with the "images", "branches" path string RootFilePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", "branches"); //extracting the image name string imageName = model.ImageUrl.FileName; string UniqueFilePaths = Path.Combine(RootFilePath, imageName); UniqueFilePath = imageName; //"copyTo" copies to the images/branches folder then "Filemode.create" "avails it n d server" //We r wrapping it up in the Using block so it will be disposed off properly wen done using (var fileStream = new FileStream(UniqueFilePaths, FileMode.Create)) { model.ImageUrl.CopyTo(fileStream); } } return(UniqueFilePath); }
public IActionResult NewBranch(NewBranchViewModel model) { if (ModelState.IsValid) { string UniqueFilePath = UploadFileMethod(model); var newBranch = new LibraryBranch { Id = model.Id, Name = model.Name, Address = model.Address, Telephone = model.Telephone, Description = model.Description, OpenDate = model.OpenDate, ImageUrl = UniqueFilePath }; _branch.Add(newBranch); return(RedirectToAction("Detail", new { id = model.Id })); } return(View()); }
public NewBranchPage() { InitializeComponent(); BindingContext = new NewBranchViewModel(); }