public ActionResult CreateTitle(Title title, HttpPostedFileBase file) { // Make sure that the user has selected a file to upload if (file != null && file.ContentLength > 0) { // Get the info on the file var fileName = Path.GetFileName(file.FileName); var contentLength = file.ContentLength; var contentType = file.ContentType; // Check in Output window to see if the file was uploaded System.Diagnostics.Debug.Write(file); //Read the content of the file string data = new StreamReader(file.InputStream).ReadToEnd(); // Check in output window to see if the content of the file appears System.Diagnostics.Debug.WriteLine(data); // Create a new instance of Apprepository called repo to add and save title variable AppRepository repo = new AppRepository(); repo.AddTitle(title); //Save to database FileSRT srt = new FileSRT() { FileSRTName = fileName, Data = data, ContentType = contentType, ContentLength = contentLength, TitleID = title.ID, }; repo.AddfileSRT(srt); //Show if success return RedirectToAction("Index"); } else { return View("Error"); } }
// A void function that allows user to edit a file from the database // and overrides changes to the original file public void SaveFile(FileSRT model) { FileSRT current = GetFile(model.FileSRTID.Value); m_db.Entry(current).CurrentValues.SetValues(model); m_db.SaveChanges(); }
// A void function that adds a new instance, variable called fileSRT, // of class FileSRT and saves it to the database public void AddfileSRT(FileSRT fileSRT) { m_db.Files.Add(fileSRT); m_db.SaveChanges(); }
public ActionResult EditTitle(FileSRT model) { // Enable user to edit a file // by calling the Savefile function if(ModelState.IsValid) { m_repository.SaveFile(model); } return View("Success"); }