public InspectionFileViewModel()
        {
            using(DatabaseContext databaseContext = new DatabaseContext())
            {

                IEnumerable<InspectionFileVM> inspectionFiles = databaseContext.InspectionFiles.ToList().Select(inspectionFile => new InspectionFileVM(inspectionFile));
                InspectionFiles = new ObservableCollection<InspectionFileVM>(inspectionFiles);

                IEnumerable<AccountVM> inspectors = databaseContext.Accounts.ToList().Select(inspector => new AccountVM(inspector));
                Inspectors = new ObservableCollection<AccountVM>(inspectors);

                IEnumerable<RepresenterVM> representers = databaseContext.Representers.ToList().Select(representer => new RepresenterVM(representer));
                Representers = new ObservableCollection<RepresenterVM>(representers);

                IEnumerable<TaskVM> tasks = databaseContext.Tasks.ToList().Select(task => new TaskVM(task));
                Tasks = new ObservableCollection<TaskVM>(tasks);

                IEnumerable<string> questionLists = databaseContext.QuestionLists.ToList().Select(questionList => questionList.Id.ToString());
                QuestionLists = new ObservableCollection<string>(questionLists);

                IEnumerable<InspectionTypeVM> inspectionTypes = databaseContext.InspectionTypes.ToList().Select(inspectionType => new InspectionTypeVM(inspectionType));
                InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes);

                // Select the first inspection file from the observable collection. Nothing found, a new instance will be created
                SelectedInspectionFile = InspectionFiles.FirstOrDefault() != null ? InspectionFiles.FirstOrDefault() : new InspectionFileVM();

                IEnumerable<TaskVM> inspectionFileTasks = SelectedInspectionFile.Tasks.Select(task => new TaskVM(task));
                InspectionFileTasks = new ObservableCollection<TaskVM>(inspectionFileTasks);

                IEnumerable<QuestionListVM> inspectionFileQuestionLists = SelectedInspectionFile.QuestionLists.Select(questionList => new QuestionListVM(questionList));
                InspectionFileQuestionLists = new ObservableCollection<QuestionListVM>(inspectionFileQuestionLists);

            }
        }
        public LoginWindowViewModel()
        {
            _databaseContext = new DatabaseContext();
            IEnumerable<AccountVM> accounts = _databaseContext.Accounts.ToList().Select(account => new AccountVM(account));
            Accounts = new ObservableCollection<AccountVM>(accounts);

            DoLogIn = new RelayCommand(LogIn, CanLogIn);
        }
 public CreateCustomerViewModel()
 {
     using (DatabaseContext databaseContext = new DatabaseContext())
     {
         IEnumerable<RegionVM> regions = databaseContext.Regions.ToList().Select(Regio => new RegionVM(Regio));
         Regions = new ObservableCollection<RegionVM>(regions);
     }
 }
        public QuestionListTemplateAddWindowViewModel()
        {
            _databaseContext = new DatabaseContext();

            IEnumerable<InspectionTypeVM> inspectionTypes = _databaseContext.InspectionTypes.ToList().Select(inspectiontype => new InspectionTypeVM(inspectiontype));
            InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes);

            DoAddTemplateToDB = new RelayCommand(AddTemplateToDB, CanAddTemplateToDb);
        }
        public QuestionListViewModel()
        {
            _databaseContext = new DatabaseContext();

            IEnumerable<QuestionListVM> questionlists = _databaseContext.QuestionLists.ToList().Select(questionList => new QuestionListVM(questionList));
            QuestionLists = new ObservableCollection<QuestionListVM>(questionlists);

            IEnumerable<QuestionVM> questions = _databaseContext.Questions.ToList().Select(question => new QuestionVM(question));
            Questions = new ObservableCollection<QuestionVM>(questions);
        }
        public QuestionListAddViewModel()
        {
            _databaseContext = new DatabaseContext();

            IEnumerable<QuestionTypeVM> questionTypes = _databaseContext.QuestionTypes.ToList().Select(questionType => new QuestionTypeVM(questionType));
            IEnumerable<QuestionVM> questions = _databaseContext.Questions.ToList().Select(question => new QuestionVM(question));
            QuestionTypes = new ObservableCollection<QuestionTypeVM>(questionTypes);
            Questions = new ObservableCollection<QuestionVM>(questions);

            DoaddQuestion = new RelayCommand(addQuestion);
        }
        public InspectedOrganisationViewModel()
        {
            _myContext = new DatabaseContext();

            IEnumerable<InspectedOrganisationVM> organisations = _myContext.InspectedOrganisations.ToList().Select(InspectedOrganisation => new InspectedOrganisationVM(InspectedOrganisation));
            InspectedOrganisations = new ObservableCollection<InspectedOrganisationVM>(organisations);
            SelectedOrganisations = new List<InspectedOrganisationVM>();

            Addresses = new ObservableCollection<AddressVM>();

            RemoveInspectedOrganisations = new RelayCommand(RemoveSelectedOrganisation, CanRemoveSelectedOrganisation);
            RemoveAddresses = new RelayCommand(RemoveSelectedAddress, CanRemoveSelectedAddress);
        }
        public MainViewModel()
        {
            _myContext = new DatabaseContext();

            IEnumerable<InspectedOrganisationVM> inspectedOrganisations = _myContext.InspectedOrganisations.ToList().Select(inspectedOrganisation => new InspectedOrganisationVM(inspectedOrganisation));
            InspectedOrganisations = new ObservableCollection<InspectedOrganisationVM>(inspectedOrganisations);

            IEnumerable<InspectionTypeVM> inspectionTypes = _myContext.InspectionTypes.ToList().Select(inspectionType => new InspectionTypeVM(inspectionType));
            InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes);

            IEnumerable<RegionVM> regions = _myContext.Regions.ToList().Select(region => new RegionVM(region));
            Regions = new ObservableCollection<RegionVM>(regions);
        }
        public UserAccountOverViewWindowViewModel()
        {
            _myContext = new DatabaseContext();
            IEnumerable<AccountVM> accounts = _myContext.Accounts.ToList().Select(account => new AccountVM(account));
            Accounts = new ObservableCollection<AccountVM>(accounts);

            FirstDetails = new ObservableCollection<AccountVM>();

            EditAccount = new RelayCommand(EditSelectedAccount, CanEdit);
            RemoveAccount = new RelayCommand(RemoveSelectedAccount, CanRemove);
            AddUser = new RelayCommand(AddNewUser);
            RemoveAccountByDetails = new RelayCommand(RemoveSelectedAccountByDetails, CanRemoveByDetails);
        }
        public CustomerLinkRepresenterViewModel()
        {
            using (DatabaseContext databaseContext = new DatabaseContext())
            {
                IEnumerable<RepresenterVM> allRepresenters = databaseContext.Representers
                    .ToList()
                    .Select((cr) => new RepresenterVM(cr));
                AllRepresenters = new ObservableCollection<RepresenterVM>(allRepresenters);

                // Just get the ones we need from the fetched list of all representers
                IEnumerable<RepresenterVM> customerRepresenters = AllRepresenters.Where((r) => r.Customers.Any((c) => c.Id.Equals(CustomerVM.Id)));
                CustomerRepresenters = new ObservableCollection<RepresenterVM>(customerRepresenters);
            }
        }
        private void AddTemplateToDB()
        {
            using (DatabaseContext databaseContext = new DatabaseContext())
            {
                QuestionListTemplateVM q = new QuestionListTemplateVM();
                q.toQuestionListTemplate().InspectionTypeId = SelectedInspectionType.Id;
                databaseContext.QuestionListTemplates.Add(q.toQuestionListTemplate());
                databaseContext.SaveChanges();

                MessageBox.Show("Template toegevoegd!", "Succes!", MessageBoxButton.OK, MessageBoxImage.Information);

                CloseWindow();
                return;

            }
        }
        public QuestionListTemplatesViewModel()
        {
            _databaseContext = new DatabaseContext();

            IEnumerable<QuestionListTemplate> questionListTemplates = _databaseContext.QuestionListTemplates.ToList();
            IEnumerable<QuestionListTemplateVM> questionListTemplatesVM = questionListTemplates.Select(questionListTemplate => new QuestionListTemplateVM(questionListTemplate));
            IEnumerable<InspectionTypeVM> inspectionTypes = _databaseContext.InspectionTypes.ToList().Select(inspectionType => new InspectionTypeVM(inspectionType));
            QuestionListTemplates = new ObservableCollection<QuestionListTemplateVM>(questionListTemplatesVM);
            InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes);

            DoAddTemplate = new RelayCommand(AddTemplate);

            foreach (QuestionListTemplate questionListTemplate in questionListTemplates)
            {
                _databaseContext.Entry(questionListTemplate).Reference(qLT => qLT.InspectionType).Load();
            }
        }
        public CustomerViewModel()
        {
            using (DatabaseContext databaseContext = new DatabaseContext())
            {
                IEnumerable<Customer> customers = databaseContext.Customers.ToList();
                IEnumerable<CustomerVM> customersVM = customers.Select(c => new CustomerVM(c));
                Customers = new ObservableCollection<CustomerVM>(customersVM);

                IEnumerable<RegionVM> regionsVM = databaseContext.Regions.ToList().Select(c => new RegionVM(c));
                Regions = new ObservableCollection<RegionVM>(regionsVM);

                foreach (Customer customer in customers)
                {
                    databaseContext.Entry(customer).Reference(c => c.Region).Load();
                }
            }
        }
        public StatisticsViewModel()
        {
            _myContext = new DatabaseContext();

            string[] months = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli","Augustus","September","Oktober","November","December" };
            Months = new ObservableCollection<string>(months);

            List<int> yearValues = new List<int>();
            for (int i = DateTime.UtcNow.Year; i > 1949; i--)
            {
                yearValues.Add(i);
            }

            Years = new ObservableCollection<int>(yearValues);

            IEnumerable<RegionVM> regions = _myContext.Regions.ToList().Select(region => new RegionVM(region));
            Regions = new ObservableCollection<RegionVM>(regions);

            IEnumerable<InspectionTypeVM> inspectionTypes = _myContext.InspectionTypes.ToList().Select(inspectionType => new InspectionTypeVM(inspectionType));
            InspectionTypes = new ObservableCollection<InspectionTypeVM>(inspectionTypes);
        }
 public void SaveInspectionFile()
 {
     using (DatabaseContext databaseContext = new DatabaseContext())
     {
         SelectedInspectionFile.Account = SelectedInspector.ToAccount;
         SelectedInspectionFile.InspectionType = SelectedInspectionType.ToInspectionType;
         SelectedInspectionFile.Representer = SelectedRepresenter.Representer;
         databaseContext.InspectionFiles.Add(SelectedInspectionFile.ToInspectionFile);
         databaseContext.SaveChanges();
     }
 }
 public void Add()
 {
     using (DatabaseContext databaseContext = new DatabaseContext())
     {
         databaseContext.InspectionFiles.Add(SelectedInspectionFile.ToInspectionFile);
         databaseContext.SaveChanges();
         InspectionFiles.Add(SelectedInspectionFile);
     }
 }
 private void AddTemplate()
 {
     QuestionListTemplateVM qlt = new QuestionListTemplateVM();
     QuestionListTemplates.Add(qlt);
     using (DatabaseContext dbc = new DatabaseContext())
     {
         dbc.QuestionListTemplates.Add(qlt.toQuestionListTemplate());
         dbc.SaveChanges();
     }
 }