public static List <ServiceSheetViewModel> loadHolidayAbsenceSheets()
        {
            List <ServiceSheetViewModel> retval = new List <ServiceSheetViewModel>();

            UserViewModel dbUser = getDbUser();

            if (dbUser == null)
            {
                return(null);
            }
            //Downloads the service sheets from the database and creates the vms
            try
            {
                using (var dbContext = new ServiceSheetsEntities())
                {
                    updateContextConnection(dbUser, dbContext);
                    var serviceSheets = from ServiceSheet in dbContext.ServiceSheets
                                        where ServiceSheet.SubmissionNumber < 0
                                        select ServiceSheet;
                    retval = ServiceSheetViewModel.loadFromModel(serviceSheets);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
            return(retval);
        }
        public static bool?checkForClashingDates(DateTime startDate, DateTime endDate, string username)
        {
            //Returns true if a service day exists for between the given dates.
            List <ServiceSheetViewModel> retval = new List <ServiceSheetViewModel>();

            UserViewModel dbUser = getDbUser();

            if (dbUser == null)
            {
                return(null);
            }


            try
            {
                using (var dbContext = new ServiceSheetsEntities())
                {
                    updateContextConnection(dbUser, dbContext);
                    var serviceSheets =
                        from ss in dbContext.ServiceSheets
                        join sd in dbContext.ServiceDays on ss.Id equals sd.ServiceSheetId
                        where ss.Username == username && sd.DtReport >= startDate && sd.DtReport <= endDate
                        select ss;

                    retval = ServiceSheetViewModel.loadFromModel(serviceSheets);
                }
            }
            catch (EntityException entityEx)
            {
                //Something went wrong with the load.  Clear the cache for the username.
                clearCacheDbUsername();
                Console.WriteLine(entityEx.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }

            if (retval.Count == 0)
            {
                return(false);
            }
            return(true);
        }
        public static List <ServiceSheetViewModel> downloadServiceSheets(DateTime monthFirstDay, DateTime monthEndDay)
        {
            List <ServiceSheetViewModel> retval = new List <ServiceSheetViewModel>();

            UserViewModel dbUser = getDbUser();

            if (dbUser == null)
            {
                return(null);
            }
            //Downloads the service sheets from the database and creates the vms
            try
            {
                using (var dbContext = new ServiceSheetsEntities())
                {
                    updateContextConnection(dbUser, dbContext);
                    var serviceSheets = from ServiceSheet in dbContext.ServiceSheets
                                        //join sDay in dbContext.ServiceDays
                                        //on ServiceSheet.Id equals sDay.ServiceSheetId
                                        where ServiceSheet.ServiceDays.Any(sDays => sDays.DtReport >= monthFirstDay && sDays.DtReport <= monthEndDay)
                                        select ServiceSheet;
                    retval = ServiceSheetViewModel.loadFromModel(serviceSheets);
                }
            }
            catch (EntityException entityEx)
            {
                //Something went wrong with the load.  Clear the cache for the username.
                clearCacheDbUsername();
                Console.WriteLine(entityEx.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
            return(retval);
        }
        public static List <ServiceSheetViewModel> downloadAllServiceSheets()
        {
            List <ServiceSheetViewModel> retval = new List <ServiceSheetViewModel>();

            UserViewModel dbUser = getDbUser();

            if (dbUser == null)
            {
                return(null);
            }
            //Downloads the service sheets from the database and creates the vms
            try
            {
                using (var dbContext = new ServiceSheetsEntities())
                {
                    updateContextConnection(dbUser, dbContext);
                    var serviceSheets = from ServiceSheet in dbContext.ServiceSheets
                                        where ServiceSheet.SubmissionNumber > 15679
                                        select ServiceSheet;
                    retval = ServiceSheetViewModel.loadFromModel(serviceSheets);
                }
            }
            catch (EntityException entityEx)
            {
                //Something went wrong with the load.  Clear the cache for the username.
                clearCacheDbUsername();
                Console.WriteLine(entityEx.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
            return(retval);
        }