Ejemplo n.º 1
0
        private void EditCurrentUser()
        {
            if (this.Users.CurrentItem != null)
            {
                DbSet<PrfBmProfil> setProfils = this.DataContextPrf.Set<PrfBmProfil>();
                DbSet<PrfBmUserProfil> setUserProfils = this.DataContextPrf.Set<PrfBmUserProfil>();
                UserView view = new UserView();
                view.Title ="Modification d'un utilisateur";
                UserViewModel vm = this.Users.CurrentItem as UserViewModel;
                UserViewModel vmClone = new UserViewModel(vm.Model);
                view.DataContext = vmClone;
                view.Owner = Application.Current.GetActiveWindow();
                Nullable<Boolean> result = view.ShowDialog();
                if (result.HasValue && result.Value == true)
                {

                    vmClone.Write();
                    if (vmClone.FamDec != null && vmClone.CdDec != null)
                    {

                        vmClone.Model.FamDecInf = vmClone.FamDec.FamDec;
                        vmClone.Model.CdDecInf = vmClone.CdDec.CdDec;
                    }
                    else
                    {
                        vmClone.Model.FamDecInf = null;
                        vmClone.Model.CdDecInf = null;
                    }
                    vm.FamDec = vmClone.FamDec;
                    vm.CdDec = vmClone.CdDec;
                    this.DataContextPrf.SaveChanges();
                    foreach (UserProfilViewModel userProfilVm in vmClone.Profils)
                    {
                        PrfBmUserProfil prfBmUserProfil = (from p in setUserProfils where p.PrfBmUser.IdPk.Equals (vm.Model.IdPk) && p.PrfBmProfil.PrfBmSchema.IdPk.Equals (userProfilVm.Schema.IdPk) select p).FirstOrDefault();
                        switch (userProfilVm.PrivilegeLevel)
                        {
                            case Layers.Shared.Enums.PrivilegeLevel.Administrateur:
                                prfBmUserProfil.PrfBmProfil = (from p in setProfils where p.PrfBmSchema.IdPk.Equals (userProfilVm.Schema.IdPk) && p.Profil.Equals ("ADMIN_"+userProfilVm.Schema.Schema ) select p).FirstOrDefault();
                                break;
                            case Layers.Shared.Enums.PrivilegeLevel.Valideur:
                                prfBmUserProfil.PrfBmProfil = (from p in setProfils where p.PrfBmSchema.IdPk.Equals(userProfilVm.Schema.IdPk) && p.Profil.Equals("VALID_"+userProfilVm.Schema.Schema ) select p).FirstOrDefault();
                                break;
                            case Layers.Shared.Enums.PrivilegeLevel.Consultant:
                                 prfBmUserProfil.PrfBmProfil = (from p in setProfils where p.PrfBmSchema.IdPk.Equals (userProfilVm.Schema.IdPk) && p.Profil.Equals ("CONSULT_"+userProfilVm.Schema.Schema ) select p).FirstOrDefault();
                                break;
                        }
                    }
                    this.DataContextPrf.SaveChanges();
                    vm.Read();
                    vm.ReadProfils();
                    vm.RaiseChanges();
                }
            }
        }
Ejemplo n.º 2
0
        private void AddUser()
        {
            UserView view = new UserView();
            PrfBmUser user = new PrfBmUser();

            DbSet<PrfBmSchema> setSchema = this.DataContextPrf.Set<PrfBmSchema>();
            DbSet<PrfBmProfil> setProfils = this.DataContextPrf.Set<PrfBmProfil>();
            DbSet<PrfBmUserProfil> setUserProfils = this.DataContextPrf.Set<PrfBmUserProfil>();

            UserViewModel vm = new UserViewModel(user);

            view.DataContext = vm;
            view.Title = "Ajout d'un utilisateur";
            view.Owner = Application.Current.GetActiveWindow();
            Nullable<Boolean> result = view.ShowDialog();
            if (result.HasValue && result.Value == true)
            {
                vm.Write();
                if (vm.FamDec != null && vm.CdDec != null)
                {

                    vm.Model.FamDecInf = vm.FamDec.FamDec;
                    vm.Model.CdDecInf = vm.CdDec.CdDec;
                }
                else
                {
                    vm.Model.FamDecInf = null;
                    vm.Model.CdDecInf = null;
                }
                this.DataContextPrf.Set<PrfBmUser>().Add(vm.Model);
                this.DataContextPrf.SaveChanges();
                this._users.Add(vm);

                foreach (UserProfilViewModel profilVm in vm.Profils)
                {
                    PrfBmUserProfil userProfil = new PrfBmUserProfil();
                    userProfil.BmUserLogin = vm.Model.Login;
                    switch (profilVm.PrivilegeLevel)
                    {
                        case Layers.Shared.Enums.PrivilegeLevel.Administrateur :
                            userProfil.BmProfilProfil = "ADMIN_"+profilVm.Schema.Schema ;
                            break;
                        case Layers.Shared.Enums.PrivilegeLevel.Consultant:
                            userProfil.BmProfilProfil ="CONSULT_"+ profilVm.Schema.Schema ;
                            break;
                        case Layers.Shared.Enums.PrivilegeLevel.Valideur:
                            userProfil.BmProfilProfil = "VALID_"+profilVm.Schema.Schema;
                            break;
                    }
                    userProfil.PrfBmUserIdPk = vm.Model.IdPk;
                    userProfil.PrfBmProfilIdPk = (from p in setProfils where p.Profil.Equals (userProfil.BmProfilProfil) select p.IdPk).FirstOrDefault();
                    setUserProfils.Add(userProfil);
                }
                 this.DataContextPrf.SaveChanges();
                 vm.RaiseChanges();
            }
        }