Пример #1
0
        internal static void DeleteUser(UserViewModel user)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var userToDelete =
                from utd in entity.Users
                where utd.Username.Contains(user.Username)
                select utd;

            if (userToDelete.Count() != 0)
            {
                foreach (var item in userToDelete)
                {
                    entity.Users.Remove(item);
                }

                entity.SaveChanges();

                MessageBox.Show("User " + user.Username + " deleted", "Confirmation", MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show("User " + user.Username + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
        }
Пример #2
0
        internal static void AddUser(UserViewModel user)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var userToAdd =
                from uta in entity.Users
                where uta.Username==user.Username
                select uta;

            if (userToAdd.Count()!=0)
            {
                MessageBox.Show("User " + user.Username + " exists", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                entity.Users.Add(new User()
                                     {
                                         Username = user.Username,
                                         Password = Convert.ToBase64String(System.Security.Cryptography.MD5.Create().
                                                    ComputeHash(Encoding.UTF8.GetBytes(user.Password))),
                                         Rank = user.Rank
                                     });

                    entity.SaveChanges();
                    MessageBox.Show("User " + user.Username + " added", "Confirmation", MessageBoxButton.OK);
            }
        }
Пример #3
0
 public WarehouseViewModel()
 {
     this.newProductViewModel = new ProductViewModel();
     this.newVendorViewModel = new VendorViewModel();
     this.newUserViewModel = new UserViewModel();
 }