Ejemplo n.º 1
0
        // CAR VALIDATIONS
        public string CarPlateValidation(string carPlate)
        {
            DatabaseRequests request = new DatabaseRequests();
            string           errorMessage;

            if (string.IsNullOrWhiteSpace(carPlate))
            {
                errorMessage = "This field is required";
            }
            else if (!Regex.IsMatch(carPlate, @"[A-Za-z]{2}\s[0-9]{2}\s[A-Za-z]{3}"))
            {
                errorMessage = "Please use the correct format. E.g. AB 12 ABC";
            }
            else
            {
                errorMessage = request.GetCarIDByPlate(carPlate) == 0 ? "This Car Plate doesn't exist in the database" : "";
            }
            return(errorMessage);
        }
Ejemplo n.º 2
0
        // NEW CAR RENT VALIDATIONS
        public Tuple <List <string>, bool> ValidateCarRent(string plate, string clientID, string startDate, string endDate, string city)
        {
            Reservation      reservation = new Reservation();
            Car              car         = new Car();
            Customer         customer    = new Customer();
            DatabaseRequests request     = new DatabaseRequests();
            List <string>    errors      = new List <string>();

            string plateError     = "";
            string IDError        = "";
            string startDateError = "";
            string endDateError   = "";
            string cityError      = "";
            string overlapDates   = "";

            // Plate check
            plateError = CarPlateValidation(plate);

            // ClientID check
            IDError = ClientIDValidation(clientID);

            // Start-End Date check
            startDateError = DateValidation(startDate);

            if (startDateError == "")
            {
                startDateError = CompareDateValidation(DateTime.Today, DateTime.Parse(startDate));

                if (startDateError == "")
                {
                    endDateError = DateValidation(endDate);

                    if (endDateError == "")
                    {
                        endDateError = CompareDateValidation(DateTime.Parse(startDate), DateTime.Parse(endDate));

                        if (endDateError != "")
                        {
                            endDateError += " the start date";
                        }
                    }
                }
                else
                {
                    startDateError += " today";
                }
            }
            // Date Overlap check

            if (startDateError == "" && endDateError == "" && plateError == "")
            {
                plateError = request.CheckDateOverlap(DateTime.Parse(startDate), DateTime.Parse(endDate), request.GetCarIDByPlate(plate));
            }

            // City check
            cityError = LocationValidation(city);

            // Return true if all the data is correct/no error message
            if (plateError == "" && IDError == "" && startDateError == "" && endDateError == "" && cityError == "" && overlapDates == "")
            {
                return(Tuple.Create(errors, true));
            }

            errors.Add(plateError);
            errors.Add(IDError);
            errors.Add(startDateError);
            errors.Add(endDateError);
            errors.Add(cityError);

            return(Tuple.Create(errors, false));
        }