Beispiel #1
0
 public async Task <bool> RenewalRequalificationAsync(Driver driver, Requalificaiton requalificaiton)
 {
     try
     {
         if (driver.ActiveRequalificaiton != null)
         {
             driver.ActiveRequalificaiton.IsActive = false;
             driver.ActiveRequalificaiton.Archived = DateTime.Now;
             _dataContext.Update(driver.ActiveRequalificaiton);
         }
         requalificaiton.IsActive = true;
         if (!await AddNewRequalificationAsync(driver, requalificaiton))
         {
             throw new Exception("Error adding new driver's requalification.");
         }
         driver.Requalificaitons = new List <Requalificaiton> {
             requalificaiton
         };
         _dataContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        /// <summary>
        /// Loads the DriverLicense, Requalification and MedicalExam list for the specified driver.
        /// </summary>
        /// <param name="driver">The driver to be updated.</param>
        private void SetDriverDependencies(Driver driver)
        {
            DriverLicense   license         = null;
            Requalificaiton requalification = null;
            var             driver_id       = new Parameter("driver_id", driver.Id);
            var             licenseId       = DatabaseConnector.ExecuteFunction <int>("GetActiveLicenseIdForDriver", driver_id);

            if (licenseId > 0)
            {
                license = new DriverLicense {
                    Id = licenseId
                };
                license = DatabaseConnector.SelectDBObject(license).GetDBObject <DriverLicense>();
            }
            var requalificationId = DatabaseConnector.ExecuteFunction <int>("GetActiveRequalificationIdForDriver", driver_id);

            if (requalificationId > 0)
            {
                requalification = new Requalificaiton {
                    Id = requalificationId
                };
                requalification = DatabaseConnector.SelectDBObject(requalification).GetDBObject <Requalificaiton>();
            }
            var medexams = DatabaseConnector.ExecuteStoredProcedure("GetActiveMedExamsForDriver", driver_id).GetList <MedicalExam>();

            driver.DriverLicense   = license;
            driver.Requalificaiton = requalification;
            driver.MedicalExams    = medexams;
        }
 public bool RemoveRequalification(Requalificaiton requalificaiton)
 {
     try
     {
         DatabaseConnector.DeleteDBObject(requalificaiton);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool AddNewRequalification(Driver driver, Requalificaiton requalification)
 {
     try
     {
         requalification.Driver = driver;
         DatabaseConnector.InsertDBObject(requalification);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #5
0
 public async Task <bool> RemoveRequalificationAsync(Requalificaiton requalificaiton)
 {
     try
     {
         _dataContext.Remove(requalificaiton);
         _dataContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #6
0
        public async Task <bool> AddNewRequalificationAsync(Driver driver, Requalificaiton requalification)
        {
            try
            {
                requalification.Driver = driver;
                await _dataContext.Requalificaitons.AddAsync(requalification);

                _dataContext.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public bool RenewalRequalification(Driver driver, Requalificaiton requalificaiton)
 {
     try
     {
         if (driver.Requalificaiton != null)
         {
             driver.Requalificaiton.IsActive = false;
             driver.Requalificaiton.Archived = DateTime.Now;
             DatabaseConnector.UpdateDBObject(driver.Requalificaiton);
         }
         requalificaiton.IsActive = true;
         if (!AddNewRequalification(driver, requalificaiton))
         {
             throw new Exception("Error adding new driver's requalification.");
         }
         driver.Requalificaiton = requalificaiton;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Determines if any of the expiration dates of Driver's License, Requalification or Medical Exams are in the specified period.
 /// </summary>
 /// <param name="periodForLicense">The specified period for driver's license.</param>
 /// <param name="periodForRequalification">The specified period for driver's requalification.</param>
 /// <param name="periodForMedicalExam">The specified period for a driver's medical examl.</param>
 /// <returns>True if expiration date is in the period.</returns>
 public bool GetIfAnyParameterExpireDateIsInPeriod(TimeSpan periodForLicense, TimeSpan periodForRequalification, TimeSpan periodForMedicalExam)
 {
     return(DriverLicense == null || Requalificaiton == null || MedicalExams == null
             ? false
             : DriverLicense.GetIfExpirationDateIsInPeriod(periodForLicense) || Requalificaiton.GetIfExpirationDateIsInPeriod(periodForRequalification) || MedicalExams.Count(me => me.GetIfExpirationDateIsInPeriod(periodForMedicalExam)) > 0);
 }