Exemple #1
0
    public void Bind()
    {
        List <Cars> carsownedbyuser = new Cars().GetCarsOwnedByUser(Convert.ToInt32(Session["ttid"]));

        d.DataSource = new Cars().GetALl().Where(i => !carsownedbyuser.Any(p => i.carId == p.carId));
        d.DataBind();
        a.DataSource = new Cars().GetALl().Where(i => !carsownedbyuser.Any(p => i.carId == p.carId));
        a.DataBind();
    }
        //------------------------------------------------------------------
        private int GetFreePosition(int sign)
        {
            int position = 0;
            int lower    = 0 + sign * border;
            int upper    = height + sign * border;

            // Get free position for 20 iterations
            foreach (var index in Enumerable.Range(0, 20))
            {
//                if (index == 19) Console.WriteLine ("No Space");

                position = Random.Next(lower, upper);

                if (!Cars.Any())
                {
                    break;
                }

                float minimum = Cars.Min(car => Math.Abs(car.Position.Y - position));

                if (minimum > 150)
                {
                    break;
                }
            }

            return(position);
        }
Exemple #3
0
        protected override void ExecuteCore()
        {
            var isAnyCar = Cars.Any();
            var isAnyCarWithAPriceGreaterThanThirty = Cars.Any(x => x.Price > 30);

            Console.Write("\tAny Car - " + isAnyCar);
            Console.WriteLine("\n\tIs there any car with a price greater than 30 - " + isAnyCarWithAPriceGreaterThanThirty);
        }
 public void OnCarVersionChanged(CarObject car)
 {
     if (!_carVersionIsWrong || !PortExtended.HasValue ||
         Cars?.Any(x => x.CarObjectWrapper?.Value == car) != true)
     {
         return;
     }
     CheckPostUpdate();
 }
Exemple #5
0
 public void OnCarVersionChanged(CarObject car)
 {
     if (!_carVersionIsWrong || !HasDetails ||
         Cars?.Any(x => x.CarWrapper?.Value == car) != true)
     {
         return;
     }
     CheckPostUpdate();
 }
Exemple #6
0
 public void RemoveSetOfRegistrationNumber(List <string> registrationNumbers)
 {
     foreach (var item in registrationNumbers)
     {
         if (Cars.Any(x => x.RegistrationNumber == item))
         {
             Cars.RemoveAll(x => x.RegistrationNumber == item);
         }
     }
 }
Exemple #7
0
 public void RemoveSetOfRegistrationNumber(List <string> RegistrationNumbers)
 {
     foreach (var registrationNumber in RegistrationNumbers)
     {
         if (Cars.Any(c => c.RegistrationNumber == registrationNumber))
         {
             Cars = Cars.Where((c => c.RegistrationNumber != registrationNumber)).ToList();
         }
     }
 }
Exemple #8
0
 public string RemoveCar(string registrationNumber)
 {
     if (Cars.Any(x => x.RegistrationNumber == registrationNumber))
     {
         Cars.RemoveAll(x => x.RegistrationNumber == registrationNumber);
         return($"Successfully removed {registrationNumber}");
     }
     else
     {
         return("Car with that registration number, doesn't exist!");
     }
 }
Exemple #9
0
 public string RemoveCar(string registrationNumber)
 {
     if (Cars.Any(c => c.RegistrationNumber == registrationNumber))
     {
         Cars = Cars.Where(c => c.RegistrationNumber != registrationNumber).ToList();
         return($"Successfully removed {registrationNumber}");
     }
     else
     {
         return("Car with that registration number, doesn't exist!");
     }
 }
Exemple #10
0
 public string RemoveCar(string regNum)
 {
     if (!Cars.Any(x => x.RegistrationNumber == regNum))
     {
         return("Car with that registration number, doesn't exist!");
     }
     else
     {
         var carToRemove = Cars.FindIndex(x => x.RegistrationNumber == regNum);
         Cars.RemoveAt(carToRemove);
         return($"Successfully removed {regNum}");
     }
 }
Exemple #11
0
        public string RemoveCar(string registrationNumber)
        {
            if (Cars.Any(car => car.RegistrationNumber == registrationNumber))
            {
                var carToRemove = this.Cars.FirstOrDefault(c => c.RegistrationNumber == registrationNumber);
                this.Cars.Remove(carToRemove);

                return($"Successfully removed {registrationNumber}");
            }
            else
            {
                return($"Car with that registration number, doesn't exist!");
            }
        }
Exemple #12
0
 public string AddCar(Car car)
 {
     if (Cars.Any(x => x.RegistrationNumber == car.RegistrationNumber))
     {
         return("Car with that registration number, already exists!");
     }
     else if (Cars.Count == capacity)
     {
         return("Parking is full!");
     }
     else
     {
         Cars.Add(car);
         return($"Successfully added new car {car.Make} {car.RegistrationNumber}");
     }
 }
