public ActionResult Create(CarRecord carRecord)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     carData.CarRecords.Add(carRecord);
     carData.SaveChanges();
     //Response.Redirect("StudentAdmission",true);
     return(RedirectToAction("CarList"));
 }
Пример #2
0
        public void TestCarRecordLookup()
        {
            CarRecord carRecord = _database.CarRecordManager.FindCarRecordByName("BMWM3GTR");

            Assert.IsNotNull(carRecord);
            Assert.AreEqual("BMWM3GTR", carRecord.CarTypeName);
            Assert.AreEqual("BMWM3GTR", carRecord.BaseModelName);
            Assert.AreEqual(@"CARS\BMWM3GTR\GEOMETRY.BIN", carRecord.GeometryFilename);
            Assert.AreEqual("BMW", carRecord.ManufacturerName);
            Assert.AreEqual(CarUsageType.Racing, carRecord.UsageType);
            Assert.AreEqual(CarMemoryType.Racing, carRecord.MemoryType);
        }
Пример #3
0
        // Update

        void UpdateCar(CarRecord car, bool byVin)
        {
            if (car == null)
            {
                ShowError("Car not found.");
                return;
            }

            selectedCar           = car;
            pgdCar.SelectedObject = selectedCar;

            deleteByVin = byVin;
        }
        public ActionResult Edit(CarRecord carRecord)
        {
            var orignalRecord = (from m in carData.CarRecords where m.Id == carRecord.Id select m).First();

            if (!ModelState.IsValid)
            {
                return(View(orignalRecord));
            }
            carData.Entry(orignalRecord).CurrentValues.SetValues(carRecord);

            carData.SaveChanges();
            return(RedirectToAction("CarList"));
        }
Пример #5
0
        private bool DoesCarAlreadyExists(CarRecord car)
        {
            bool exists = false;
            int  id     = Convert.ToInt32(car.Id);

            foreach (var item in carManager.CarsAsCarRecords)
            {
                if (id == item.Id)
                {
                    exists = true;
                    break;
                }
            }
            return(exists);
        }
Пример #6
0
        private void fillCarsAsCarRecordsFromRecords()
        {
            List <Record> carsAsRecords = carManager.Select();

            foreach (var record in carsAsRecords)
            {
                CarRecord carRecord = new CarRecord();
                carRecord.Name             = (record as CarRecord).Name;
                carRecord.UserId           = (record as CarRecord).UserId;
                carRecord.Fuel_type        = (record as CarRecord).Fuel_type;
                carRecord.Body_type        = (record as CarRecord).Body_type;
                carRecord.Manufacture_year = (record as CarRecord).Manufacture_year;
                carRecord.Motor_power      = (record as CarRecord).Motor_power;

                carManager.CarsAsCarRecords.Add(carRecord);
            }
        }
Пример #7
0
        public void CarRentWithCarCheckUpTest()
        {
            CarRecord carRecord = new CarRecord("Lada Granta", "cherry", "1234321");

            //                                  0                           1                       2                           3                           4                           5                       6                           7                           8                       9
            DateTime[] startRentDates = { new DateTime(2017, 1, 1), new DateTime(2017, 2, 1), new DateTime(2017, 2, 3), new DateTime(2017, 2, 5), new DateTime(2017, 2, 6), new DateTime(2017, 2, 7), new DateTime(2017, 2, 8), new DateTime(2017, 2, 9), new DateTime(2017, 2, 10), new DateTime(2017, 2, 21) };
            DateTime[] endRentDates   = { new DateTime(2017, 1, 20), new DateTime(2017, 2, 2), new DateTime(2017, 2, 4), new DateTime(2017, 2, 5), new DateTime(2017, 2, 6), new DateTime(2017, 2, 7), new DateTime(2017, 2, 8), new DateTime(2017, 2, 9), new DateTime(2017, 2, 10), new DateTime(2017, 2, 23) };
            bool       carRentSuccess;

            for (int i = 0; i < startRentDates.Count(); i++)
            {
                carRentSuccess = carRecord.Rent(startRentDates[i], endRentDates[i]);
                Assert.AreEqual(carRentSuccess, true);
            }

            // Время аренды попадает на уже запланированное ТО
            DateTime startOfRent = new DateTime(2017, 2, 24);
            DateTime endOfRent   = new DateTime(2017, 2, 25);

            // пробуем арендовать во время запланированного ТО
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);

            // Аренда, после которой придётся делать ТО, время которого пересечётся
            // с уже запланированной бронью:
            startOfRent = new DateTime(2017, 2, 19);
            endOfRent   = new DateTime(2017, 2, 20);
            // пробуем арендовать
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);

            // Нормальная аренда:
            startOfRent = new DateTime(2017, 2, 12);
            endOfRent   = new DateTime(2017, 2, 12);
            // пробуем арендовать на время, которое ни с чем не пересекается
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, true);

            // Аренда, сдвигающая расписание так, что только что добавленная нормальная аренда
            // попадёт на период ТО:
            startOfRent = new DateTime(2017, 1, 21);
            endOfRent   = new DateTime(2017, 1, 21);
            // пробуем арендовать
            carRentSuccess = carRecord.Rent(startOfRent, endOfRent);
            Assert.AreEqual(carRentSuccess, false);
        }
