private List <Vehicles> GetAllAvaliableVehicles(DateTime date) { try { using (var vehicleBusiness = new VehicleBusiness()) { var vehicles = vehicleBusiness.GetAll(); using (var rentedbusiness = new RentedVehicleBusiness()) { var rentedVehicles = rentedbusiness.GetAll(); foreach (var rentedvehicle in rentedVehicles) { List <DateTime> isntavaliabletimes = new List <DateTime>(); for (DateTime time = rentedvehicle.PickUpDate.Date; time <= rentedvehicle.DropOffDate.Date; time = time.AddDays(1)) { isntavaliabletimes.Add(time); } if (isntavaliabletimes.Contains(date)) { var removethisvehicle = vehicleBusiness.GetByID(rentedvehicle.RentId); vehicles.Remove(removethisvehicle); } } return(vehicles); } } } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("Request doesn't exists."); } }
public bool ApproveOrDenyTheRequest(RentalRequests rentalRequests, bool isApprove, decimal rentalprice, int pickupkm, int dropoffkm) { try { bool isDeleteSuccess = false, isInsertSuccess = false; if (isApprove) { using (var rentedvehiclebusiness = new RentedVehicleBusiness()) { var rentedvehicle = new RentedVehicles(); rentedvehicle.DriverCustomerId = rentalRequests.RentalRequestCustomerId; rentedvehicle.DropOffDate = rentalRequests.RequestedDropOffDate; rentedvehicle.PickUpDate = rentalRequests.RequestedPickUpDate; rentedvehicle.RentalPrice = rentalprice; rentedvehicle.RentedVehicleId = rentalRequests.RequestedVehicleId; rentedvehicle.SupplierCompanyId = rentalRequests.RequestedSupplierCompanyId; rentedvehicle.VehiclesPickUpKm = pickupkm; rentedvehicle.VehiclesDropOffKm = dropoffkm; isInsertSuccess = rentedvehiclebusiness.Insert(rentedvehicle); if (isInsertSuccess) { isDeleteSuccess = DeleteById(rentalRequests.RentalRequestId); } } } else { isDeleteSuccess = DeleteById(rentalRequests.RentalRequestId); } return(isDeleteSuccess); } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("CarRental.BusinessLogic.Concretes:RentalRequestBusiness::ApproveOrDenyTheRequest:Error occured.", ex); } }
private bool ApproveAndAdd(int ID) { try { using (var rentalRequesBusiness = new RentalRequestBusiness()) { RentalRequests rentalreq = rentalRequesBusiness.GetByID(ID); var rentingtime = Convert.ToInt32(rentalreq.RequestedDropOffDate.Date - rentalreq.RequestedPickUpDate.Date); using (var vehicleBusiness = new VehicleBusiness()) { Vehicles reqvehicle = vehicleBusiness.GetByID(rentalreq.RequestedVehicleId); using (var rentedvehicleBusiness = new RentedVehicleBusiness()) { RentedVehicles rentvehicle = new RentedVehicles() { RentalPrice = reqvehicle.DailyRentalPrice * rentingtime, DropOffDate = rentalreq.RequestedDropOffDate, PickUpDate = rentalreq.RequestedPickUpDate, VehiclesPickUpKm = reqvehicle.VehiclesInstantKm, VehiclesDropOffKm = reqvehicle.VehiclesInstantKm + (reqvehicle.KmLimitPerDay * rentingtime), SupplierCompanyId = rentalreq.RequestedSupplierCompanyId, RentedVehicleId = rentalreq.RequestedVehicleId, DriverCustomerId = rentalreq.RentalRequestCustomerId }; DeleteRequest(ID); return(rentedvehicleBusiness.Insert(rentvehicle)); } } } } catch (Exception ex) { LogHelper.Log(LogTarget.File, ExceptionHelper.ExceptionToString(ex), true); throw new Exception("Request doesn't exists."); } }