/// <summary> /// Method that logs a user into the system /// </summary> /// <param name="username">A username string that is passed to this method</param> /// <param name="password">A password string that is passed to this method</param> public static async void Login(string username, string password) { foreach (Account account in _accountList.AccountList) { if (username == account.UserName && password == account.PassWord) { _account = new Account(account.UserName, account.PassWord, account.DisplayName); SetDisplayNameForUI = _account.DisplayName; AccountDetail = new AccountDetails(); _accountDetails = await AccountDetail.LoadUserDetailsFile(username); SetProfileImagePathForUI = _accountDetails.ProfilePicturePath; MainPageVm?.CallForAccountStatus(); StoreVm?.OnAccountChanged(); GameTemplateVm?.OnAccountChanged(); if (AccountDetail.AccountShoppingCart != null) { if (AccountDetail.AccountShoppingCart.Count > 0) { ShoppingCart.Instance.AddGame(AccountDetail?.AccountShoppingCart); } } else { AccountDetail.AccountShoppingCart = new ObservableCollection <Game>(); } MainPageVm?.RefreshPurchaseSelectedGame(); break; } } }
/// <summary> /// Creates an account in the system and writes the account to the files /// </summary> /// <param name="account">An account object that is passed</param> /// <param name="pfpPath">A string that is passed that links an image to the account</param> public static void CreateAccount(Account account, string pfpPath) { _accountList.AccountList.Add(account); SetDisplayNameForUI = _account.DisplayName; AccountDetail = new AccountDetails(); _accountDetails.DisplayName = account.DisplayName; _accountDetails.UserName = account.UserName; _accountDetails.ProfilePicturePath = pfpPath; SetProfileImagePathForUI = _accountDetails.ProfilePicturePath; _joinDateBeforeFormat = DateTime.Now; _accountDetails.JoinDate = _joinDateBeforeFormat.Date.ToShortDateString(); _accountDetails.CreateUserDetailsFile(_accountDetails, account.UserName); MainPageVm?.CallForAccountStatus(); StoreVm?.OnAccountChanged(); GameTemplateVm?.OnAccountChanged(); }
/// <summary> /// Logs a user off the system and sets objects to null /// </summary> public static void LogOff() { _accountDetails.CreateUserDetailsFile(_accountDetails, _account.UserName); //Bellow needs implementing without errors /*foreach (Game game in AccountDetail.AccountShoppingCart.Games) * { * ShoppingCart.Instance.RemoveGame(game); * }*/ _account = null; _displaynameForUI = null; _accountDetails = null; SetProfileImagePathForUI = null; MainPageVm?.CallForAccountStatus(); StoreVm?.OnAccountChanged(); GameTemplateVm?.OnAccountChanged(); ShoppingCart.Instance.ClearShoppingCart(); MainPageVm?.RefreshPurchaseSelectedGame(); }