private static void SyncWorkshopSettings() { var generalSettingsRepository = ContainerBootstrapper.Resolve <ISettingsRepository <WorkshopSettings> >(); var workshopSettings = generalSettingsRepository.GetWorkshopSettings(); if (workshopSettings.Uploaded != null) { return; } using (var context = new TachographContext()) { context.Configuration.ProxyCreationEnabled = false; var settings = context.WorkshopSettings.AsNoTracking() .Where(w => !string.IsNullOrEmpty(w.Address1) || !string.IsNullOrEmpty(w.Address2) || !string.IsNullOrEmpty(w.Address3) || !string.IsNullOrEmpty(w.Office) || !string.IsNullOrEmpty(w.PostCode) || !string.IsNullOrEmpty(w.Town) || !string.IsNullOrEmpty(w.WorkshopName)) .First(c => c.Id == workshopSettings.Id); _connectClient.Service.UploadWorkshopSettings(settings); } if (workshopSettings.Created == default(DateTime) || workshopSettings.Created == DateTime.Parse("01/01/1900")) { workshopSettings.Created = DateTime.Now; } workshopSettings.Uploaded = DateTime.Now; generalSettingsRepository.Save(workshopSettings); }
public virtual T First(Expression <Func <T, bool> > predicate) { return(Safely(() => { using (var context = new TachographContext()) { return context.Set <T>().First(predicate.Compile()); } })); }
public T First() { return(Safely(() => { using (var context = new TachographContext()) { return context.Set <T>().First(); } })); }
public bool Any() { return(Safely(() => { using (var context = new TachographContext()) { return context.Set <T>().Any(); } })); }
public virtual void Save(T settings) { Safely(() => { using (var context = new TachographContext()) { if (settings == null) { context.Set <T>().Add(new T()); } else { context.Set <T>().Attach(settings); context.Entry(settings).State = EntityState.Modified; } context.SaveChanges(); } }); }
public T Get(Func <T, bool> filter, params string[] includes) { List <T> settings = Safely(() => { using (var context = new TachographContext()) { return(context.Set <T>().WithIncludes(context, includes).ToList()); } }); if (settings.Count == 1) { return(settings.First()); } if (filter != null) { return(settings.FirstOrDefault(filter)); } return(settings.FirstOrDefault()); }
protected override void Load() { using (var context = new TachographContext()) { var documents = context.GetAllDocuments().Select(c => new DocumentHistoryItem(c)); Documents = new ObservableCollection <IDocumentHistoryItem>( documents.Concat(context.GetQCReports().Select(c => new DocumentHistoryItem(c))) .Concat(context.GetReports <GV212Report>().Select(c => new DocumentHistoryItem(c))) .OrderByDescending(c => c.Created)); _originalDocumentHistoryItems = new ObservableCollection <IDocumentHistoryItem>(Documents); } DocumentTypes = new List <string> { Resources.TXT_SELECT_ALL, typeof(TachographDocument).Name.SplitByCapitals(), typeof(UndownloadabilityDocument).Name.SplitByCapitals(), typeof(LetterForDecommissioningDocument).Name.SplitByCapitals(), typeof(QCReport).Name.SplitByCapitals(), "QC 3 Month Walkaround", "GV 212", Resources.TXT_ANALOGUE_ONLY }; SearchFilters = new List <string> { Resources.TXT_REGISTRATION_NUMBER, Resources.TXT_CUSTOMER, Resources.TXT_TECHNICIAN, Resources.TXT_OFFICE, Resources.TXT_DOCUMENT_TYPE }; SelectedSearchFilter = SearchFilters.First(); SelectedDocumentType = Resources.TXT_SELECT_ALL; }