Exemple #1
0
        public EditChildrenViewModel()
        {
            LoadClasses();
            LoadConditions();
            SaveCommand = new RelayCommand <object>((p) => { return(true); },
                                                    async(p) =>
            {
                var mySettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText    = "Ok",
                    NegativeButtonText       = "Go away!",
                    FirstAuxiliaryButtonText = "Cancel",
                    ColorScheme = Window.MetroDialogOptions.ColorScheme
                };
                Child.name         = this._childrenName;
                Child.sex          = this._sex;
                Child.birthdate    = this._birthDate;
                Child.nickname     = this._nickName;
                Child.id_class     = DataProvider.Ins.DB.classes.Where(x => x.name == selectedClass).ToArray()[0].id;
                Child.id_condition = DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).ToArray()[0].id;
                DataProvider.Ins.DB.SaveChanges();
                ManageChildrenViewModel.Ins.LoadData();
                EnrollViewModel.LoadClasses();
                await Window.ShowMessageAsync("Hello!", "Saved changes successfully.", MessageDialogStyle.Affirmative, mySettings);
                Window.Close();
            });

            foreach (Window window in Application.Current.Windows)
            {
                if (window.Name == "EditChildrenWindow")
                {
                    this.Window = window as EditChildren;
                    break;
                }
            }
            Child = DataProvider.Ins.DB.children.Where(x => x.id == Window.id).Join(
                DataProvider.Ins.DB.parents,
                d => d.id_parent,
                f => f.id,
                (d, f) => d
                ).ToArray()[0];
            this.selectedClass = DataProvider.Ins.DB.classes.Where(x => x.id == Child.id_class).ToArray()[0].name;
            this._childrenName = Child.name;
            this._nickName     = Child.nickname;
            this._birthDate    = Child.birthdate;
            this._sex          = Child.sex;
            this._motherName   = Child.parent.Mothername;
            this._fatherName   = Child.parent.FatherName;
            if (DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).Count() > 0)
            {
                this.selectedCondition = DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).ToArray()[0].name;
            }
        }
        public EditChildrenViewModel()
        {
            LoadClasses();
            LoadConditions();
            UploadImageCommand = new RelayCommand <object>((p) => true, (p) =>
            {
                var dlg              = new OpenFileDialog();
                dlg.Title            = "Choose profile picture";
                dlg.InitialDirectory = "";
                dlg.Filter           = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                       "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                       "Portable Network Graphic (*.png)|*.png";
                dlg.Multiselect = false;
                if (dlg.ShowDialog() == true)
                {
                    this.ImageURL = dlg.FileName;
                }
            });
            SaveCommand = new RelayCommand <object>((p) => { return(true); },
                                                    async(p) =>
            {
                var mySettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText    = "Ok",
                    NegativeButtonText       = "Go away!",
                    FirstAuxiliaryButtonText = "Cancel",
                    ColorScheme = Window.MetroDialogOptions.ColorScheme
                };
                Child.name      = this._childrenName;
                Child.sex       = this._sex;
                Child.birthdate = this._birthDate;
                Child.nickname  = this._nickName;
                Child.imageUrl  = this.ImageURL;
                Child.id_class  = DataProvider.Ins.DB.classes.Where(x => x.name == selectedClass).ToArray()[0].id;
                if (DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).FirstOrDefault() != null)
                {
                    Child.id_condition = DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).FirstOrDefault().id;
                }
                DataProvider.Ins.DB.SaveChanges();
                ManageChildrenViewModel.Ins.LoadData();
                EnrollViewModel.LoadClasses();
                await Window.ShowMessageAsync("Hello!", "Save changes success.", MessageDialogStyle.Affirmative, mySettings);
                Window.Close();
            });

            foreach (Window window in Application.Current.Windows)
            {
                if (window.Name == "EditChildrenWindow")
                {
                    this.Window = window as EditChildren;
                    break;
                }
            }
            Child = DataProvider.Ins.DB.children.Where(x => x.id == Window.id).Join(
                DataProvider.Ins.DB.parents,
                d => d.id_parent,
                f => f.id,
                (d, f) => d
                ).ToArray()[0];
            this.selectedClass = DataProvider.Ins.DB.classes.Where(x => x.id == Child.id_class).ToArray()[0].name;
            this._childrenName = Child.name;
            this._nickName     = Child.nickname;
            this._birthDate    = Child.birthdate;
            this._sex          = Child.sex;
            this.ImageURL      = Child.imageUrl;
            this._motherName   = Child.parent.Mothername;
            this._fatherName   = Child.parent.FatherName;
            if (DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).Count() > 0)
            {
                this.selectedCondition = DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).ToArray()[0].name;
            }
        }