public ActionResult CreateTitle() { //Creating a new instance of the class Title Title a = new Title(); return View(a); }
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 adds a new instance of class Title // and saves it to the database public void AddTitle(Title title) { m_db.Titles.Add(title); m_db.SaveChanges(); }