public ActionResult Create([Bind(Include = "ComicID,ComicType,DistributorID,Title,Authors,Issue,Publisher,Rating,Description,Quantity,Price,Status")] Comic comic) { if (ModelState.IsValid) { if (_comicManager.AddComicToInventory(comic.Title, comic.Issue, comic.Authors, comic.Publisher, comic.ComicType, comic.DistributorID, comic.Rating, comic.Description, comic.Quantity, comic.Price, comic.Status) == true) { return(RedirectToAction("Index")); } else { return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable)); } } else { return(View(comic)); } }
private void btnAddComic_Click(object sender, RoutedEventArgs e) { decimal priceField = 0; var title = txtTitle.Text; var issue = cboIssue.SelectedItem; var authors = txtAuthors.Text; var publisher = txtPublisher.Text; var comicType = cboComicType.Text; var distributorID = cboDistributor.SelectedItem; var rating = txtRating.Text; var description = txtDescription.Text; var quantity = cboQuantity.SelectedItem; var status = _comicStatus; // Validing inputs are present for all fields if (title == "") { MessageBox.Show("Must enter a title."); txtTitle.Focus(); return; } if (issue == null) { MessageBox.Show("Must choose an issue number. Enter '0' for \ngraphic novels or bound trades without one."); txtTitle.Focus(); return; } if (authors == "") { MessageBox.Show("Must list authors and illustrators."); txtAuthors.Focus(); return; } if (publisher == "") { MessageBox.Show("Must list the book's publisher. \nE.g. Marvel, Image, Dark Horse, etc."); txtPublisher.Focus(); return; } if (comicType == "") { MessageBox.Show("Must select comic type."); cboComicType.Focus(); return; } if (distributorID == null) { MessageBox.Show("Must select distributor ID."); cboDistributor.Focus(); return; } if (rating == "") { MessageBox.Show("Must enter a rating."); txtRating.Focus(); return; } if (description == "") { MessageBox.Show("Must enter a description."); txtRating.Focus(); return; } if (quantity == null) { MessageBox.Show("Must enter a quantity."); cboQuantity.Focus(); return; } // Validates price input, converts to decimal data type try { priceField = Convert.ToDecimal(txtPrice.Text); } catch (Exception) { MessageBox.Show("Must enter a valid price."); txtPrice.Clear(); txtPrice.Focus(); return; } var price = priceField; if (_comic == null) { try { _comicManager.AddComicToInventory(title, (int)issue, authors, publisher, comicType, (int)distributorID, rating, description, (int)quantity, price, status); MessageBox.Show("Comic added."); Close(); //txtTitle.Clear(); //txtTitle.Focus(); //cboIssue.Equals(null); //txtAuthors.Clear(); //txtPublisher.Clear(); //cboComicType.Equals(null); //cboDistributor.Equals(null); //txtRating.Clear(); //txtDescription.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace, "Error"); } } else { MessageBox.Show("Comic not added."); } }