Example #1
0
        async private void JoinHouseholdButton_Clicked(object sender, EventArgs e)
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            // Household tmp = db.Household.FindByHouseholdId(JoinHouseholdEntry.Text);
            if (db.Household.Exists(new Household()
            {
                HouseholdId = JoinHouseholdEntry.Text
            }))
            {
                User user = new User()
                {
                    Name        = Username,
                    Password    = HashedPassword,
                    HouseholdId = JoinHouseholdEntry.Text
                };
                db.User.AddIfNotExists(user);
                App.Current.MainPage = new LoginPage();
            }
            else
            {
                //tmp = null;
                await DisplayAlert("Falsche Eingabe", "Dieser Haushalt existiert nicht.", "Zurück zum Haushalt");
            }
        }
Example #2
0
        public HomePage()
        {
            db = new HaushaltsplanerDB();
            InitializeComponent();

            BindingContext = viewModel = new HomeViewModel();
        }
 async void CreateUserButtonOnClick(object sender, EventArgs args)
 {
     if (string.IsNullOrWhiteSpace(RegisterUsername.Text) || string.IsNullOrWhiteSpace(RegisterPassword.Text))
     {
         await DisplayAlert("Ungültige Eingabe", "Geben Sie einen Benutzernamen und ein Passwort ein.", "Zurück zur Registrierung");
     }
     else
     {
         HaushaltsplanerDB db = new HaushaltsplanerDB();
         //User tmp = db.User.FindByName(RegisterUsername.Text);
         if (db.User.Exists(new User()
         {
             Name = RegisterUsername.Text
         }))
         {
             await DisplayAlert("Benutzername bereits vergeben", "Dieser Benutzername ist bereits vergeben. Bitte geben Sie einen anderen Namen ein.", "Zurück zur Registrierung");
         }
         else
         {
             await Navigation.PushAsync(new RegisterHouseholdPage()
             {
                 Username = RegisterUsername.Text, HashedPassword = Crypto.ComputeSHA256(RegisterPassword.Text)
             });
         }
     }
 }
Example #4
0
        /// <summary>
        /// Returns a list of users that joined the household
        /// </summary>
        /// <returns></returns>
        private List <User> FindAllHouseholdUsers()
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();
            List <User>       household_users = db.User.FindAllUserFromHousehold(Session.Household.HouseholdId);

            return(household_users);
        }
Example #5
0
        /// <summary>
        /// Overwrites session with data from database
        /// </summary>
        public void Pull()
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            User           = db.User.FindByName(Session.User.Name);
            Household      = db.Household.FindByHouseholdId(Session.Household.HouseholdId);
            HouseholdUsers = FindAllHouseholdUsers();
        }
Example #6
0
        public static void RegisterJoinHousehold(string username, string password, string householdID)
        {
            HaushaltsplanerDB db         = new HaushaltsplanerDB();
            string            hashed_pwd = Crypto.ComputeSHA256(password);

            db.User.AddIfNotExists(new User()
            {
                Name = username, Password = hashed_pwd, HouseholdId = householdID
            });
        }
Example #7
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            HaushaltsplanerDB db = new HaushaltsplanerDB();
            List <User>       household_users = db.User.FindAllUserFromHousehold(Session.Household.HouseholdId);

            Label_username.Text      = Session.User.Name;
            Label_household.Text     = Session.User.HouseholdId;
            Label_houshold_user.Text = string.Join(", ", household_users);
        }
Example #8
0
        public SettingsPage()
        {
            InitializeComponent();

            HaushaltsplanerDB db = new HaushaltsplanerDB();
            List <User>       household_users = db.User.FindAllUserFromHousehold(Session.Household.HouseholdId);

            Label_username.Text      = Session.User.Name;
            Label_household.Text     = Session.User.HouseholdId;
            Label_houshold_user.Text = string.Join(", ", household_users);
        }
Example #9
0
        public HouseholdViewModel()
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            Session.Household = db.Household.FindByHouseholdId(Session.Household.HouseholdId);

            Title           = $"Haushalt {Session.Household.Name}";
            _householdUsers = Session.HouseholdUsers;
            Total           = 0;
            ShowPieChart(DateTime.Now);
            ShowPointChart(DateTime.Now.Year);
        }
Example #10
0
        public static bool CheckIfUserExists(string username)
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            if (db.User.FindByName(username) != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        public static bool LoginUser(string username, string password)
        {
            HaushaltsplanerDB db         = new HaushaltsplanerDB();
            string            hashed_pwd = Crypto.ComputeSHA256(password);
            User      user      = db.User.FindByName(username);
            Household household = db.Household.FindByHouseholdId(user.HouseholdId);

            if (user.Password == hashed_pwd)
            {
                Session Session = new Session(user, household);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #12
0
        async private void CreateHouseholdButton_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(RegisterHousholdEntry.Text))
            {
                await DisplayAlert("Falsche Eingabe", "Bitte geben Sie einen Namen ein.", "Zurück zum Haushalt");
            }
            else
            {
                HaushaltsplanerDB db = new HaushaltsplanerDB();
                Random            rnd = new Random();
                int       _randomId, _idLength;
                string    _finalId;
                Household household = new Household();
                do
                {
                    _randomId = rnd.Next(1, 9999);
                    _idLength = _randomId.ToString().Length;
                    _finalId  = String.Empty;
                    for (int i = 0; i < (4 - _idLength); i++)
                    {
                        _finalId = _finalId + "0";
                    }
                    _finalId = _finalId + _randomId.ToString();

                    household = new Household()
                    {
                        Name        = RegisterHousholdEntry.Text,
                        HouseholdId = RegisterHousholdEntry.Text + "#" + _finalId
                    };
                } while (db.Household.Exists(household));


                User user = new User()
                {
                    Name        = Username,
                    Password    = HashedPassword,
                    HouseholdId = household.HouseholdId
                };


                db.Household.AddIfNotExists(household);
                db.User.AddIfNotExists(user);
                App.Current.MainPage = new LoginPage();
            }
        }
Example #13
0
        public PurchaseViewModel()
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            Session.Household = db.Household.FindByHouseholdId(Session.Household.HouseholdId);

            Title     = "Einkäufe";
            Purchases = new ObservableCollection <Purchase>();

            PopulatePurchases();

            // Creates a subscriber that waits for new added purchases from New Purchase Page
            MessagingCenter.Subscribe <NewPurchasePage, Purchase>(this, "AddPurchase", (sender, arg) =>
            {
                // insert new purchase to listview
                Purchases.Insert(0, arg);
            });
        }