Exemple #13
0
 public static bool AddCar(Car newCar)
 {
     if (Cars.Any(car => car.Id == newCar.Id))
     {
         Console.WriteLine("Such car already exists. Try another car(id).");
     }
     if (newCar != null && Settings.ParkingSpace > Cars.Count)
     {
         cars.Add(newCar);
         ParkingSpace--;
         Console.WriteLine("Car successfully added.");
         return(true);
     }
     Console.WriteLine("Can't add new car");
     return(false);
 }
Exemple #14
0
 public void Remove(Car carToRemove)
 {
     if (carToRemove != null)
     {
         Cars.Remove(carToRemove);
         if (Cars.Any())
         {
             SelectedCar = Cars.Last();
         }
         else
         {
             SelectedCar = null;
         }
     }
     else
     {
         throw new ArgumentNullException("There are no Car Models to be removed.");
     }
 }
Exemple #15
0
        private async Task CreateACarAsync()
        {
            using (UserDialogs.Instance.Loading("Loading"))
            {
                SelectedCar.RentId = CurrentRent.Id;
                var json = JsonConvert.SerializeObject(SelectedCar);
                var g    = json.Remove(1, 7);
                App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                HttpContent httpContent = new StringContent(g, Encoding.UTF8, "application/json");
                var         response    = await App.client.PostAsync(App.API_URL_BASE + "cars", httpContent);

                if (response.IsSuccessStatusCode)
                {
                    UserDialogs.Instance.Alert("Vetura u shtua me sukses", "Sukses", "OK");
                }
                else
                {
                    UserDialogs.Instance.Alert("Vetura nuk u shtua me sukses", "Error", "OK");
                }
                var responseString = await response.Content.ReadAsStringAsync();

                Car addedCar = JsonConvert.DeserializeObject <Car>(responseString);
                if (Cars != null && !Cars.Any())
                {
                    Cars = new ObservableCollection <Car>();
                }
                Cars.Add(addedCar);
                HasCars = Cars.Any();
                OnPropertyChanged("Cars");
                OnPropertyChanged("HasCars");
                HasAvailableCars = true;
                AvailableCars.Add(addedCar);
                OnPropertyChanged("HasAvailableCars");
                OnPropertyChanged("AvailableCars");
            }
        }
Exemple #16
0
 internal bool HasCar(string registration) => Cars.Any(x => x.HasRegistration(registration));
Exemple #17
0
        public void InitialDbData()
        {
            if (!Cars.Any())
            {
                List <Vehicle> cars = new List <Vehicle>()
                {
                    new Car()
                    {
                        CarId = Guid.Parse("7295a624-dea8-479c-b920-a3254f92af77"), CurrentDistance = 20.3, RegistrationNumber = "KRA2436", Status = Status.wolny, TotalDistance = 15034.5, XPosition = 2.4, YPosition = 5.2
                    },
                    new Car()
                    {
                        CarId = Guid.Parse("6291ffd4-cb73-4c37-aa9a-1591247f554d"), CurrentDistance = 13.7, RegistrationNumber = "KOL0201", Status = Status.wypożyczony, TotalDistance = 20134.5, XPosition = 1.4, YPosition = -2.2
                    },
                    new Car()
                    {
                        CarId = Guid.Parse("7fb934b4-dae2-4659-a9ee-d5af7af36f40"), CurrentDistance = 20.3, RegistrationNumber = "KRA2436", Status = Status.wolny, TotalDistance = 15034.5, XPosition = 2.4, YPosition = 5.2
                    }
                };
                foreach (Car item in cars)
                {
                    Cars.Add(item);
                    var carReadModel = new CarViewModel()
                    {
                        CarId              = item.CarId,
                        CurrentDistance    = item.CurrentDistance,
                        RegistrationNumber = item.RegistrationNumber,
                        Status             = item.Status,
                        TotalDistance      = item.TotalDistance,
                        XPosition          = item.XPosition,
                        YPosition          = item.YPosition
                    };
                    CarViewModels.Add(carReadModel);
                }
            }

            if (!Drivers.Any())
            {
                Driver driver = new Driver("42222/12/01118", "Jan", "Kowalski");
                driver.DriverId = Guid.Parse("0871afd6-dae6-45f2-b9cf-8f91f184d6af");

                Drivers.Add(driver);

                DriverViewModel driverViewModel = new DriverViewModel()
                {
                    DriverId      = driver.DriverId,
                    FirstName     = driver.FirstName,
                    LastName      = driver.LastName,
                    LicenceNumber = driver.LicenceNumber
                };

                DriverViewModels.Add(driverViewModel);
            }

            if (!Rentals.Any())
            {
                Rental rental = new Rental()
                {
                    RentalId = Guid.Parse("1c3444e1-e09c-48a1-9cf2-db713731b5b1"),
                    CarId    = Guid.Parse("6291ffd4-cb73-4c37-aa9a-1591247f554d"),
                    Started  = DateTime.ParseExact("21/05/2020 07:25:47", "dd/MM/yyyy hh:mm:ss", CultureInfo.InvariantCulture),
                    DriverId = Guid.Parse("0871afd6-dae6-45f2-b9cf-8f91f184d6af")
                };

                Rentals.Add(rental);

                if (Cars.Any())
                {
                    var carToUpdate = Cars.FirstOrDefault(x => x.CarId == rental.CarId);
                    carToUpdate.ChangeStatus();
                }

                RentalReadModel rentalReadModel = new RentalReadModel()
                {
                    RentalId           = rental.RentalId,
                    RegistrationNumber = "KOL0201",
                    CarId          = rental.CarId,
                    DriverId       = rental.DriverId,
                    Driver         = "Jan Kowalski",
                    Created        = rental.Started,
                    StartXPosition = 1.4,
                    StartYPosition = -2.2
                };

                RentalReadModels.Add(rentalReadModel);
            }

            this.SaveChanges();
        }
