Esempio n. 1
0
        // Retrieving information about item selected on profile by current user (e.g. if it has been lent out or not)
        public async void OnSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var game     = e.SelectedItem as Boardgames;
            var requests = await tableManager.GetRequestAsync();

            string borrowMsg = "";

            if (game.Borrowed)
            {
                Request req   = requests.Where(r => string.Equals(r.Lender, this.sid) && string.Equals(r.ItemId, game.Id)).ElementAt(0);
                var     users = await tableManager.GetUserAsync();

                User borrower = users.Where(u => string.Equals(u.UserId, req.Borrower)).ElementAt(0);
                var  alert    = await DisplayAlert("Item information", String.Format("You have lent this game to {0} {1} from {2} to {3}", borrower.FirstName, borrower.LastName, req.StartDate, req.EndDate), "Mark As Returned", "Cancel");

                if (alert)
                {
                    await Navigation.PushModalAsync(new LeaveReviewPage(borrower, game, false));

                    req.Accepted = "Returned";
                    await tableManager.SaveRequestAsync(req);
                }
            }
            else
            {
                borrowMsg = String.Format("This game is still available for users to borrow in {0} for {1} days\n", game.Location, game.Lend_duration);
                List <Request> pendingReqs = requests.Where(r => string.Equals(r.ItemId, game.Id) && string.Equals(r.Accepted, "Pending")).ToList();

                if (pendingReqs.Count == 0)
                {
                    var alert = await DisplayAlert("Item information", borrowMsg, "Delete", "OK");

                    if (alert)
                    {
                        await tableManager.DeleteBoardgamesAsync(game);
                    }
                }
                else
                {
                    await DisplayAlert("Item information", borrowMsg, "OK");
                }
            }
            await RefreshItems(false, syncItems : false);
        }