/// <summary> /// Adds a comic book. /// </summary> /// <param name="comicBook">The ComicBook entity instance to add.</param> public static void AddComicBook(ComicBook comicBook) { using (Context context = GetContext()) { context.ComicBooks.Add(comicBook); if (comicBook.Series != null && comicBook.Series.Id > 0) { context.Entry(comicBook.Series).State = EntityState.Unchanged; } context.SaveChanges(); } }
public ComicBook GetComicBook(int id) { ComicBook comicBookToReturn = null; foreach (var comicBook in _comicBooks) { if (comicBook.Id == id) { comicBookToReturn = comicBook; break; // break out of foreach loop after comic book identified. } } return(comicBookToReturn); }
// GET: /ComicBooks/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ComicBook comicbook = db.ComicBooks.Find(id); if (comicbook == null) { return(HttpNotFound()); } return(View(comicbook)); }
public ComicBook GetComicBook(int id) { ComicBook comicBook = null; foreach (var currentComicBook in _comicBooks) { if (currentComicBook.Id == id) { comicBook = currentComicBook; break; } } return(comicBook); }
private static ImageProvider GetProvider(ComicBook comic) { var provider = comic.CreateImageProvider(); if (provider == null) { return(null); } if (provider.Status != ImageProviderStatus.Completed) { provider.Open(false); } return(provider); }
public ComicBook GetComicBook(int Id) { ComicBook ReturnedComicBook = null; foreach (var comicBook in _comicBooks) { if (comicBook.Id == Id) { ReturnedComicBook = comicBook; break; } } return(ReturnedComicBook); }
public ComicBook GetComicBook(int id) { ComicBook comicBookToReturn = null; foreach (var comicBook in _comicBooks) { if (comicBook.Id == id) { comicBookToReturn = comicBook; break; } } return(comicBookToReturn); }
/// <summary> /// Attempts to parse the provided command as a line number /// and if successful, calls the appropriate user input method /// for the selected comic book property. /// </summary> /// <param name="command">The line number command.</param> /// <param name="comicBook">The comic book to update.</param> /// <returns>Returns "true" if the comic book property was successfully updated, otherwise "false".</returns> private static bool AttemptUpdateComicBookProperty( string command, ComicBook comicBook) { var successful = false; // Attempt to parse the command to a line number. int lineNumber = 0; int.TryParse(command, out lineNumber); // If the number is within range then get that comic book ID. if (lineNumber > 0 && lineNumber <= EditableProperties.Count) { // Retrieve the property name for the provided line number. string propertyName = EditableProperties[lineNumber - 1]; // Switch on the provided property name and call the // associated user input method for that property name. switch (propertyName) { case "SeriesId": comicBook.SeriesId = GetSeriesId(); comicBook.Series = Repository.GetSeries(comicBook.SeriesId); break; case "IssueNumber": comicBook.IssueNumber = GetIssueNumber(); break; case "Description": comicBook.Description = GetDescription(); break; case "PublishedOn": comicBook.PublishedOn = GetPublishedOnDate(); break; case "AverageRating": comicBook.AverageRating = GetAverageRating(); break; default: break; } successful = true; } return(successful); }
public ActionResult Detail(int?id) { if (id == null) { return(HttpNotFound()); } ComicBook comicBook = _comicBookRepository.GetComicBook(id.Value); if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday) { return(Redirect("/ComicBooks/Index")); } return(View(comicBook)); }
public ComicBook getComicBook(int id) { ComicBook rslt = null; foreach (var book in _comicBooks) { if (book.Id == id) { rslt = book; break; } } return(rslt); }
public ActionResult Delete(int id) { var comicBook = new ComicBook() { Id = id }; Context.Entry(comicBook).State = EntityState.Deleted; Context.SaveChanges(); TempData["Message"] = "Your comic book was successfully deleted!"; return(RedirectToAction("Index")); }
public ComicBook GetComicBook(int id) { ComicBook _comicBookToReturn = null; foreach (var comicBook in _comicBooks) { if (id == comicBook.ID) { _comicBookToReturn = comicBook; break; } } return(_comicBookToReturn); }
public ComicBook getComicBook(int Id) { ComicBook comic = null; foreach (ComicBook item in _comicBooks) { if (item.Id == Id) { comic = item; break; } } return(comic); }
public ComicBook GetComicBook(int id) { ComicBook comicBook = null; foreach (var comic in _comicBooks) { if (comic.Id == id) { comicBook = comic; break; } } return(comicBook); }
/// <summary> /// Validates a comic book on the server /// before adding a new record or updating an existing record. /// </summary> /// <param name="comicBook">The comic book to validate.</param> private void ValidateComicBook(ComicBook comicBook) { //// If there aren't any "SeriesId" and "IssueNumber" field validation errors... if (ModelState.IsValidField("ComicBook.SeriesId") && ModelState.IsValidField("ComicBook.IssueNumber")) { // Then make sure that the provided issue number is unique for the provided series. if (_comicBooksRepository.ComicBookSeriesHasIssueNumber(comicBook.Id, comicBook.SeriesId, comicBook.IssueNumber)) { ModelState.AddModelError("ComicBook.IssueNumber", "The provided Issue Number has already been entered for the selected Series."); } } }
/// <summary> /// Lists the editable properties for the provided comic book ID /// and prompts the user to select a property to edit. /// </summary> /// <param name="comicBookId">The comic book ID to update.</param> private static void UpdateComicBook(int comicBookId) { ComicBook comicBook = Repository.GetComicBook(comicBookId); string command = CommandListComicBookProperties; // If the current command doesn't equal the "Cancel" command // then evaluate and process the command. while (command != CommandCancel) { switch (command) { case CommandListComicBookProperties: ListComicBookProperties(comicBook); break; case CommandSave: Repository.UpdateComicBook(comicBook); command = CommandCancel; continue; default: if (AttemptUpdateComicBookProperty(command, comicBook)) { command = CommandListComicBookProperties; continue; } else { ConsoleHelper.OutputLine("Sorry, but I didn't understand that command."); } break; } // List the available commands. ConsoleHelper.OutputBlankLine(); ConsoleHelper.Output("Commands: "); if (EditableProperties.Count > 0) { ConsoleHelper.Output("Enter a Number 1-{0}, ", EditableProperties.Count); } ConsoleHelper.OutputLine("S - Save, C - Cancel", false); // Get the next command from the user. command = ConsoleHelper.ReadInput("Enter a Command: ", true); } ConsoleHelper.ClearOutput(); }
public ComicBook GetComicBook(int id) { ComicBook ComicBookToReturn = null; foreach (var ComicBook in _comicBooks) { if (ComicBook.id == id) { ComicBookToReturn = ComicBook; break; } } return(ComicBookToReturn); }
/// <summary> /// Deletes a comic book. /// </summary> /// <param name="comicBookId">The comic book ID to delete.</param> public static void DeleteComicBook(int comicBookId) { using (Context context = GetContext()) { //Crea una intacia del modelo de ComicBook y asigna el id dado por el usuario. var comicBook = new ComicBook() { Id = comicBookId }; //Pasa la informacion para lograr el Delete. context.Entry(comicBook).State = EntityState.Deleted; context.SaveChanges(); } }
public ComicBook GetComicBook(int id) { ComicBook comicBookToReturn = null; //Look through list of coomic books and find one with matching id foreach (var comicBook in _comicBooks) { if (comicBook.Id == id) { comicBookToReturn = comicBook; break; } } return(comicBookToReturn); }
/// <summary> /// Updates a comic book. /// </summary> /// <param name="comicBook">The ComicBook entity instance to update.</param> public static void UpdateComicBook(ComicBook comicBook) { using (Context context = GetContext()) { //context.Entry(comicBookToUpdate).CurrentValues.SetValues(comicBook); context.ComicBooks.Attach(comicBook); var comicBookEntry = context.Entry(comicBook); comicBookEntry.State = EntityState.Modified; //comicBookEntry.Property("IssueNumber").IsModified = false; //This would allow you to cement the IssueNumber and prevent it from being changed once its created context.SaveChanges(); } }
public ComicBook GetComicBook(int id) { ComicBook returnComicBook = null; foreach (ComicBook comicBook in _comicBooks) { if (comicBook.ID == id) { returnComicBook = comicBook; break; } } return(returnComicBook); }
/// <summary> /// Updates a comic book. /// </summary> /// <param name="comicBook">The ComicBook entity instance to update.</param> public static void UpdateComicBook(ComicBook comicBook) { using (Context context = GetContext()) { //llama la identidad deseada por el usuario. context.ComicBooks.Attach(comicBook); // Pasamos la informacion que va ser update a la base de datos. var comicBookEntry = context.Entry(comicBook); //Modifica los cambios nuevos. comicBookEntry.State = EntityState.Modified; //No deseamos que cambie ciertos campos en la tabla deseada. comicBookEntry.Property("IssueNumber").IsModified = false; } }
public static ComicBook GetComicBook(int id) { ComicBook comicBook = null; foreach (var book in _comicBooks) { if (book.Id == id) { comicBook = book; break; } } return(comicBook); }
private void btnRemove_Click(object sender, EventArgs e) { string fileName = lstBxSavedComics.SelectedItem.ToString(); //get comic book ComicBook importedCb = comicManager.GetComicBook(Path.Combine(cbResourceDirectory, fileName)); //remove from user library loggedInUser.MyComicLibrary.RemoveComicBook(importedCb.GetArchivePath()); //write changes accountManager.WriteComicLibrary(loggedInUser.Id, loggedInUser.MyComicLibrary); //refresh to reflect changes ReloadLibrary(); btnRemove.Enabled = false; }
public ComicBook GetComicBook(int id) { ComicBook comicBookToReturn = null; foreach (var comicBook in _comicBooks) { if (comicBook.Id == id) { comicBookToReturn = comicBook; break; } } return(comicBookToReturn); //return (ComicBook)_comicBooks.Where(c => c.Id == id).Select(s => s); }
/// <summary> /// Lists the editable comic book properties to the screen. /// </summary> /// <param name="comicBook">The comic book property values to list.</param> private static void ListComicBookProperties(ComicBook comicBook) { ConsoleHelper.ClearOutput(); ConsoleHelper.OutputLine("UPDATE COMIC BOOK"); // NOTE: This list of comic book property values // needs to match the collection of editable properties // declared at the top of this file. ConsoleHelper.OutputBlankLine(); ConsoleHelper.OutputLine("1) Series: {0}", comicBook.Series.Title); ConsoleHelper.OutputLine("2) Issue Number: {0}", comicBook.IssueNumber); ConsoleHelper.OutputLine("3) Description: {0}", comicBook.Description); ConsoleHelper.OutputLine("4) Published On: {0}", comicBook.PublishedOn.ToShortDateString()); ConsoleHelper.OutputLine("5) Average Rating: {0}", comicBook.AverageRating); }
/// <summary> /// Validates a comic book on the server /// before adding a new record or updating an existing record. /// </summary> /// <param name="comicBook">The comic book to validate.</param> private void ValidateComicBook(ComicBook comicBook) { //// If there aren't any "SeriesId" and "IssueNumber" field validation errors... //if (ModelState.IsValidField("ComicBook.SeriesId") && // ModelState.IsValidField("ComicBook.IssueNumber")) //{ // // Then make sure that the provided issue number is unique for the provided series. // // TODO Call method to check if the issue number is available for this comic book. // if (false) // { // ModelState.AddModelError("ComicBook.IssueNumber", // "The provided Issue Number has already been entered for the selected Series."); // } //} }
public ComicBook GetComicBook(int id) { ComicBook _comicBookToReturn = null; foreach (var comicBook in _comikBooks) { if (comicBook.ID == id) { _comicBookToReturn = comicBook; break; // To stop looping once found!!! } } return(_comicBookToReturn); }
public void Build_MissingPropertyOrderItem_ThrowsException() { var builder = new OrderBuilder(); var comicBook = new ComicBook(); var employee = new User(); var bc = builder .Details .Date(new DateTime(1999, 01, 01)) .User(employee) .Item .ComicBook(comicBook) .Discount(0); Assert.Throws <ValidationException>((() => bc.Add())); }
public ComicBook GetComicBook(int id) { ComicBook comicBook = null; foreach (var item in Data.ComicBooks) { if (item.Id == id) { comicBook = item; break; } } return(comicBook); }
/// <summary> /// Handles the Loaded event of the MainDisplay control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void MainDisplay_Loaded(object sender, RoutedEventArgs e) { //Ensure that the window is active on start Activate(); _imageUtils = new ImageUtils(); _fileLoader = new FileLoader(); //set mouse idle timer _timeoutToHide = TimeSpan.FromSeconds(2); MouseIdle = new DispatcherTimer {Interval = TimeSpan.FromSeconds(1)}; MouseIdle.Tick += MouseIdleChecker; MouseIdle.Start(); //Load config LoadConfiguration(); SetBookmarkMenus(); if (Configuration.Windowed) { SetWindowMode(WindowMode.Windowed); } //gray out resume last file if the files dont't exist if (Configuration.Resume != null) { foreach (string file in Configuration.Resume.Files) { if (!System.IO.File.Exists(file)) { ResumeFile_MenuBar.IsEnabled = false; ResumeFile_RightClick.IsEnabled = false; } } } else { ResumeFile_MenuBar.IsEnabled = false; ResumeFile_RightClick.IsEnabled = false; } _scrollValueHorizontal = (int)(ScrollField.ViewportHeight * 0.05); _imageUtils.ScreenHeight = (int)ScrollField.ViewportHeight; _imageUtils.ScreenWidth = (int)ScrollField.ViewportWidth; //open file (when opening associated by double click) if (_openingFile != null) { LoadAndDisplayComic(false); } else { _comicBook = new ComicBook(); // KBR use an empty placeholder book } KeyGrid.ItemsSource = KeyHints; // TODO consider using an InformationWindow and show on the '?' key }
/// <summary> /// Load the archives /// </summary> /// <param name="files">Archive location</param> /// <param name="fileNumber">File in array to start at</param> /// <param name="pageNumber">Page on which to start from selected file</param> public void LoadFile(string[] files, int fileNumber, int pageNumber) { KeyGrid.Visibility = Visibility.Collapsed; _fileLoader.Load(files); if (_fileLoader.LoadedFileData.HasFile) { _comicBook = _fileLoader.LoadedFileData.ComicBook; if (_comicBook.TotalPages < 1) // Found a ZIP containing ZIPs { ShowMessage("Unable to load any images"); return; } DisplayImage(_comicBook.GetPage(fileNumber, pageNumber), ImageStartPosition.Top); foreach (ComicFile comicFile in _comicBook) { if (!string.IsNullOrEmpty(comicFile.InfoText)) { Mouse.OverrideCursor = Cursors.Arrow; var infoText = new InformationText(comicFile.Location, comicFile.InfoText); infoText.ShowDialog(); Mouse.OverrideCursor = Cursors.Wait; } } if (!string.IsNullOrEmpty(_fileLoader.Error)) { ShowMessage(_fileLoader.Error); } } else if (!string.IsNullOrEmpty(_fileLoader.Error)) { ShowMessage(_fileLoader.Error); } else { ShowMessage("No supported files found."); } }
private static ImageProvider GetProvider(ComicBook comic) { var provider = comic.CreateImageProvider(); if (provider == null) { return null; } if (provider.Status != ImageProviderStatus.Completed) { provider.Open(false); } return provider; }
/// <summary> /// Load the archives /// </summary> /// <param name="files">Archive location</param> /// <param name="fileNumber">File in array to start at</param> /// <param name="pageNumber">Page on which to start from selected file</param> public void LoadFile(string[] files, int fileNumber, int pageNumber) { _fileLoader.Load(files); if (_fileLoader.LoadedFileData.HasFile) { _comicBook = _fileLoader.LoadedFileData.ComicBook; foreach (ComicFile comicFile in _comicBook) { if (!string.IsNullOrEmpty(comicFile.InfoText)) { Mouse.OverrideCursor = Cursors.Arrow; _informationText = new InformationText(comicFile.Location, comicFile.InfoText); _informationText.ShowDialog(); Mouse.OverrideCursor = Cursors.Wait; } } DisplayImage(_comicBook.GetPage(fileNumber, pageNumber), ImageStartPosition.Top); if (!string.IsNullOrEmpty(_fileLoader.Error)) { ShowMessage(_fileLoader.Error); } } else if (!string.IsNullOrEmpty(_fileLoader.Error)) { ShowMessage(_fileLoader.Error); } else { ShowMessage("No supported files found."); } }