Beispiel #1
0
        public async Task <bool> createNewBoard(string beaconId, MainBoard board)
        {
            bool boardExists = await checkBoardCreated(board.beaconID);

            if (boardExists == false)
            {
                await MobileService.GetTable <MainBoard>().InsertAsync(board);

                return(true);
            }
            return(false);
        }
        protected async override void OnStart()
        {
            base.OnStart();
            db_accessBoard   = new BoardServerAccess();
            db_accessMessage = new MessageServerAccess();

            if (typeOfBoard.Equals("MainBoard"))
            {
                createMessageButton.Visibility = ViewStates.Visible;
                if (!beaconId.Equals(""))
                {
                    messageList = await db_accessMessage.getMainBoardMessages(beaconId);
                }
                MainBoard mb = await db_accessBoard.returnMainBoard(beaconId);

                boardCreator = mb.Creator;

                if (boardCreator.Equals(username))
                {
                    delteBoardButton.Visibility = ViewStates.Visible;
                }


                messageListview.Adapter = new MessageAdapter(this, messageList);
            }


            if (typeOfBoard.Equals("ReplyBoard"))
            {
                messageList = new List <Message>();
                if (!parentMessageID.Equals(""))
                {
                    replyMessageList = await db_accessMessage.getReplyMessages(parentMessageID);
                }

                foreach (ReplyMessage rm in replyMessageList)
                {
                    messageList.Add(rm.ReturnBase());
                }

                messageListview.Adapter = new MessageAdapter(this, messageList);
            }

            if (typeOfBoard.Equals("UserBoard"))
            {
                messageList = new List <Message>();
                {
                    messageList = await db_accessMessage.getUserMessages(username);
                }

                messageListview.Adapter = new MessageAdapter(this, messageList);
            }
        }
Beispiel #3
0
        private async void CreateBoardButton_Click(object sender, EventArgs e)
        {
            if (boardTitle.Equals(""))
            {
                var alert = new AlertDialog.Builder(this);
                alert.SetTitle("No Board name");
                alert.SetMessage("Please enter a board name.");
                alert.SetPositiveButton("OK", (senderAlert, args) => { });
                alert.Show();
            }
            else
            {
                MainBoard mb = new MainBoard(beaconId, username, boardTitle.Text);
                if (isPrivateCheckbox.Checked)
                {
                    if (boardPassword.Text.Equals(""))
                    {
                        var alert = new AlertDialog.Builder(this);
                        alert.SetTitle("No password");
                        alert.SetMessage("Please enter a password to create a private board.");
                        alert.SetPositiveButton("OK", (senderAlert, args) => { });
                        alert.Show();
                        return;
                    }
                    else
                    {
                        mb.Password       = boardPassword.Text;
                        mb.isPrivateBoard = true;
                    }
                }
                bool created = await db_accessBoard.createNewBoard(beaconId, mb);

                if (created)
                {
                    var boardActivity = new Intent(this, typeof(BoardActivity));
                    boardActivity.PutExtra("_boardType", "MainBoard");
                    boardActivity.PutExtra("_beaconID", beaconId);
                    boardActivity.PutExtra("_username", username);
                    boardActivity.PutExtra("_boardCreator", username);
                    StartActivity(boardActivity);
                }
                else
                {
                    var alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Board Not Created");
                    alert.SetMessage("The board could not be created");
                    alert.SetPositiveButton("OK", (senderAlert, args) => { });
                    alert.Show();
                }
            }
        }
        private async void UpdateBoardNames(object sender, BeaconManager.NearableEventArgs e)
        {
            for (int i = 0; i < myBeacons.Count; i++)
            {
                try
                {
                    beaconStatus.Text = "Loading Beacons";
                    BeaconView beaconView = myBeacons[i];
                    //bool boardCreated = await db_accessBoard.createNewBoard(beaconView.BeaconId, new MainBoard(beaconView.BeaconId, "Ryan Barrett", "Test Board 1"));
                    string boardname = "Not Found";
                    if (beaconsList.ContainsKey(beaconView.BeaconId))
                    {
                        beaconsList.TryGetValue(beaconView.BeaconId, out boardname);
                        myBeacons[i].BoardName = boardname;
                    }

                    else
                    {
                        MainBoard mb = await db_accessBoard.returnMainBoard(beaconView.BeaconId);

                        if (mb != null)
                        {
                            myBeacons[i].BoardName = mb.BoardName;

                            if (!beaconsList.ContainsKey(myBeacons[i].BeaconId))
                            {
                                beaconsList.Add(myBeacons[i].BeaconId, myBeacons[i].BoardName);
                            }
                        }
                    }
                    beaconStatus.Text = "";
                }
                catch (System.Exception ex)
                {
                    if (ex is System.Net.WebException)
                    {
                        beaconStatus.Text = "Web error";
                    }
                }
            }
            viewList.Adapter = new BeaconAdapter(this, myBeacons);
        }
