static void Main(string[] args) { var mt = new MovieTicket(); double oPrice = 60.0; mt.Price = oPrice; Console.WriteLine("原始票价:{0}", oPrice); Console.WriteLine("----------------------------------------"); IDiscount discount1 = new StudentDiscount(); if (discount1 != null) { mt.Discount = discount1; var currPrice = mt.Price; Console.WriteLine("学生折后票价:{0}", currPrice); } IDiscount discount2 = new VIPDiscount(); if (discount2 != null) { mt.Discount = discount2; var currPrice = mt.Price; Console.WriteLine("VIP折后票价:{0}", currPrice); } IDiscount discount3 = new ChildrenDiscount(); if (discount3 != null) { mt.Discount = discount3; var currPrice = mt.Price; Console.WriteLine("儿童折后票价:{0}", currPrice); } }
public ActionResult DeleteConfirmed(int id) { StudentDiscount studentDiscount = db.StudentDiscounts.Find(id); db.StudentDiscounts.Remove(studentDiscount); db.SaveChanges(); return(RedirectToAction("StudentDiscountIndex")); }
// GET: StudentDiscounts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentDiscount studentDiscount = db.StudentDiscounts.Find(id); if (studentDiscount == null) { return(HttpNotFound()); } return(View(studentDiscount)); }
public ActionResult Edit([Bind(Include = "Id,FeeDiscountId,StudentId")] StudentDiscount studentDiscount) { if (ModelState.IsValid) { var Month = Request.Form["Month"]; studentDiscount.Month = Month; db.Entry(studentDiscount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("StudentDiscountIndex")); } ViewBag.StudentId = new SelectList(db.AspNetStudents, "Id", "Name", studentDiscount.StudentId); ViewBag.FeeDiscountId = new SelectList(db.FeeDiscounts, "Id", "Name", studentDiscount.FeeDiscountId); return(View(studentDiscount)); }
public ActionResult Create([Bind(Include = "Id,FeeDiscountId,StudentId")] StudentDiscount studentDiscount) { string S_UID = Request.Form["StudentId"]; int? S_Id = db.AspNetStudents.Where(x => x.StudentID == S_UID).Select(x => x.Id).FirstOrDefault(); if (S_UID != null && S_Id != 0) { studentDiscount.StudentId = S_Id; try { var Month = Request.Form["Month"]; studentDiscount.Month = Month; studentDiscount.Status = "Pending"; db.StudentDiscounts.Add(studentDiscount); db.SaveChanges(); //Student_ChallanForm std_from = db.Student_ChallanForm.Where(x => x.StudentId == studentDiscount.StudentId).FirstOrDefault(); //var amount = db.FeeDiscounts.Where(x => x.Id == studentDiscount.FeeDiscountId).Select(x => x.Amount).FirstOrDefault(); //std_from.AmountPayable -= amount; //db.SaveChanges(); //var fee = db.StudentDiscounts.Where(x => x.FeeDiscountId == studentDiscount.FeeDiscountId).Select(x => x.FeeDiscount.Amount).FirstOrDefault(); //Ledger ledger = db.Ledgers.Where(x => x.Name == "Student Receivables").FirstOrDefault(); //ledger.StartingBalance -= fee; //ledger.CurrentBalance -= fee; //db.SaveChanges(); //Ledger l = db.Ledgers.Where(x => x.Name == "Student Fee").FirstOrDefault(); //l.StartingBalance -= fee; //l.CurrentBalance -= fee; //db.SaveChanges(); return(RedirectToAction("StudentDiscountIndex")); } catch { return(RedirectToAction("Create")); } } else { return(RedirectToAction("StudentDiscountIndex")); } ViewBag.StudentId = new SelectList(db.AspNetStudents, "Id", "Name", studentDiscount.StudentId); ViewBag.FeeDiscountId = new SelectList(db.FeeDiscounts, "Id", "Name", studentDiscount.FeeDiscountId); return(View(studentDiscount)); }
// GET: StudentDiscounts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentDiscount studentDiscount = db.StudentDiscounts.Find(id); if (studentDiscount == null) { return(RedirectToAction("StudentDiscountIndex")); } ViewBag.StudentId = new SelectList(db.AspNetStudents, "Id", "Name", studentDiscount.StudentId); ViewBag.FeeDiscountId = new SelectList(db.FeeDiscounts, "Id", "Name", studentDiscount.FeeDiscountId); return(View(studentDiscount)); }