예제 #1
0
        private async void BorrowItem(Boardgames game)
        {
            BorrowItemPage borrowPage = new BorrowItemPage(game);
            await Navigation.PushModalAsync(borrowPage, false);

            resultList.ItemsSource = null;
        }
예제 #2
0
 public LeaveReviewPage(User user, Boardgames product, bool borrowed)
 {
     InitializeComponent();
     otherUser     = user;
     item          = product;
     this.borrowed = borrowed;
     manager       = TableManager.DefaultManager;
     // Changing questions based on if borrower or lender is leaving reviews
     if (borrowed)
     {
         userExperienceTitle.Text     = String.Format("How was your experience borrowing from {0} {1}?", otherUser.FirstName, otherUser.LastName);
         userFeedbackDescription.Text = String.Format("Leave some feedback about how reliable {0} was, when you borrowed {1} from them", otherUser.FirstName, item.Name);
         itemExperienceTitle.Text     = String.Format("How would you rate the condition of {0} when you borrowed it?", item.Name);
         itemFeedbackDescription.Text = String.Format("Leave some feedback about the product, {0}, that you borrowed", item.Name);
     }
     else
     {
         userExperienceTitle.Text          = String.Format("How was your experience lending to {0} {1}?", otherUser.FirstName, otherUser.LastName);
         userFeedbackDescription.Text      = String.Format("Leave some feedback about how well your item, {0} was looked after by {1} for other users to see!", item.Name, otherUser.FirstName);
         itemExperienceTitle.IsVisible     = false;
         itemFeedbackDescription.IsVisible = false;
         itemRating.IsVisible = false;
         itemReview.IsVisible = false;
     }
 }
예제 #3
0
        public async void OnSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var reqMsg = e.SelectedItem as RequestMessage;

            seenUnseenCol = "White";

            if (!String.Equals("Vouch", reqMsg.RequestType))
            {
                var        alert         = false;
                var        alert2        = false;
                var        alert3        = false;
                Request    req           = reqMsg.Request;
                Boardgames requestedItem = reqMsg.RequestedItem;

                if (reqMsg.AcceptStatus.Equals("Pending") && reqMsg.RequestType.Equals("Lend Request"))
                {
                    alert = await DisplayAlert("Borrowing request", reqMsg.OtherUser.FirstName + " " + reqMsg.OtherUser.LastName + " has requested to borrow " + requestedItem.Name + " from " + req.StartDate + " to " + req.EndDate, "View Profile", "Cancel");
                }
                else if (reqMsg.AcceptStatus.Equals("Returned") && reqMsg.RequestType.Equals("Borrow Request"))
                {
                    await Navigation.PushModalAsync(new LeaveReviewPage(reqMsg.OtherUser, requestedItem, true));

                    requestedItem.Borrowed = false;
                    await tableManager.SaveBoardgamesAsync(requestedItem);

                    await tableManager.DeleteRequestAsync(req);
                    await RefreshItems(false, syncItems : false);
                }
                else if (reqMsg.AcceptStatus.Equals("Accepted") && reqMsg.RequestType.Equals("Lend Request"))
                {
                    alert2 = await DisplayAlert("Undo", "Undo accepted lend request?", "Yes", "No");
                }
                else if (reqMsg.AcceptStatus.Equals("Pending") && reqMsg.RequestType.Equals("Borrow Request"))
                {
                    alert3 = await DisplayAlert("Undo", "Undo pending borrow request?", "Yes", "No");
                }

                if (alert)
                {
                    await Navigation.PushModalAsync(new ProfileViewPage(reqMsg.OtherUser, requestedItem, reqMsg.Request, false));
                    await RefreshItems(false, syncItems : false);
                }

                if (alert2)
                {
                    await tableManager.DeleteRequestAsync(req);
                    await RefreshItems(false, syncItems : false);
                }

                if (alert3)
                {
                    await tableManager.DeleteRequestAsync(req);
                    await RefreshItems(false, syncItems : false);
                }
            }
        }
예제 #4
0
 public async Task SaveBoardgamesAsync(Boardgames item)
 {
     if (item.Id == null)
     {
         await boardgamesTable.InsertAsync(item);
     }
     else
     {
         await boardgamesTable.UpdateAsync(item);
     }
 }