Example #14
0
        /// <summary>
        /// creates a new session when username and password are correct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async void LoginButtonOnClick(object sender, EventArgs args)
        {
            // username and password required for login
            if (string.IsNullOrWhiteSpace(username.Text) || string.IsNullOrWhiteSpace(password.Text))
            {
                // error message
                await DisplayAlert("Fehlende Eingabe", "Bitte geben Sie Benutzernamen und Passwort ein.", "Zurück zum Login");
            }
            else
            {
                // MongoDB Connection
                HaushaltsplanerDB db         = new HaushaltsplanerDB();
                string            hashed_pwd = Crypto.ComputeSHA256(password.Text); // password hashed (SHA256)
                User user = db.User.FindByName(username.Text);                      // instanciates user object from database
                //if user does not exist
                if (user == null)
                {
                    // error message
                    await DisplayAlert("Falsche Eingabe", "Falscher Benutzername oder Passwort.", "Zurück zum Login");

                    hashed_pwd = String.Empty;
                }
                else // if user exists
                {
                    // instanciates household object from database
                    Household household = db.Household.FindByHouseholdId(user.HouseholdId);
                    // if password and username are correct
                    if (user.Password == hashed_pwd)
                    {
                        // create a new session that can be accessed later on
                        Session Session = new Session(user, household);
                        App.Current.MainPage = new MainPage();
                    }
                    else // wrong password
                    {
                        // error message
                        await DisplayAlert("Falsche Eingabe", "Falscher Benutzername oder Passwort.", "Zurück zum Login");

                        hashed_pwd = String.Empty;
                        user       = null;
                    }
                }
            }
        }
Example #15
0
        public HomeViewModel()
        {
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            Session.Household = db.Household.FindByHouseholdId(Session.Household.HouseholdId);

            Title = "Startseite";

            HouseholdUsers    = new ObservableCollection <User>();
            Claim             = new ObservableCollection <UserClaim>();
            Debt              = new ObservableCollection <UserDebt>();
            _claim_dictionary = new Dictionary <string, double>();
            _debt_dictionary  = new Dictionary <string, double>();
            Netto             = 0;

            _household_users = FindAllHouseholdUsers();

            // Fills the listview with data
            PopulateHouseholdUsers();

            CostCalculation();
        }
Example #16
0
        public async void InsertPurchase(object sender, EventArgs e)
        {
            if (!IsFormValid())
            {
                await DisplayAlert("Fehler", "Bitte geben Sie ein Titel und ein gültigen Preis an.", "Ok");

                return;
            }


            // create username list from selected users in collection view CollectionView_purchase_involved_users
            List <String> _usersInvolved = new List <String>();

            foreach (var item in CollectionView_purchase_involved_users.SelectedItems)
            {
                User selectedUser = (User)item;
                _usersInvolved.Add(selectedUser.Name);
            }

            // add payed users to involved
            //if (!_usersInvolved.Contains(((User)Picker_purchase_payed_by.SelectedItem).Name))
            //{
            //    _usersInvolved.Add(((User)Picker_purchase_payed_by.SelectedItem).Name);
            //}

            // add payed users to payed list
            List <string> _usersInvolvedPayed = new List <string>();

            _usersInvolvedPayed.Add(((User)Picker_purchase_payed_by.SelectedItem).Name);

            // get image
            Receipt receipt = new Receipt();

            try
            {
                ImageSource img = Image_purchase_receipt.Source;
                if ((viewModel.ReceiptImageLocalPath != null || viewModel.ReceiptImageLocalPath != "") &&
                    (viewModel.Image_ReceiptImage != null))
                {
                    viewModel.ReceiptImageS3Path = await S3.Upload(viewModel.ReceiptImageLocalPath, viewModel.Image_ReceiptImage.Id.ToString());

                    receipt.ImageUrl = $"{viewModel.ReceiptImageS3Path}";
                }
            }
            catch (Exception)
            {
            }


            Purchase newPurchase = new Purchase()
            {
                Title              = Entry_purchase_title.Text,
                Price              = double.Parse(Entry_purchase_price.Text),
                Date               = DatePicker_purchase_day.Date,
                UserPayed          = ((User)Picker_purchase_payed_by.SelectedItem).Name,
                UsersInvolved      = _usersInvolved,
                UsersInvolvedPayed = _usersInvolvedPayed,
                Receipt            = receipt
            };
            HaushaltsplanerDB db = new HaushaltsplanerDB();

            // sync session with database
            Session.Household = db.Household.FindByHouseholdId(Session.Household.HouseholdId);
            // add new purchase to session
            Session.Household.AddPurchase(newPurchase);
            // update database with session
            db.Household.Update(Session.Household);

            // Send message to Purchase Page
            // updates listview with new purchase
            MessagingCenter.Send(this, "AddPurchase", newPurchase);

            CollectionView_purchase_involved_users.SelectedItem  = null;
            CollectionView_purchase_involved_users.SelectedItems = null;
            Navigation.PopAsync();
        }