Exemplo n.º 1
0
        public App()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
            UnitOfWork = new UnitOfWork();
            var kernel = new StandardKernel();

            kernel.Load(Assembly.GetExecutingAssembly());
            using (LibraryDBContext db = new LibraryDBContext())
            {
                if (db.Users.AsQueryable().FirstOrDefault(x => x.Username == "Islam") == null)
                {
                    db.Users.Add(new User("Islam", De_En_Crypter.Encrypt("123", "Encrypt"), true));
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public override void Execute(object parameter)
        {
            if (Convert.ToInt32(parameter) == UserVM.StateUser)
            {
                try
                {
                    if (UserVM.CurrentUser.Id == 0)
                    {
                        if (App.UnitOfWork.Users.GetAll().AsQueryable().FirstOrDefault(x => x.Username == UserVM.CurrentUser.Username) != null)
                        {
                            (new CustomMessageBox()).Show("This Username Already Taken!");
                            return;
                        }
                        UserVM.CurrentUser.Password = De_En_Crypter.Encrypt(UserVM.PasswordBox.ToString(), "Encrypt");
                        App.UnitOfWork.Users.Add(UserVM.CurrentUser);
                        (new CustomMessageBox()).Show("User Added!");
                    }
                    else if (UserVM.CurrentUser.Id > 0)
                    {
                        App.UnitOfWork.Users.Add(UserVM.CurrentUser);
                        (new CustomMessageBox()).Show("User Updated!");
                    }
                    UserVM.CurrentUser = new User();
                }
                catch (Exception)
                {
                    (new CustomMessageBox()).Show("Error!");
                }
                UserVM.CurrentUser = new User();
                UserVM.Users       = new ObservableCollection <User>(App.UnitOfWork.Users.GetAll());
                UserVM.StateUser   = 0;
                return;
            }
            int value = Convert.ToInt32(parameter);

            UserVM.StateUser = value;
        }