예제 #5
0
        private async Task RefreshItems(bool showActivityIndicator, bool syncItems)
        {
            string sid = await App.Authenticator.GetUserId();

            var reqs = await tableManager.GetRequestAsync(syncItems);

            var games = await tableManager.GetBoardgamesAsync(syncItems);

            var users = await tableManager.GetUserAsync(syncItems);

            var lenderAcceptedRequests = reqs.Where(r => (String.Equals(r.Lender, sid)) && (r.Accepted.Equals("True")));
            var borrowAcceptedRequests = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (r.Accepted.Equals("True")));

            List <RequestMessage> borrows = new List <RequestMessage>();
            List <RequestMessage> lends   = new List <RequestMessage>();

            string requestType   = "Lend Request";
            string requestStatus = "Accepted";
            string col           = "#00cc00";
            string seenUnseenCol = "#E0E0E0";

            foreach (Request r in lenderAcceptedRequests)
            {
                User       borrowingUser   = users.Where(user => String.Equals(r.Borrower, user.UserId)).ElementAt(0);
                Boardgames requestedItem   = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                string     notifView       = String.Format("{0}", requestedItem.Name);
                string     notifViewDetail = String.Format(" ");

                if (borrowingUser.UserId == Receiver.UserId)
                {
                    lends.Add(new RequestMessage(requestedItem, borrowingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }
            }

            requestType   = "Borrow Request";
            requestStatus = "Accepted";

            foreach (Request r in borrowAcceptedRequests)
            {
                User       lendingUser     = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                Boardgames requestedItem   = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                string     notifView       = String.Format("{0}", requestedItem.Name);
                string     notifViewDetail = String.Format(" ");

                if (lendingUser.UserId == Receiver.UserId)
                {
                    borrows.Add(new RequestMessage(requestedItem, lendingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }
            }

            borrowList.ItemsSource = borrows;
            lendList.ItemsSource   = lends;
        }
예제 #6
0
 public RequestMessage(Boardgames item, User notifier, string requestType, string acceptStatus,
                       string updatedAt, string notificationView, string notificationViewDetail, string notificationColour, string seenUnseenColour, Request req)
 {
     requestedItem               = item;
     otherUser                   = notifier;
     this.requestType            = requestType;
     this.acceptStatus           = acceptStatus;
     this.updatedAt              = updatedAt;
     this.notificationView       = notificationView;
     this.notificationViewDetail = notificationViewDetail;
     this.notificationColour     = notificationColour;
     this.seenUnseenColour       = seenUnseenColour;
     request = req;
 }
예제 #7
0
 public ItemViewPage(Boardgames item, User owner)
 {
     InitializeComponent();
     manager          = TableManager.DefaultManager;
     this.item        = item;
     this.owner       = owner;
     Owner.Text       = owner.FirstName + ' ' + owner.LastName;
     ProductName.Text = item.Name;
     Description.Text = item.Description;
     Category.Text    = item.Category;
     Location.Text    = item.Location;
     Duration.Text    = String.Format("Available for {0} days", item.Lend_duration);
     displayItemImage();
     displayRatings();
 }
예제 #8
0
        public BorrowItemPage(Boardgames game)
        {
            InitializeComponent();
            tableManager          = TableManager.DefaultManager;
            gameName.Text         = game.Name;
            gameDescription.Text  = game.Description;
            lend_duration         = game.Lend_duration;
            gameLendDuration.Text = "Available for " + lend_duration + " days.";
            startDate.MinimumDate = DateTime.Today.AddDays(1);
            endDate.Date          = startDate.Date.AddDays(lend_duration);
            endDate.MinimumDate   = startDate.Date.AddDays(1);
            endDate.MaximumDate   = endDate.Date;

            this.owner = game.Owner;
            this.id    = game.Id;
        }
예제 #9
0
 // View of another user's profile, i.e. only shows items that they are lending out that are still available
 public ProfileViewPage(User profOwner, Boardgames reqItem, Request req, bool borrowing)
 {
     InitializeComponent();
     tableManager   = TableManager.DefaultManager;
     this.profOwner = profOwner;
     this.reqItem   = reqItem;
     this.borrowing = borrowing;
     if (!borrowing)
     {
         this.req = req;
     }
     displayDetails();
     displayProfilePicture();
     displayGemAndRank();
     VouchMessage.GestureRecognizers.Add(new TapGestureRecognizer((view) => SeeVouchers()));
 }
예제 #10
0
        // Creating JSON object to represent new item, and then sending it to backend to be inserted into database table
        public async void OnAdd(object sender, EventArgs e)
        {
            string sid = await App.Authenticator.GetUserId();

            // Checking that user has filled in all required fields
            if (string.IsNullOrEmpty(newItemName.Text) || newItemCategory.SelectedIndex.Equals(-1) || string.IsNullOrEmpty(newItemDescription.Text) || string.IsNullOrEmpty(newItemLendDuration.Text) || string.IsNullOrEmpty(newItemLocation.Text))
            {
                await DisplayAlert("Error", "All fields must be completed", "Ok");
            }
            else
            {
                var location = newItemLocation.Text;
                var latitude = await getLatitudeFromLocation(location);

                var longitude = await getLongitudeFromLocation(location);

                int duration;
                if (int.TryParse(newItemLendDuration.Text, out duration) && duration > 0)
                {
                    buttonsPanel.IsVisible = false;
                    using (var scope = new ActivityIndicatorScope(syncIndicator, true))
                    {
                        var boardgames = new Boardgames {
                            Name = newItemName.Text, Description = newItemDescription.Text, Lend_duration = Int32.Parse(newItemLendDuration.Text), Location = location, Latitude = latitude, Longitude = longitude, Owner = sid, Borrowed = false, Category = newItemCategory.Items[newItemCategory.SelectedIndex]
                        };
                        await AddItem(boardgames);

                        //Add item photo to storage account
                        if (itemImageFile != null)
                        {
                            var boardGamesTable = await manager.GetBoardgamesAsync();

                            var itemId = boardGamesTable.Where(b => (String.Equals(b.Owner, sid)))
                                         .OrderByDescending(b => b.CreatedAt)
                                         .Select(b => b.Id)
                                         .ElementAt(0);
                            var itemName = await ImageManager.GenerateItemPhotoName(itemId);

                            await ImageManager.UploadImage(itemImageFile.GetStream(), itemName);

                            itemImageFile.Dispose();
                            itemImageFile = null;
                        }
                    }
                    buttonsPanel.IsVisible = true;
                    await DisplayAlert("Success", "Your item has been added", "Ok");

                    // Empty all fields after item has been successfully added
                    newItemName.Text              = string.Empty;
                    newItemDescription.Text       = descriptionPlaceholder;
                    newItemDescription.TextColor  = Color.Gray;
                    newItemLendDuration.Text      = string.Empty;
                    newItemLocation.Text          = string.Empty;
                    newItemCategory.SelectedIndex = -1;
                    newItemName.Unfocus();
                    itemImage.Source = null;
                }
                else
                {
                    await DisplayAlert("Error", "Number of days must be a positive whole number", "Ok");
                }
            }
        }
예제 #11
0
 // Data methods
 async Task AddItem(Boardgames item)
 {
     await manager.SaveBoardgamesAsync(item);
 }
예제 #12
0
        private async Task RefreshItems(bool showActivityIndicator, bool syncItems)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator))
            {
                string sid = await App.Authenticator.GetUserId();

                var reqs = await tableManager.GetRequestAsync(syncItems);

                var chats = await tableManager.GetChatAsync(syncItems);

                var games = await tableManager.GetBoardgamesAsync(syncItems);

                var users = await tableManager.GetUserAsync(syncItems);

                var message = await tableManager.GetMessageAsync(syncItems);

                var itemLendRequests   = reqs.Where(r => (String.Equals(r.Lender, sid)) && (String.Equals(r.Accepted, "True")));
                var itemBorrowRequests = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (String.Equals(r.Accepted, "True")));

                List <ChatDetails> acceptedMsgs = new List <ChatDetails>();
                bool seen = false;

                foreach (Request r in itemLendRequests)
                {
                    User       borrowingUser = users.Where(user => String.Equals(r.Borrower, user.UserId)).ElementAt(0);
                    User       lendingUser   = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);


                    foreach (ChatDetails c in acceptedMsgs)
                    {
                        // Checking that two chats are not created between the same two users
                        if ((String.Equals(lendingUser.Id, c.Recipient.Id)) || (String.Equals(borrowingUser.Id, c.Recipient.Id)))
                        {
                            seen = true;
                            Debug.WriteLine("Borrowing user if: {0}", borrowingUser.FirstName);
                        }
                    }

                    if (!seen)
                    {
                        var msgs = message.Where(m => (String.Equals(m.Sender, sid) && String.Equals(m.Receiver, borrowingUser.UserId)) ||
                                                 (String.Equals(m.Receiver, sid) && String.Equals(m.Sender, borrowingUser.UserId)));

                        var lastMessage = " ";

                        if (msgs.Count() > 0)
                        {
                            lastMessage = msgs.Last().Text;
                        }

                        acceptedMsgs.Add(new ChatDetails(lastMessage, borrowingUser, false));
                    }

                    seen = false;
                }


                foreach (Request r in itemBorrowRequests)
                {
                    User       borrowingUser = users.Where(user => String.Equals(r.Borrower, user.UserId)).ElementAt(0);
                    User       lendingUser   = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);


                    foreach (ChatDetails c in acceptedMsgs)
                    {
                        if ((String.Equals(lendingUser.Id, c.Recipient.Id)) || (String.Equals(borrowingUser.Id, c.Recipient.Id)))
                        {
                            seen = true;
                            Debug.WriteLine("Lending user if: {0}", lendingUser.FirstName);
                        }
                    }

                    if (!seen)
                    {
                        var msgs = message.Where(m => (String.Equals(m.Sender, sid) && String.Equals(m.Receiver, lendingUser.UserId)) ||
                                                 (String.Equals(m.Receiver, sid) && String.Equals(m.Sender, lendingUser.UserId)));

                        var lastMessage = " ";

                        if (msgs.Count() > 0)
                        {
                            lastMessage = msgs.Last().Text;
                        }

                        acceptedMsgs.Add(new ChatDetails(lastMessage, lendingUser, false));
                    }

                    seen = false;
                }



                acceptedList.ItemsSource = acceptedMsgs;
            }
        }
