/// <summary> /// The addCopy method is used to add a DVDCopy object that was selected in the DVDCopy dropdown box to /// either the rentals or purchases dictionary (depending on the received boolean). It will then reload /// the copies dropdown box to reflect the changes. /// </summary> /// <param name="isRental"></param> private void addCopy(Boolean isRental) { // If a copy is selected. if (this.copies.SelectedValue != String.Empty) { // It will fetch the DVD that the copy belongs to. DVD dvd = DVD.Fetch(Convert.ToInt32(this.dvds.SelectedValue.ToString())); // It will then fetch the copy from the DVD (by passing in the barcode). DVDCopy copy = DVDCopy.FetchCopy(Convert.ToInt32(this.copies.SelectedItem.Value)); // If the copy doesn't already exist in both dictionaries if (!(this.lstRentals.ContainsKey(this.copies.SelectedItem.Text) || this.lstPurchases.ContainsKey(this.copies.SelectedItem.Text))) { // Then it will add it to either the rentals or purchases if (isRental) { this.lstRentals.Add(copy.barcode, copy); } else { this.lstPurchases.Add(copy.barcode, copy); } } // Reloads the copies. this.loadCopies(); } // Reshows the creditcard payment option. this.checkPaymentType(); // Loads the list boxes (with the new copy included). this.loadListBoxes(); }
public ActionResult DeleteConfirmed(int id) { DVDCopy dVDCopy = db.DVDCopies.Find(id); db.DVDCopies.Remove(dVDCopy); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// The Update method is used to update the record within the database table to the instance /// data of the received object. It then coverts the instance data /// into a passable dictionary of data, which is then passed to the generic helper method of /// the DataSQL class along with the statement. The ID is also added at the end of the dictionary, /// since it is the last variable (within the where clause) of the update statement. /// </summary> /// <param name="copy">The dvd copy object.</param> /// <returns>A boolean indicating whether the record was updated.</returns> public static Boolean Update(DVDCopy copy) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("@Barcode", copy.barcode); parameters.Add("@Status", (int)copy.status); parameters.Add("@copyID", copy.copyID); return(DataSQL <DVDCopy> .NonQuery(SQL_UPDATE, parameters) > 0); }
/// <summary> /// The Add method is used to insert the received object into the corresponding database table. /// It coverts the object attributes into a dictionary, which is then passed /// into the DataSQL helper method along with the insert sql statement. /// </summary> /// <param name="copy">The dvd copy object.</param> /// <returns>A boolean indicating whether the record was inserted.</returns> public static Boolean Add(DVDCopy copy) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("@dvdID", copy.dvdID); parameters.Add("@Barcode", copy.barcode); parameters.Add("@Status", (int)copy.status); return(DataSQL <DVDCopy> .NonQuery(SQL_INSERT, parameters) > 0); }
public ActionResult Edit([Bind(Include = "DCopyId,DVDId,Price,ReleasedDate,Description")] DVDCopy dVDCopy) { if (ModelState.IsValid) { db.Entry(dVDCopy).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DVDId = new SelectList(db.DVDDetails, "DVDId", "Title", dVDCopy.DVDId); return(View(dVDCopy)); }
// GET: DVDCopies/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DVDCopy dVDCopy = db.DVDCopies.Find(id); if (dVDCopy == null) { return(HttpNotFound()); } return(View(dVDCopy)); }
// GET: DVDCopies/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DVDCopy dVDCopy = db.DVDCopies.Find(id); if (dVDCopy == null) { return(HttpNotFound()); } ViewBag.DVDId = new SelectList(db.DVDDetails, "DVDId", "Title", dVDCopy.DVDId); return(View(dVDCopy)); }
/// <summary> /// The saveCopies method adds the copies that are stored in either the rentals dictionary, or the purchases dictionary /// into the transaction object. /// </summary> /// <param name="transaction">The transaction object</param> /// <param name="isRental">A boolean indicating which dictionary list to iterate (true for rentals, false for purchases)</param> private void saveCopies(Transaction transaction, Boolean isRental) { // Iterates for each copy stored in the dictionary (either being the rentals or purchases). foreach (KeyValuePair <String, DVDCopy> entry in ((isRental) ? this.lstRentals : this.lstPurchases)) { DVDCopy copy = entry.Value; // Gets the copy object from the KeyValuePair // If the copy doesn't already exist in the transaction if (!transaction.copyExists(copy)) { transaction.AddItem(copy, (isRental) ? TransactionItem.TransactionType.RENTAL : TransactionItem.TransactionType.SALE); // Sets the availability of the copy to being false, so it can't be rented again. copy.status = DVDCopy.Status.UNAVAILABLE; DVDCopy.UpdateCopy(copy); } } }
/// <summary> /// The event is fired when the update button is pressed. It will check to see if the values are valid before /// making changes to the object. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gridCopies_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Gets the row. GridViewRow row = gridCopies.Rows[e.RowIndex]; // Gets the barcode textbox from the row. TextBox txtBarcode = (TextBox)(row.Cells[0].Controls[0]); // Checks to see whether the barcode entered is valid. if (this.validateBarcode(txtBarcode.Text)) { // Then get the relating DVDCopy from the DVD based on the Row index. DVDCopy copy = DVDCopy.FetchCopy(Convert.ToInt32(gridCopies.DataKeys[e.RowIndex].Value)); // Sets the barcode property of the DVDCopy to the value in the textbox. copy.barcode = ((TextBox)(row.Cells[0].Controls[0])).Text; // Sets the isAvailable property of the DVDCopy to the value from the checkbox. copy.status = (((CheckBox)(row.Cells[1].Controls[0])).Checked) ? DVDCopy.Status.AVAILABLE : DVDCopy.Status.UNAVAILABLE; if (DVDCopy.UpdateCopy(copy)) { // Shows a friendly message stating the copy has been updated. this.lblMessage.Text = "A copy has been updated."; this.lblMessage.ForeColor = System.Drawing.Color.Green; this.lblMessage.Visible = true; this.gridCopies.EditIndex = -1; // Ends the EditMode. this.RefreshCopies(); // Refreshes the DVDCopy DataGridView to reflect the changes. this.btnInsert.Enabled = true; // Enables the Insert button again. } else { // Shows a message stating the barcode is invalid. this.lblMessage.Text = "Barcode already exists."; this.lblMessage.ForeColor = System.Drawing.Color.Red; this.lblMessage.Visible = true; } } else { // Shows a message stating the barcode is invalid. this.lblMessage.Text = "A barcode must be 5 digits."; this.lblMessage.ForeColor = System.Drawing.Color.Red; this.lblMessage.Visible = true; e.Cancel = true; // Keeps it in Edit mode. } }
/// <summary> /// The row command event is triggered when actions are done associated with the copies DataGridView. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gridCopies_RowCommand(object sender, GridViewCommandEventArgs e) { // If the action is a delete if (e.CommandName == "cmdDelete") { // It will then get the index position of the element. int key = Convert.ToInt32(gridCopies.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Value); // It will fetch the associated DVD object. if (DVDCopy.RemoveCopy(key)) { // Displays a awesome message letting the user know. this.lblMessage.Text = "A copy has been removed."; this.lblMessage.ForeColor = System.Drawing.Color.Green; this.lblMessage.Visible = true; this.RefreshCopies(); // Reloads the copies. } else { this.lblMessage.Text = "Cannot Delete. Used elsewhere."; this.lblMessage.ForeColor = System.Drawing.Color.Red; this.lblMessage.Visible = true; } } }
/// <summary> /// The copyExists method checks whether a copy already exists within the dictionaries on the form. /// </summary> /// <param name="copy">The DVDCopy</param> /// <returns>A boolean indicating whether it exists</returns> private Boolean copyExists(DVDCopy copy) { return(this.lstRentals.ContainsKey(copy.barcode) || this.lstPurchases.ContainsKey(copy.barcode)); }