public void Create_newRentalRecord(int customerid, int employeeid, RentalRecord record) { using (var context = new eToolsContext()) { decimal subtotal = 0; decimal taxamount = 0; Rental newRentalRecord = null; newRentalRecord.CustomerID = customerid; newRentalRecord.EmployeeID = employeeid; newRentalRecord.CouponID = record.CouponID; foreach (var item in record.Details) { subtotal += item.DailyRate * (decimal)item.Days; } newRentalRecord.SubTotal = subtotal; taxamount = (decimal)0.05 * subtotal; newRentalRecord.TaxAmount = taxamount; newRentalRecord.RentalDate = record.RentalDate; newRentalRecord.PaymentType = "C"; newRentalRecord.CreditCard = record.CreditCard; if (newRentalRecord != null) { context.Rentals.Add(newRentalRecord); context.SaveChanges(); } else { throw new Exception("Rental record was created failed."); } } }
public void Run() { // read movies from file foreach (Movie movie in this.movieRepository.GetAll()) { this._out.WriteLine(movie.Key + ": " + movie.Name); } _out.Write("Enter customer name: "); string customerName = _in.ReadLine(); _out.WriteLine("Choose movie by number followed by rental days, just ENTER for bill:"); List<Rental> rentals = this.InputRentals(); var rentalRecord = new RentalRecord(customerName, rentals); string result = "Rental Record for " + rentalRecord.CustomerName + "\n"; foreach (var rental in rentalRecord.Rentals) { // show figures for this rental result += "\t" + rental.GetMovieName() + "\t" + rental.GetAmount().ToString("0.0", CultureInfo.InvariantCulture) + "\n"; } // add footer lines result += "You owed " + rentalRecord.GetTotalAmount().ToString("0.0", CultureInfo.InvariantCulture) + "\n"; result += "You earned " + rentalRecord.GetFrequentRenterPoints() + " frequent renter points\n"; _out.Write(result); }
public ActionResult DeleteConfirmed(int id) { RentalRecord rentalRecord = db.RentalRecords.Find(id); db.RentalRecords.Remove(rentalRecord); db.SaveChanges(); return(RedirectToAction("Index")); }
public void PrintRentalRecord(RentalRecord rentalRecord) { @out.WriteLine("Rental Record for " + rentalRecord.CustomerName); foreach (var rental in rentalRecord.Rentals) { // show figures for this rental @out.WriteLine( "\t" + rental.GetMovieName() + "\t" + rental.GetAmount().ToString("0.0", CultureInfo.InvariantCulture)); } }
/// <summary> /// Initialize RentalRecord: /// Calculate the total payment, /// add customerId /// </summary> /// <param name="customerId"></param> /// <param name="details"></param> /// <returns>RentalRecord</returns> public RentalRecord Initialize(int customerId, List <RentalRecordDetail> details) { RentalRecord rentalRecord = new RentalRecord(); rentalRecord.CustomerID = customerId; rentalRecord.DateRental = DateTime.Now; rentalRecord.RentalRecordDetails = details; rentalRecord.TotalPrice = CalculateTotalPayment(details); return(rentalRecord); }
/// <summary> /// Lấy ra khách hàng có đĩa trả trễ /// </summary> /// <param name="DiskID"> mã đĩa trả trễ</param> /// <returns>khách hàng</returns> public Customer GetCustomerByDiskLateCharge(int DiskID) { // lấy danh sách hóa đơn có đĩa quá hạn. RentalRecordDetail rentalRecordDetail = new RentalRecordDetail(); rentalRecordDetail = _context.RentalRecordDetails.Where(x => x.DiskID == DiskID && x.LateCharge != null).FirstOrDefault(); RentalRecord rentalRecord = new RentalRecord(); rentalRecord = _context.RentalRecords.Where(x => x.RentalRecordID.Equals(rentalRecordDetail.RentalRecordID)).FirstOrDefault(); return(_context.Customers.Where(c => c.CustomerID.Equals(rentalRecord.CustomerID)).FirstOrDefault()); }
public ActionResult Edit([Bind(Include = "RentalID,MovieID,CustomerID,RentalDate,DueDate,ReturnDate")] RentalRecord rentalRecord) { if (ModelState.IsValid) { db.Entry(rentalRecord).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "MovieName", rentalRecord.MovieID); return(View(rentalRecord)); }
public void Run() { console.PrintMovies(movieRepository.GetAll()); string customerName = console.InputCustomerName(); List<Rental> rentals = console.InputRentals(); var rentalRecord = new RentalRecord(customerName, rentals); console.PrintRentalRecord(rentalRecord); console.PrintFooter(rentalRecord); }
public async Task AddAsync(RentalRecord rentalRecord, CancellationToken cancellationToken = default) { if (rentalRecord == null) { throw new ArgumentNullException(); } await toolShedContext.RentalRecordSet .AddAsync(rentalRecord, cancellationToken); await toolShedContext.SaveChangesAsync(cancellationToken); }
public ActionResult Create([Bind(Include = "RentalID,MovieID,CustomerID,RentalDate,DueDate,ReturnDate")] RentalRecord rentalRecord) { if (ModelState.IsValid) { db.RentalRecords.Add(rentalRecord); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerID = new SelectList(db.CustomerInfoes, "CustomerID", "CustomerName", rentalRecord.CustomerID); ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "MovieName", rentalRecord.MovieID); return(View(rentalRecord)); }
/// <summary> /// /// </summary> /// <param name="disk"></param> /// <returns> /// Have late charge return 1 /// Not have late charge return 0 /// error return 1 /// exception return 2 /// </returns> public int ReturnDisk(Disk disk, DateTime dateReturn) { if (disk != null) { AddLateCharge addLateCharge = new AddLateCharge(); RentalRecordDetail detailLatest = detailRepository.GetLatest(disk.DiskID); RentalRecord rentalRecord = recordRepository.Get(detailLatest.RentalRecordID); if (detailLatest != null) { if (dateReturn > detailLatest.DateReturn.Date) { int result = addLateCharge.Add(disk.DiskID, dateReturn); if (result >= 0) { return(1); } else { return(-1); } } else if (dateReturn < rentalRecord.DateRental) { return(3); } else { using (TransactionScope transaction = new TransactionScope()) { try { detailLatest.DateReturnActual = dateReturn; detailRepository.Update(detailLatest); diskRepository.ModifyStatus(disk, StatusOfDisk.ON_SHELF); //reservationRepository.AddReservationReturnDisk(disk.DiskID); transaction.Complete(); return(0); } catch { transaction.Dispose(); return(-2); } } } } } return(-1); }
// GET: RentalRecords/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalRecord rentalRecord = db.RentalRecords.Find(id); if (rentalRecord == null) { return(HttpNotFound()); } return(View(rentalRecord)); }
// GET: RentalRecords/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RentalRecord rentalRecord = db.RentalRecords.Find(id); if (rentalRecord == null) { return(HttpNotFound()); } ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "MovieName", rentalRecord.MovieID); return(View(rentalRecord)); }
public void Delete_RentalRecord(int customerid, int employeeid, RentalRecord rentalRecord) { using (var context = new eToolsContext()) { var exists = (from x in context.Rentals where x.CustomerID.Equals(customerid) && x.EmployeeID.Equals(employeeid) && x.RentalDate == rentalRecord.RentalDate select x).FirstOrDefault(); if (exists == null) { throw new Exception("Rental record has been removed."); } else { context.Rentals.Remove(exists); context.SaveChanges(); } } }
/// <summary> /// Add a RentalRecord and change status of disk rented /// </summary> /// <param name="rentalRecord"></param> /// <returns></returns> public bool AddRentalRecord(RentalRecord rentalRecord) { if (rentalRecord != null) { using (var transaction = new TransactionScope()) { try { rentalRepository.Insert(rentalRecord); diskRepository.ModifyStatus(rentalRecord.RentalRecordDetails.Select(x => x.DiskID).ToList(), StatusOfDisk.RENTED); transaction.Complete(); return(true); } catch { transaction.Dispose(); return(false); } } } return(false); }
public void PrintFooter(RentalRecord rentalRecord) { // add footer lines @out.WriteLine("You owed " + rentalRecord.GetTotalAmount().ToString("0.0", CultureInfo.InvariantCulture)); @out.WriteLine("You earned " + rentalRecord.GetFrequentRenterPoints() + " frequent renter points"); }
public bool Overlapping(RentalRecord rentalRecord) { return(StartDay <= rentalRecord.EndDay && rentalRecord.StartDay <= EndDay); }
protected void EquipmentAdd(object sender, CommandEventArgs e) { string username = User.Identity.Name; int employeeid; int equipmentid = int.Parse(e.CommandArgument.ToString()); int customerid = int.Parse(CurrentCustomerID.Text); //ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore<ApplicationUser>(new ApplicationDbContext())); //EmployeeInfo info = secmgr.User_GetEmployee(username); employeeid = 1;//info.EmployeeID; List <RentalDetailRecord> details = new List <RentalDetailRecord>(); List <RentalEquipment> einfoList = new List <RentalEquipment>(); ShowCouponForm(); if (employeeid == 0) { MessageUserControl.ShowInfo("Warning", "Please login as an Employee!"); } else { MessageUserControl.TryRun(() => { RentalRecord Record = null; RentalDetailRecord Detail = null; if (CurrentRentalDetailListView.Items.Count == 0) { Record = new RentalRecord(); Detail = new RentalDetailRecord(); Detail.RentalEquipmentID = equipmentid; RentalEquipmentController resysmgr = new RentalEquipmentController(); RentalEquipment reinfo = resysmgr.Equipment_Find_byID(equipmentid); Detail.DailyRate = reinfo.DailyRate; Detail.Days = 1; Detail.ConditionOut = reinfo.Condition; Detail.Paid = false; Record.RentalDate = DateTime.Now; if (Detail == null) { MessageUserControl.ShowInfo("Warning", "Create new Rental failed!"); } else { details.Add(Detail); } Record.Details = details; RentalController rsysmgr = new RentalController(); rsysmgr.Create_newRentalRecord(customerid, employeeid, Record); einfoList.Add(reinfo); CurrentRentalDetailListView.DataSource = einfoList; CurrentRentalDetailListView.DataBind(); } else { Detail = new RentalDetailRecord(); Detail.RentalEquipmentID = equipmentid; RentalDetailController rdsysmgr = new RentalDetailController(); var dinfo = rdsysmgr.List_RentalDetail_forRental(customerid, employeeid, Record.RentalDate); foreach (var item in dinfo) { RentalEquipmentController resysmgr = new RentalEquipmentController(); RentalEquipment reinfo = resysmgr.Equipment_Find_byID(item.RentalEquipmentID); Detail.DailyRate = reinfo.DailyRate; Detail.Days = 1; Detail.ConditionOut = reinfo.Condition; Detail.Paid = false; einfoList.Add(reinfo); } CurrentRentalDetailListView.DataSource = einfoList; CurrentRentalDetailListView.DataBind(); } }, "Found", "Customer(s) has been found"); } }