public ActionResult Create(string title, string genre, string director, string releasedYear, int copies) { try { if (title != null) { if (director != null) { Film film = new Film(title, genre, copies, director, releasedYear); FilmRepository.CreateFilm(film); return(RedirectToAction("Index")); } else { TempData["textmsg"] = "<script>alert('You have to select a director name');</script>"; return(View()); } } else { TempData["textmsg"] = "<script>alert('You have to select a title name');</script>"; return(View()); } } catch { return(View()); } }
/// <summary> /// Creates book or film object and saves in db /// </summary> private void CreateItem() { Console.Clear(); Console.WriteLine("Create a new ITEM"); Console.WriteLine("-----------------\n"); Console.WriteLine("\n** Select ITEM category **"); string itemType = ""; while (itemType.ToLower() != "b" && itemType.ToLower() != "f") { Console.Write("Select (b)ook or (f)ilm: "); itemType = Console.ReadLine(); } string title = ""; while (title == "") { Console.Write("Enter TITLE: "); title = Console.ReadLine(); } string genre = ""; while (genre == "") { Console.Write("Enter GENRE: "); genre = Console.ReadLine(); } if (itemType.ToLower() == "b") { string author = ""; while (author == "") { Console.Write("Enter AUTHOR name: "); author = Console.ReadLine(); } string publishedYear = ""; while (true) { Console.Write("Enter PUBLISHED year(yyyy): "); string input = Console.ReadLine(); if (input.Length != 0 && input.Length == 4 && IsDigitsOnly(input) && int.Parse(input) > 0) { publishedYear = input; break; } } int copies = 0; while (true) { Console.Write("Enter amount COPIES: "); string input = Console.ReadLine(); if (input.Length != 0 && IsDigitsOnly(input) && int.Parse(input) > 0) { int.TryParse(input, out copies); break; } } Book newBook = new Book(title, genre, copies, author, publishedYear); BookRepository.CreateBook(newBook); Console.WriteLine($"\n{newBook.Copies} Copies of '{newBook.Title}' created SUCCESSFULLY"); } else if (itemType.ToLower() == "f") { string director = ""; while (director == "") { Console.Write("Enter DIRECTOR name: "); director = Console.ReadLine(); } string releasedYear = ""; while (true) { Console.Write("Enter RELEASE year(yyyy): "); string input = Console.ReadLine(); if (input.Length != 0 && input.Length == 4 && IsDigitsOnly(input) && int.Parse(input) > 0) { releasedYear = input; break; } } int copies = 0; while (true) { Console.Write("Enter amount COPIES: "); string input = Console.ReadLine(); if (input.Length != 0 && IsDigitsOnly(input) && int.Parse(input) > 0) { int.TryParse(input, out copies); break; } } Film newFilm = new Film(title, genre, copies, director, releasedYear); FilmRepository.CreateFilm(newFilm); Console.WriteLine($"\n{newFilm.Copies} Copies of '{newFilm.Title}' created SUCCESSFULLY"); } PressKeyToGoBackToStart(); }