Exemple #18
0
 public bool IsAutoJoinReady(bool anyCar)
 {
     return(Status == ServerStatus.Ready && !IsBookedForPlayer && !BookingMode && (anyCar ? Cars?.Any(x => x.IsAvailable) == true : IsAvailable));
 }
Exemple #19
0
        protected async Task CheckForAlerts()
        {
            try
            {
                if (Cars.Any())
                {
                    foreach (var car in Cars)
                    {
                        if ((car.NextDateOfCheck - DateTime.Now).TotalDays <= 2)
                        {
                            var res = await UserDialogs.Instance.ConfirmAsync("Vetura " + car.Name + " me targat :" + car.Targa + " duhet te regjistrohet", "Koha per regjistrim", "Perfundo regjistrimin", "Me Vone");

                            if (res)
                            {
                                using (UserDialogs.Instance.Loading("Duke regjistruar veturen"))
                                {
                                    Notifications notifications = new Notifications
                                    {
                                        DateReceived   = DateTime.Now,
                                        HasInteraction = true,
                                        IsImportant    = true,
                                        IsRead         = true,
                                        Message        = "Vetura " + car.Name + " me targat :" + car.Targa + " duhet te regjistrohet",
                                        Title          = "Regjistrimi: " + car.Targa,
                                        RentID         = CurrentRent.Id
                                    };
                                    var         serializedNotification  = JsonConvert.SerializeObject(notifications);
                                    HttpContent httpContentNotification = new StringContent(serializedNotification, Encoding.UTF8, "application/json");
                                    var         notificationAdded       = await App.client.PostAsync(App.API_URL_BASE + "rents/notifications/add", httpContentNotification);

                                    if (!notificationAdded.IsSuccessStatusCode)
                                    {
                                        UserDialogs.Instance.Alert("Mesazhi deshtoi te shtohet ne databaze", "Deshtim Mesazhi");
                                    }
                                    var json = JsonConvert.SerializeObject(car);
                                    App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                                    HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");
                                    var         response    = await App.client.PutAsync(App.API_URL_BASE + "rents/cars/register", httpContent);

                                    if (response.IsSuccessStatusCode)
                                    {
                                        UserDialogs.Instance.Alert("Vetura " + car.Name + " me targat :" + car.Targa + " u regjistrua per 6 muaj me sukses", "Sukses", "OK");
                                    }
                                    else
                                    {
                                        UserDialogs.Instance.Alert("Vetura " + car.Name + " me targat :" + car.Targa + " nuk u regjistrua me sukses", "Error", "OK");
                                        continue;
                                    }
                                    var responseString = await response.Content.ReadAsStringAsync();

                                    var RegisteredCar = JsonConvert.DeserializeObject <Car>(responseString);
                                    car.NextDateOfCheck = RegisteredCar.NextDateOfCheck;
                                }
                            }
                            else
                            {
                                Notifications notifications = new Notifications
                                {
                                    DateReceived   = DateTime.Now,
                                    HasInteraction = true,
                                    IsImportant    = true,
                                    IsRead         = false,
                                    Message        = "Vetura " + car.Name + " me targat :" + car.Targa + " duhet te regjistrohet",
                                    Title          = "Regjistrimi: " + car.Targa,
                                    RentID         = CurrentRent.Id
                                };
                                var         serializedNotification  = JsonConvert.SerializeObject(notifications);
                                HttpContent httpContentNotification = new StringContent(serializedNotification, Encoding.UTF8, "application/json");
                                var         notificationAdded       = await App.client.PostAsync(App.API_URL_BASE + "rents/notifications/add", httpContentNotification);

                                if (!notificationAdded.IsSuccessStatusCode)
                                {
                                    UserDialogs.Instance.Alert("Mesazhi deshtoi te shtohet ne databaze", "Deshtim Mesazhi");
                                }
                            }
                        }
                    }
                }
            }catch (Exception e)
            {
                var res = e.Message;
            }
        }
 private bool CarExistInParking(int carId)
 {
     return(Cars.Any(cus => cus.Id == carId));
 }