Пример #8
0
        public void CarCanBeRentedSecondTimeForProperTermTest()
        {
            CarRecord carRecord = new CarRecord("Lada Granta", "cherry", "1234321");

            DateTime[] startRentDates = { new DateTime(2017, 1, 1), new DateTime(2017, 1, 21) };
            DateTime[] endRentDates   = { new DateTime(2017, 1, 20), new DateTime(2017, 1, 22) };
            // арендуем первый раз
            bool carRentSuccess = carRecord.Rent(startRentDates[0], endRentDates[0]);

            Assert.AreEqual(carRentSuccess, true);
            // арендуем 2 раз
            carRentSuccess = carRecord.Rent(startRentDates[1], endRentDates[1]);
            Assert.AreEqual(carRentSuccess, true);

            CollectionAssert.AreEqual(carRecord.getStartRentDates(), startRentDates);
            CollectionAssert.AreEqual(carRecord.getEndRentDates(), endRentDates);
        }
Пример #9
0
        public static CarCollection CreateDefaultCarCollection()
        {
            var cars  = new CarCollection();
            var date  = new DateTime(2019, 07, 01);
            var price = uint.MaxValue - 1;

            for (var i = 1; i <= DefaultRecords; i++)
            {
                var car = new CarRecord
                {
                    Date      = date.AddDays(i).ToString(CarRecord.DateFormat),
                    BrandName = DefaultBrandName + i.ToString(),
                    Price     = price - (uint)(i * uint.MaxValue / DefaultRecords)
                };
                cars.CarRecords.Add(car);
            }

            return(cars);
        }
Пример #10
0
        private static CarCollection CreateDefaultCarCollection()
        {
            const string brandName = "Brand name (брэнд) ";
            const int    records   = 3;
            var          cars      = new CarCollection();
            var          date      = new DateTime(2019, 07, 01);
            var          price     = uint.MaxValue - 1;

            for (var i = 1; i <= records; i++)
            {
                var car = new CarRecord
                {
                    Date      = date.AddDays(i).ToString(CarRecord.DateFormat),
                    BrandName = brandName + i.ToString(),
                    Price     = price - (uint)(i * uint.MaxValue / records)
                };
                cars.CarRecords.Add(car);
            }

            return(cars);
        }
Пример #11
0
        private static void InternalRead(BinaryReader reader, CarCollection cars)
        {
            var header = reader.ReadUInt16();

            if (header != BinaryHeader)
            {
                throw new CarCollectionFormatException("Mismatch data format: signature is wrong");
            }

            var records = reader.ReadUInt32();

            for (var i = 0; i < records; i++)
            {
                // use this if DDMMYYYY means int values
                //var day = reader.ReadInt16();
                //var month = reader.ReadInt16();
                //var year = reader.ReadInt32();

                // use this if DDMMYYYY means char values
                var day         = reader.ReadChars(2);
                var month       = reader.ReadChars(2);
                var year        = reader.ReadChars(4);
                var brandLength = reader.ReadUInt16();
                var brand       = reader.ReadChars(brandLength);
                var price       = reader.ReadUInt32();
                var yearValue   = int.Parse(new string(year));
                var monthValue  = int.Parse(new string(month));
                var dayValue    = int.Parse(new string(day));
                var dateStr     = new DateTime(yearValue, monthValue, dayValue).ToString(CarRecord.DateFormat);
                var car         = new CarRecord
                {
                    Date      = dateStr,
                    BrandName = new string(brand),
                    Price     = price
                };
                cars.CarRecords.Add(car);
            }
        }
Пример #12
0
 /// <summary>
 /// Adds a new car record to the list of car records.
 /// </summary>
 /// <param name="carRecord"></param>
 public void AddCarRecord(CarRecord carRecord)
 {
     CarRecords.Add(carRecord);
 }
Пример #13
0
        public void RonOwed_FirstHour()
        {
            var carRecord = new CarRecord("B10ABC");

            Assert.Equal(carRecord.RonOwed, CarRecord.RonOwedPerFirstHour);
        }
Пример #14
0
        private void buttonAddRentalRecord_Click(object sender, EventArgs e)
        {
            try
            {
                // get values from form controls
                string custName     = textBoxCustName.Text.Trim();
                string carType      = dropdownCarRented.Text;
                var    dateRented   = dateTimePickerDateRented.Value;
                var    dateToReturn = dateTimePickerDateToReturn.Value;
                Decimal.TryParse(textBoxCarCost.Text.Trim(), out decimal carRentalCost);

                // declare local variables
                string errorMessage = string.Empty;

                // form control validation
                if (string.IsNullOrWhiteSpace(custName))
                {
                    errorMessage += "Error: Please enter input value for Customer Name \n\r";
                }

                if (carRentalCost == 0)
                {
                    errorMessage += "Error: Please enter input value for Car Rental Cost \n\r";
                }

                if ((dateRented == null || dateToReturn == null) || dateRented.Date > dateToReturn.Date)
                {
                    errorMessage += "Error: Please enter valid date(s) \n\r";
                }

                if (string.IsNullOrWhiteSpace(carType))
                {
                    errorMessage += "Error: Please enter input value for Car Type \n\r";
                }

                // display error message or save valid input
                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    CarRentalRecord newCarRentalRecord = new CarRentalRecord
                    {
                        CustomerName = custName,
                        Cost         = carRentalCost,
                        DateRented   = dateRented,
                        DateToReturn = dateToReturn,
                        CarID        = (int)dropdownCarRented.SelectedValue,
                    };

                    _db.CarRentalRecords.Add(newCarRentalRecord);

                    CarRecord carRented = _db.CarRecords.Where(c => c.ID == (int)dropdownCarRented.SelectedValue).First();
                    carRented.OnLoan = true;

                    _db.SaveChanges();

                    MessageBox.Show($"Customer Name: {custName} \n\r" + $"Date Rented: {dateRented.Date} \n\r" +
                                    $"Date To Return: {dateToReturn.Date} \n\r" + $"Cost: {carRentalCost} \n\r" + $"Car: {carType} \n\r");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }