public IActionResult Create([Bind] LibraryAsset libraryAsset, IFormFile pic) { if (!ModelState.IsValid) { var viewModel = new AssetModel(libraryAsset) { }; } if (libraryAsset.Id == 0) { var fileName = Path.Combine(ho.WebRootPath + "\\images\\", Path.GetFileName(pic.FileName)); pic.CopyTo(new FileStream(fileName, FileMode.Create)); libraryAsset.ImageUrl = "/images/" + Path.GetFileName(pic.FileName); libraryAsset.LocationId = 1; libraryAsset.StatusId = 3; libraryAsset.Discriminator = "Book"; assets.Add(libraryAsset); assets.Complete(); } else { var fileName = Path.Combine(ho.WebRootPath + "\\images\\", Path.GetFileName(pic.FileName)); pic.CopyTo(new FileStream(fileName, FileMode.Create)); var assetInDb = assets.GetById(libraryAsset.Id); assetInDb.Author = libraryAsset.Author; assetInDb.ISBN = libraryAsset.ISBN; assetInDb.Cost = libraryAsset.Cost; assetInDb.NumberOfCopies = libraryAsset.NumberOfCopies; assetInDb.Tittle = libraryAsset.Tittle; assetInDb.Year = libraryAsset.Year; assetInDb.ImageUrl = "/images/" + Path.GetFileName(pic.FileName); } assets.Complete(); return(RedirectToAction("Index", "Catalog")); }