/// <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); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="diskId"></param> /// <returns> /// Have late charge and add success return 1 /// Have late charge and add fail return -1 /// Not have late charge return 0 /// Order return -2 /// </returns> public int Add(int diskId, DateTime DateReturn) { //Check status disk DiskRepository diskRepository = new DiskRepository(new DBVRContext()); Disk disk = diskRepository.Get(diskId); if (disk != null) { if (disk.Status.Equals(StatusOfDisk.RENTED)) { RentalRecordDetail detail = detailRepository.GetLatest(diskId); if (detail != null) { using (TransactionScope transaction = new TransactionScope()) { try { detail.DateReturnActual = DateReturn; detail.LateCharge = disk.TitleDisk.TypeDisk.LateCharge; detailRepository.Update(detail); diskRepository.ModifyStatus(disk, StatusOfDisk.ON_SHELF); transaction.Complete(); return(1); } catch { transaction.Dispose(); return(0); } } } return(-1); } } return(-2); }