Esempio n. 1
0
 public ActionResult Edit([Bind(Include = "ComicID,ComicType,DistributorID,Title,Authors,Issue,Publisher,Rating,Description,Quantity,Price,Status")] Comic newComic)
 {
     if (ModelState.IsValid)
     {
         var oldComic = _comicManager.RetrieveAvailableComics(true).Find(c => c.ComicID == newComic.ComicID);
         if (_comicManager.UpdateComicInfo(oldComic, newComic.Title, newComic.Issue, newComic.Authors, newComic.Publisher, newComic.ComicType, newComic.DistributorID,
                                           newComic.Rating, newComic.Description, newComic.Quantity, newComic.Price, newComic.Status) == true)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable));
         }
     }
     else
     {
         return(View(newComic));
     }
 }
        private void btnEditComic_Click(object sender, RoutedEventArgs e)
        {
            decimal priceField    = 0;
            var     comic         = _comic;
            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;

            try
            {
                _comicManager.UpdateComicInfo(comic, title, (int)issue, authors, publisher, comicType, (int)distributorID, rating, description, (int)quantity, price, status);
                MessageBox.Show("Comic updated.");
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace, "Error");
            }
        }