Пример #1
0
        /// <summary>
        ///  Function takes the license plat that is a unique identifier of the car
        ///  the personal identity number of a person
        ///  the day they rent the car
        ///  and the current meter on the car when the customer receives the car
        /// </summary>
        /// <param name="licensePlate"></param>
        /// <param name="personalIdentityNumber">Personal identity number</param>
        /// <param name="startOfRent"></param>
        /// <param name="currentMeter"></param>
        /// <returns>Booking number</returns>
        public async Task <int> RentAsync(string licensePlate, string personalIdentityNumber, DateTime startOfRent, int currentMeter)
        {
            var rx = new Regex(@"\b(((20)((0[0-9])|(1[0-1])))|(([1][^0-8])?\d{2}))((0[1-9])|1[0-2])((0[1-9])|(2[0-9])|(3[01]))[-+]?\d{4}[,.]?\b");

            if (!rx.IsMatch(personalIdentityNumber))
            {
                throw new ArgumentException($"RentService::RentACarAsync Invalid SSN : {personalIdentityNumber}");
            }

            Rent rent = new Rent {
                LicensePlate           = licensePlate,
                PersonalIdentityNumber = personalIdentityNumber,
                StartOfRent            = startOfRent,
                StartOfCurrentMeter    = currentMeter
            };

            return(await _rentRepository.AddAsync(rent));
        }