Beispiel #1
0
        public async void ClickVouch(object sender, EventArgs e)
        {
            var vouch = new Vouch();

            vouch.Voucher = await App.Authenticator.GetUserId();

            vouch.Vouchee = profOwner.UserId;

            var vouchTable = await tableManager.GetVouchAsync();

            var userTable = await tableManager.GetUserAsync();

            User owner = userTable.Where(u => String.Equals(u.UserId, profOwner.UserId)).ElementAt(0);


            bool alreadyVouched = vouchTable.Where(entry => String.Equals(vouch.Vouchee, entry.Vouchee) &&
                                                   String.Equals(vouch.Voucher, entry.Voucher)).Count() > 0;

            if (!alreadyVouched)
            {
                await tableManager.SaveVouchAsync(vouch);

                vouchButton.Text = "Unvouch";
                await DisplayAlert("Success", String.Format("You have now vouched for {0}!", owner.FirstName), "OK");
            }
            else
            {
                var vouched = vouchTable.Where(entry => String.Equals(vouch.Vouchee, entry.Vouchee) &&
                                               String.Equals(vouch.Voucher, entry.Voucher)).ElementAt(0);
                await tableManager.DeleteVouchAsync(vouched);

                vouchButton.Text = "Vouch";
                await DisplayAlert("Success", String.Format("You have now Unvouched {0}!", owner.FirstName), "OK");
            }
            displayVouchDetails();
        }