Beispiel #5
0
        deleteBoard(string beaconId)
        {
            List <MainBoard> mbList = await MobileService.GetTable <MainBoard>().Where(p => p.beaconID == beaconId).ToListAsync();

            MainBoard      mb            = mbList[0];
            List <Message> boardMessages = await MobileService.GetTable <Message>().Where(p => p.BeaconID == beaconId).ToListAsync();

            foreach (Message mes in boardMessages)
            {
                await MobileService.GetTable <Message>().DeleteAsync(mes);
            }
            List <ReplyMessage> replyMessages = await MobileService.GetTable <ReplyMessage>().Where(p => p.BeaconID == beaconId).ToListAsync();

            foreach (ReplyMessage rpmsg in replyMessages)
            {
                await MobileService.GetTable <ReplyMessage>().DeleteAsync(rpmsg);
            }

            await MobileService.GetTable <MainBoard>().DeleteAsync(mb);
        }
Beispiel #6
0
        public async Task <MainBoard> returnMainBoard(string beaconID)
        {
            List <MainBoard> boardList = await MobileService.GetTable <MainBoard>()
                                         .Where(p => p.beaconID == beaconID)
                                         .ToListAsync();

            if (boardList.Count == 1)
            {
                MainBoard returnBoard = new MainBoard(boardList[0].beaconID, boardList[0].Creator, boardList[0].BoardName);
                if (boardList[0].isPrivateBoard)
                {
                    returnBoard.Password       = boardList[0].Password;
                    returnBoard.isPrivateBoard = boardList[0].isPrivateBoard;
                }
                return(returnBoard);
            }
            else
            {
                return(null);
            }
        }
        private async void ViewList_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            try
            {
                var viewList = sender as ListView;
                var t        = myBeacons[e.Position];


                if (t.BoardName.Equals("Not Found"))
                {
                    Intent createBoardActivity = new Intent(this, typeof(CreateBoardActivity));
                    string username            = Intent.GetStringExtra("_username");
                    createBoardActivity.PutExtra("_beaconID", t.BeaconId);
                    createBoardActivity.PutExtra("_username", username);
                    StartActivity(createBoardActivity);
                }
                else
                {
                    MainBoard mb = await db_accessBoard.returnMainBoard(t.BeaconId);

                    var    boardActivity = new Intent(this, typeof(BoardActivity));
                    string username      = Intent.GetStringExtra("_username");
                    boardActivity.PutExtra("_boardType", "MainBoard");
                    boardActivity.PutExtra("_beaconID", t.BeaconId);
                    boardActivity.PutExtra("_username", username);


                    if (mb.isPrivateBoard)
                    {
                        webCount = 0;
                        EditText input = new EditText(this);
                        var      alert = new AlertDialog.Builder(this);
                        input.SetRawInputType(InputTypes.TextVariationPassword);
                        alert.SetView(input);
                        alert.SetTitle("Private Board");
                        alert.SetMessage("Board is private, plase enter the password.");
                        alert.SetPositiveButton("OK", (senderAlert, args) =>
                        {
                            if (mb.Password.Equals(input.Text))
                            {
                                StartActivity(boardActivity);
                            }
                            else
                            {
                                var alert2 = new AlertDialog.Builder(this);
                                alert2.SetTitle("Private Board");
                                alert2.SetMessage("Password Incorrect");
                                alert2.SetPositiveButton("OK", (senderAlert2, args2) => { });
                                alert2.Show();
                            }
                        });
                        alert.SetNegativeButton("Cancel", (senderAlert, args) => { });
                        alert.Show();
                    }
                    else
                    {
                        webCount = 0;
                        StartActivity(boardActivity);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is System.Net.WebException && webCount < 3)
                {
                    ViewList_ItemClick(sender, e);
                }
            }
        }