예제 #1
0
        public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            UserToDisplay defaultUser = null;

            try
            {
                // Get default user from db
                defaultUser = UserService.GetDefaultUser();
                if (defaultUser != null)
                {
                    User = defaultUser;
                    NavigationService.Navigate(typeof(Views.NowPlaying));
                }
                else
                {
                    NavigationService.Navigate(typeof(Views.AskForUserName));
                }
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex.Message);
                WindowWrapper.Current().Dispatcher.Dispatch(() =>
                {
                    var errorMessage      = "There was an error during fetching default user.";
                    var modal             = Window.Current.Content as ModalDialog;
                    var errorDialog       = new ErrorDialog(errorMessage);
                    modal.ModalContent    = errorDialog;
                    modal.IsModal         = true;
                    modal.ModalBackground = new SolidColorBrush(Colors.Transparent);
                });
            }
        }
예제 #2
0
 /// <summary>
 /// Adds user to Users table or logs in when user exist
 /// </summary>
 public void AddUserOrLogIn()
 {
     try
     {
         UserToDisplay tempUser = null;
         if (!UserService.UserExist(UserName)) // If new user
         {
             UserService.AddUser(new UserToAdd()
             {
                 username  = UserName,
                 isDefault = (bool)IsDefault
             });
             tempUser = UserService.GetUser(UserName);
             Logger.LogInfo(this, $"Added user {tempUser.username} (ID: {tempUser.id})");
             App.User = tempUser;
             Logger.LogInfo(this, $"Logged in as user {App.User.username} (ID: {App.User.id})");
         }
         else // If user exists
         {
             tempUser = UserService.GetUser(UserName);
             if (tempUser.isDefault != IsDefault)
             {
                 tempUser.isDefault = (bool)IsDefault;
                 UserService.ModifyUser(tempUser);
                 Logger.LogInfo(this, $"Modified user {tempUser.username} (ID: {tempUser.id})");
             }
             App.User = tempUser;
             Logger.LogInfo(this, $"Logged in as user {App.User.username} (ID: {App.User.id})");
         }
         NavigationService.Navigate(typeof(Views.NowPlaying));
     }
     catch (Exception ex)
     {
         Logger.LogError(this, ex.Message);
         ShowErrorMessage("There was an error during loggin in / adding user.");
     }
 }
예제 #3
0
 /// <summary>
 /// Modifies user in database
 /// </summary>
 /// <param name="user"></param>
 public static void ModifyUser(UserToDisplay user)
 {
     if (user != null)
     {
         using (var db = new TraxxPlayerContext())
         {
             if (UserExist(user.id))
             {
                 var userToModify = db.Users.First(u => u.id == user.id);
                 userToModify.username  = user.username;
                 userToModify.isDefault = user.isDefault;
                 db.SaveChanges();
             }
             else
             {
                 throw new Exception("User with provided id doesn't exist. Add failed");
             }
         }
     }
     else
     {
         throw new Exception("User cannot be null. Add failed");
     }
 }
예제 #4
0
 private void DeleteUserExecute(UserToDisplay user)
 {
     _userService.DeleteUser(user.Login);
     RetrieveUsers();
 }