public static void CreateAccount(bool agree, string username, string password, string name, string surname, string address) { if (!agree) { NotificationWindowContoller.NewNotification("Error!", "You can't create new account", ComputerPeripheralsShop.Models.Notification.NotificationType.Success); return; } using (UnitOfWork context = new UnitOfWork()) { foreach (User curUser in context.UserRepository.AppContext.User) { if (username.Equals(curUser.Login)) { NotificationWindowContoller.NewNotification("Error!", "This username already exists", ComputerPeripheralsShop.Models.Notification.NotificationType.Danger); return; } } User user = new User(username, HashConverters.GetHashEncryption(password), name, surname, address); context.UserRepository.AppContext.User.Add(user); context.SaveChanges(); curUser = user; IsLoggedIn = true; CloseCreateAccountWindow(); } }
public static void LogOut() { if (curUser != null) { curUser = null; IsLoggedIn = false; NotificationWindowContoller.NewNotification("Success!", "You successfully logged out", ComputerPeripheralsShop.Models.Notification.NotificationType.Success); MainFrameNavigator.FrameGoBack(); return; } else { NotificationWindowContoller.NewNotification("Error!", "You are not logged in", ComputerPeripheralsShop.Models.Notification.NotificationType.Danger); } }
public static void Login(string username, string password) { using (UnitOfWork context = new UnitOfWork()) { var registeredUser = context.UserRepository.GetUserByUsername(username); if (registeredUser != null) { if (HashConverters.GetHashString(HashConverters.GetHashEncryption(password)).Equals(HashConverters.GetHashString(registeredUser.Password_hash))) { curUser = registeredUser; IsLoggedIn = true; CloseLoginWindow(); return; } } NotificationWindowContoller.NewNotification("Error!", "The username or password is incorrect", ComputerPeripheralsShop.Models.Notification.NotificationType.Danger); } }
private void ExecuteAddProduct() { using (UnitOfWork context = new UnitOfWork()) { try { _product.Weight += "g"; _product.Height += "mm"; _product.Width += "mm"; _product.Picture_Main = BitmapConverters.ConvertBitmapSourceToByteArray(_picture_Main_Path); _product.Picture1 = BitmapConverters.ConvertBitmapSourceToByteArray(_picture1_Path); _product.Picture2 = BitmapConverters.ConvertBitmapSourceToByteArray(_picture2_Path); _product.MenuPicture = BitmapConverters.ConvertBitmapSourceToByteArray(_menuPicture_Path); context.ProductRepository.AddProduct(_product); context.SaveChanges(); NotificationWindowContoller.NewNotification("Success!", "Product added successfully!", Notification.NotificationType.Success); } catch { NotificationWindowContoller.NewNotification("Error!", "Fail to add product!", Notification.NotificationType.Danger); } } }