예제 #13
0
 public async Task DeleteBoardgamesAsync(Boardgames item)
 {
     await boardgamesTable.DeleteAsync(item);
 }
예제 #14
0
        private async Task RefreshItems(bool showActivityIndicator, bool syncItems)
        {
            using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator))
            {
                string sid = await App.Authenticator.GetUserId();

                var reqs = await tableManager.GetRequestAsync(syncItems);

                var games = await tableManager.GetBoardgamesAsync(syncItems);

                var users = await tableManager.GetUserAsync(syncItems);

                var vouches = await tableManager.GetVouchAsync(syncItems);

                var myVouches              = vouches.Where(v => (String.Equals(sid, v.Vouchee)));
                var lenderPendingRequests  = reqs.Where(r => (String.Equals(r.Lender, sid)) && (r.Accepted.Equals("Pending")));
                var lenderAcceptedRequests = reqs.Where(r => (String.Equals(r.Lender, sid)) && (r.Accepted.Equals("True")));
                var borrowPendingRequests  = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (r.Accepted.Equals("Pending")));
                var borrowRejectedRequests = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (r.Accepted.Equals("False")));
                var borrowAcceptedRequests = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (r.Accepted.Equals("True")));
                var borrowReturnedRequests = reqs.Where(r => (String.Equals(r.Borrower, sid)) && (r.Accepted.Equals("Returned")));

                List <RequestMessage> requestsMsgs = new List <RequestMessage>();

                string requestType   = "Lend Request";
                string requestStatus = "Pending";
                string col           = "#00cc00";
                seenUnseenCol = "#bfbfbf";

                // Finding all the requests that show another user wanting to borrow an item from current user (pending requests)
                foreach (Request r in lenderPendingRequests)
                {
                    User       borrowingUser   = users.Where(user => String.Equals(r.Borrower, user.UserId)).ElementAt(0);
                    Boardgames requestedItem   = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    string     notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string     notifViewDetail = String.Format("{0} wants to borrow your item", borrowingUser.FirstName);
                    requestsMsgs.Add(new RequestMessage(requestedItem, borrowingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                requestStatus = "Accepted";
                seenUnseenCol = "White";

                // Finding all the requests that show current user has accepted a request to borrow item
                foreach (Request r in lenderAcceptedRequests)
                {
                    User       borrowingUser = users.Where(user => String.Equals(r.Borrower, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    Debug.WriteLine("Date accepted: {0}", r.UpdatedAt);
                    string notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string notifViewDetail = String.Format("You have accepted {0}'s request", borrowingUser.FirstName);
                    requestsMsgs.Add(new RequestMessage(requestedItem, borrowingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                requestType   = "Borrow Request";
                col           = "#b35050";
                seenUnseenCol = "White";

                // Finding all the requests that show another user has accepted current user's request to borrow item
                foreach (Request r in borrowAcceptedRequests)
                {
                    User       lendingUser   = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    Debug.WriteLine("Date accepted: {0}", r.UpdatedAt);
                    string notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string notifViewDetail = String.Format("{0} has accepted your request!", lendingUser.FirstName);
                    requestsMsgs.Add(new RequestMessage(requestedItem, lendingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                requestStatus = "Pending";
                seenUnseenCol = "White";

                // Finding all the pending requests that show current user has requested to borrow an item
                foreach (Request r in borrowPendingRequests)
                {
                    User       lendingUser   = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    Debug.WriteLine("Date pending: {0}", r.UpdatedAt);
                    string notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string notifViewDetail = String.Format("Waiting for {0} to accept your request", lendingUser.FirstName, requestStatus);
                    requestsMsgs.Add(new RequestMessage(requestedItem, lendingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                requestStatus = "Rejected";
                seenUnseenCol = "White";

                // Finding all the requests that show another user has rejected current user's request to borrow item
                foreach (Request r in borrowRejectedRequests)
                {
                    User       lendingUser   = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    Debug.WriteLine("Date: {0}", r.UpdatedAt);
                    string notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string notifViewDetail = String.Format("{0} has rejected your request", lendingUser.FirstName);
                    requestsMsgs.Add(new RequestMessage(requestedItem, lendingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                requestStatus = "Returned";
                seenUnseenCol = "#bfbfbf";

                // Finding all the requests that show current user has returned an item that they borrowed
                foreach (Request r in borrowReturnedRequests)
                {
                    User       lendingUser     = users.Where(user => String.Equals(r.Lender, user.UserId)).ElementAt(0);
                    Boardgames requestedItem   = games.Where(game => String.Equals(r.ItemId, game.Id)).ElementAt(0);
                    string     notifView       = String.Format("{0}: {1}", requestType, requestedItem.Name);
                    string     notifViewDetail = String.Format("{0} - {1}", lendingUser.FirstName, requestStatus);
                    requestsMsgs.Add(new RequestMessage(requestedItem, lendingUser, requestType, requestStatus, r.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, r));
                }

                col           = "#6666ff";
                seenUnseenCol = "White";

                // Finding all the users who have vouched for current user, and creating a notification for this
                foreach (Vouch v in myVouches)
                {
                    User   voucher         = users.Where(user => String.Equals(user.UserId, v.Voucher)).ElementAt(0);
                    string notifView       = String.Format("Vouch Alert: {0} {1}", voucher.FirstName, voucher.LastName);
                    string notifViewDetail = String.Format("{0} has vouched for you!", voucher.FirstName);
                    requestsMsgs.Add(new RequestMessage(null, voucher, "Vouch", "Vouch Alert", v.UpdatedAt, notifView, notifViewDetail, col, seenUnseenCol, null));
                }


                requestsMsgs.Sort((y, x) => x.UpdatedAt.CompareTo(y.UpdatedAt));

                notifsList.ItemsSource = requestsMsgs;
            }
        }