Example #1
0
        private async void MakeChatroom(int bobs_ID)
        {
            Response res = Task.FromResult <Response>(await ChatRoomRepository.PostChatRoom(bobs_ID)).Result;

            if (res.Success == true)
            {
                VindRitChatVM.ID = res.NewID.Value;

                Bob.All          bob             = VindRitVM.SelectedBob;
                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From   = MainViewVM.USER.ID, //from user
                    To     = bob.User.ID,        //to bob
                    Status = true,
                    Object = res.NewID.Value
                };

                Libraries.Socket socketSendToUser = new Libraries.Socket()
                {
                    From   = bob.User.ID,        //from bob
                    To     = MainViewVM.USER.ID, //to user
                    Status = true,
                    Object = res.NewID.Value
                };


                MainViewVM.socket.Emit("chatroom_OPEN:send", JsonConvert.SerializeObject(socketSendToBob));  //bob
                MainViewVM.socket.Emit("chatroom_OPEN:send", JsonConvert.SerializeObject(socketSendToUser)); //bob
            }
        }
Example #2
0
        //by user
        //wanneer bob accepteer, wordt door gebruiker die aanvraagd aangemaakt
        private async void MakeTrip(Trip trip, int bobID)
        {
            Response res = Task.FromResult <Response>(await TripRepository.PostTrip(trip)).Result;

            if (res.Success == true)
            {
                VindRitVM.StatusID = 1;
                Location location = await LocationService.GetCurrent();

                Trips_Locations tripL = new Trips_Locations()
                {
                    Trips_ID    = res.NewID.Value,
                    Location    = JsonConvert.SerializeObject(location),
                    Statuses_ID = VindRitVM.StatusID
                };

                Response okTripL = await TripRepository.PostLocation(tripL);


                Trip currentTrip = Task.FromResult <Trip>(await TripRepository.GetCurrentTrip()).Result;


                Bob.All          bob             = VindRitVM.SelectedBob;
                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From   = MainViewVM.USER.ID, //from user
                    To     = bob.User.ID,        //to bob
                    Status = true,
                    Object = currentTrip
                };


                MainViewVM.socket.Emit("trip_START:send", JsonConvert.SerializeObject(socketSendToBob)); //bob
                StartTrip(currentTrip);                                                                  //user
                TripSave(currentTrip);


                MakeChatroom(bobID);
            }
        }
Example #3
0
        private async Task <Boolean> AddComment_task()
        {
            ChatComment comment = new ChatComment()
            {
                ChatRooms_ID = MainViewVM.ChatRoom.ID,
                Comment      = this.ChatComment
            };
            Response res = await ChatRoomRepository.PostChatComment(comment);

            if (res.Success == true)
            {
                int              bobID  = ChatRoom.ChatRoom.Bobs_ID;
                Bob.All          bob    = Task.FromResult <Bob.All>(await BobsRepository.GetBobById(bobID)).Result;
                int              userID = ChatRoom.ChatRoom.Users_ID;
                Libraries.Socket socketSendToBob;
                Libraries.Socket socketSendToUser;

                if (MainViewVM.USER.IsBob == false)
                {
                    socketSendToBob = new Libraries.Socket()
                    {
                        From    = MainViewVM.USER.ID,
                        To      = bob.User.ID,
                        Status  = true,
                        Object  = comment.Comment,
                        Object2 = true
                    };
                    socketSendToUser = new Libraries.Socket()
                    {
                        From    = bob.User.ID,
                        To      = ChatRoom.ChatRoom.Users_ID,
                        Status  = true,
                        Object  = comment.Comment,
                        Object2 = false
                    };
                }
                else
                {
                    socketSendToBob = new Libraries.Socket()
                    {
                        From    = MainViewVM.USER.ID,
                        To      = bob.User.ID,
                        Status  = true,
                        Object  = comment.Comment,
                        Object2 = false
                    };
                    socketSendToUser = new Libraries.Socket()
                    {
                        From    = bob.User.ID,
                        To      = ChatRoom.ChatRoom.Users_ID,
                        Status  = true,
                        Object  = comment.Comment,
                        Object2 = true
                    };
                }



                MainViewVM.socket.Emit("chatroom_COMMENT:send", JsonConvert.SerializeObject(socketSendToUser));
                MainViewVM.socket.Emit("chatroom_COMMENT:send", JsonConvert.SerializeObject(socketSendToBob));

                this.ChatComment = "";
                RaiseAll();
            }
            return(res.Success);
        }
        private async Task<Boolean> AddComment_task()
        {
            ChatComment comment = new ChatComment()
            {
                ChatRooms_ID= MainViewVM.ChatRoom.ID,
                Comment=this.ChatComment
            };
            Response res = await ChatRoomRepository.PostChatComment(comment);
            if (res.Success == true)
            {

                int bobID=ChatRoom.ChatRoom.Bobs_ID;
                Bob.All bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(bobID)).Result;
                int userID = ChatRoom.ChatRoom.Users_ID;
                Libraries.Socket socketSendToBob;
                Libraries.Socket socketSendToUser;

                if (MainViewVM.USER.IsBob==false)
                {
                    socketSendToBob = new Libraries.Socket()
                    {
                        From = MainViewVM.USER.ID,
                        To = bob.User.ID,
                        Status = true,
                        Object = comment.Comment,
                        Object2 = true
                    };
                    socketSendToUser = new Libraries.Socket()
                    {
                        From = bob.User.ID,
                        To = ChatRoom.ChatRoom.Users_ID,
                        Status = true,
                        Object = comment.Comment,
                        Object2=false
                    };
                }
                else
                {
                    socketSendToBob = new Libraries.Socket()
                    {
                        From = MainViewVM.USER.ID,
                        To = bob.User.ID,
                        Status = true,
                        Object = comment.Comment,
                        Object2 = false
                    };
                    socketSendToUser = new Libraries.Socket()
                    {
                        From = bob.User.ID,
                        To = ChatRoom.ChatRoom.Users_ID,
                        Status = true,
                        Object = comment.Comment,
                        Object2 = true
                    };
                }

              
                

                MainViewVM.socket.Emit("chatroom_COMMENT:send", JsonConvert.SerializeObject(socketSendToUser));
                MainViewVM.socket.Emit("chatroom_COMMENT:send", JsonConvert.SerializeObject(socketSendToBob));

                this.ChatComment = "";
                RaiseAll();
               
            }
            return res.Success;
        }
        private async Task GetCurrentTrip()
        {
           

            if (MainViewVM.CurrentTrip == null ||MainViewVM.CurrentTrip.ID == 0)
            {
                try
                {
                    string json = await Localdata.read("trip.json");
                    if (json != null && json !="")
                    {
                        var data = JsonConvert.DeserializeObject<Trip>(json);
                        if (data.ID != -1)
                        {
                            this.Loading = true;
                            RaiseAll();

                            SetStatus(data.StatusID.Value);
                            MainViewVM.CurrentTrip = data;

                            if (data.StatusID.Value== 5)
                            {
                                Bobs_Parties bobs_parties = new Bobs_Parties()
                                {
                                    Bobs_ID = MainViewVM.CurrentTrip.Bobs_ID,
                                    Party_ID = MainViewVM.CurrentTrip.Party_ID,
                                    Trips_ID = MainViewVM.CurrentTrip.ID,
                                    Users_ID = MainViewVM.CurrentTrip.Users_ID

                                };

                                Libraries.Socket socketSendToUser = new Libraries.Socket()
                                {
                                    From = MainViewVM.USER.ID,
                                    To = MainViewVM.CurrentTrip.Users_ID,
                                    Status = true,
                                    Object = JsonConvert.SerializeObject(bobs_parties),
                                    Object2 = true
                                };
                                MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToUser));
                            }
                           

                            Location location = await LocationService.GetCurrent();
                            Users_Destinations destination = Task.FromResult<Users_Destinations>(await DestinationRepository.GetDestinationById(MainViewVM.CurrentTrip.Destinations_ID)).Result;
                            Bob.All bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(MainViewVM.CurrentTrip.Bobs_ID)).Result;
                            Party party = Task.FromResult<Party>(await PartyRepository.GetPartyById(MainViewVM.CurrentTrip.Party_ID)).Result;
                            VindRitVM.SelectedBob = bob;
                            VindRitVM.SelectedParty = party;

                            if (bobTypes != null)
                            {
                                VindRitFilterVM.SelectedBobsType = bobTypes.Where(r => r.ID == bob.Bob.BobsType_ID).First();
                            }
                            VindRitFilterVM.SelectedDestination = destination;

                            if (MainViewVM.CurrentTrip.StatusID.HasValue)
                            {
                                if (MainViewVM.CurrentTrip.StatusID == 2 || MainViewVM.CurrentTrip.StatusID == 8)
                                {
                                    ShowRoute((Location)VindRitVM.SelectedParty.Location, (Location)VindRitFilterVM.SelectedDestination.Location);
                                }
                                else
                                {
                                    ShowRoute(location, (Location)VindRitFilterVM.SelectedDestination.Location);
                                }
                            }

                            

                            ShowedOnParty = true;
                            this.EnableFind = false;
                            this.Loading = false;
                            RaiseAll();
                            return;
                        }
                    }

                    SetStatus(0);
                    ShowedOnParty = true;
                    this.EnableFind = true;



                }
                catch (Exception ex)
                {
                    SetStatus(0);
                    ShowedOnParty = true;
                    this.EnableFind = true;
                   
                }
            }
            else
            {
                this.Loading = true;
                RaiseAll();

                MainViewVM.CurrentTrip = Task.FromResult<Trip>(await TripRepository.GetCurrentTrip()).Result;

                if (MainViewVM.CurrentTrip.StatusID.Value == 5)
                {
                    Bobs_Parties bobs_parties = new Bobs_Parties()
                    {
                        Bobs_ID = MainViewVM.CurrentTrip.Bobs_ID,
                        Party_ID = MainViewVM.CurrentTrip.Party_ID,
                        Trips_ID = MainViewVM.CurrentTrip.ID,
                        Users_ID = MainViewVM.CurrentTrip.Users_ID

                    };

                    Libraries.Socket socketSendToUser = new Libraries.Socket()
                    {
                        From = MainViewVM.USER.ID,
                        To = MainViewVM.CurrentTrip.Users_ID,
                        Status = true,
                        Object = JsonConvert.SerializeObject(bobs_parties),
                        Object2 = true
                    };
                    MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToUser));
                }

                Location location = await LocationService.GetCurrent();
                Users_Destinations destination = Task.FromResult<Users_Destinations>(await DestinationRepository.GetDestinationById(MainViewVM.CurrentTrip.Destinations_ID)).Result;
                Bob.All bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(MainViewVM.CurrentTrip.Bobs_ID)).Result;
                Party party = Task.FromResult<Party>(await  PartyRepository.GetPartyById(MainViewVM.CurrentTrip.Party_ID)).Result;
                VindRitVM.SelectedBob = bob;
                VindRitVM.SelectedParty = party;

                if (bobTypes != null)
                {
                    VindRitFilterVM.SelectedBobsType = bobTypes.Where(r => r.ID == bob.Bob.BobsType_ID).First();
                }
                VindRitFilterVM.SelectedDestination = destination;


               

                ShowedOnParty = true;

                if (MainViewVM.CurrentTrip.StatusID.HasValue)
                {
                    if (MainViewVM.CurrentTrip.StatusID == 2 || MainViewVM.CurrentTrip.StatusID == 8)
                    {
                        ShowRoute((Location)VindRitVM.SelectedParty.Location, (Location)VindRitFilterVM.SelectedDestination.Location);
                    }
                    else
                    {
                        ShowRoute(location, (Location)VindRitFilterVM.SelectedDestination.Location);
                    }

                    SetStatus(MainViewVM.CurrentTrip.StatusID.Value);
                }

                this.EnableFind = false;
                this.Loading = false;
               

            }
            RaiseAll();




        }
        private async void BobisDone(string text)
        {
            this.Map.MapElements.Clear();
            ClearAllMapItems();

            Response active = Task.FromResult<Response>(await TripRepository.PutActive(MainViewVM.CurrentTrip.ID, false)).Result;

            if (active.Success == true)
            {
                Bob.All bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(MainViewVM.CurrentTrip.Bobs_ID)).Result;

                Libraries.Socket socketSendToBob = new Libraries.Socket() {
                    To = bob.User.ID,
                    Status = true
                };
                Libraries.Socket socketSendToUser = new Libraries.Socket()
                {
                    To = MainViewVM.USER.ID,
                    Status = true
                };


                //todo: rating
                await UserRepository.PostPoint();
                   

                MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToUser));
                MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToBob));


                var dialog = new MessageDialog(text);
                dialog.Commands.Add(new UICommand("Ok") { Id = 0 });
                dialog.DefaultCommandIndex = 0;
                var result = await dialog.ShowAsync();
                int id = int.Parse(result.Id.ToString());

                this.EnableFind = true;
                this.VisibleSelectedFriends = Visibility.Collapsed;
                this.VisibleSelectedBob = Visibility.Collapsed;
                this.VisibleSelectedBobsType = Visibility.Collapsed;
                this.VisibleSelectedRating = Visibility.Collapsed;
                this.VisibleSelectedParty = Visibility.Collapsed;
                ShowedOnParty = false;

                this.VisibleCancel = Visibility.Collapsed;
                this.VisibleFind = Visibility.Visible;
                this.Loading = false;
                this.Status = null;
                   
                SetStatus(0);

                  

                canShowDialog = true;
                RaiseAll();
               

            }
        }
        private async void find_bob(bool ok)
        {
            if (ok == false)
            {
                this.Loading = false;
               

                RaiseAll();
                if (bobs != null)
                {
                    try
                    {
                        bobs.Remove(bobs.First());

                        if (bobs.Count == 0)
                        {
                            Messenger.Default.Send<Dialog>(new Dialog()
                            {
                                Message = "Geen bob gevonden",
                                Ok = "Ok",
                                Nok = null,
                                ViewOk = null,
                                ViewNok = null,
                                ParamView = false,
                                Cb = null
                            });
                            this.VisibleFind = Visibility.Visible;
                            this.VisibleCancel = Visibility.Collapsed;
                            RaiseAll();
                        }
                        else
                        {
                            ShowBob(bobs.First());
                        }
                    }
                    catch (Exception ex )
                    {

                        Debug.WriteLine(ex.Message.ToString());
                    }
                    
                }
                else
                {

                    Messenger.Default.Send<Dialog>(new Dialog()
                    {
                        Message = "Geen bob gevonden",
                        Ok = "Ok",
                        Nok = null,
                        ViewOk = null,
                        ViewNok = null,
                        ParamView = false,
                        Cb = null
                    });
                    this.VisibleFind = Visibility.Visible;
                    this.VisibleCancel = Visibility.Collapsed;
                    RaiseAll();
                }
               
              
            }
            else
            {
                //take this bob
                if (bobs != null)
                {
                    await UserRepository.PostPoint();

                    Random random = new Random();
                    float randomNumber = random.Next(0, 1000);
                    VindRitVM.FindID = randomNumber;

                    Bob bob = bobs.First();

                    Bob.All bobAll = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(bob.ID.Value)).Result;
                    VindRitVM.SelectedBob = bobAll;

                    Libraries.Socket socketSend = new Libraries.Socket() { From = MainViewVM.USER.ID, To = bobAll.User.ID, Status = true, ID=randomNumber };
                    MainViewVM.socket.Emit("bob_ACCEPT:send", JsonConvert.SerializeObject(socketSend));

                    ShowRoute((Location)VindRitVM.SelectedParty.Location, (Location)VindRitFilterVM.SelectedDestination.Location);

                    SetStatus(6);
                    this.VisibleSelectedBob = Visibility.Visible;
                    ShowedOnParty = false;
                    this.Loading = true;
                    RaiseAll();
                }


            }
        }
        private async void RatingDialog(Bobs_Parties item)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
            {

                var dialog = new ContentDialog()
                {
                    Title = "Rating",
                };

                // Setup Content
                var panel = new StackPanel();

                panel.Children.Add(new TextBlock
                {
                    Text = "Uw rit is ten einde, hoeveel rating wilt u deze bob geven? ",
                    TextWrapping = TextWrapping.Wrap,
                    Margin = new Thickness(0, 0, 0, 15)
                });

                List<string> items = new List<string>();
                for (int i = 1; i < 5; i++)
                {
                    items.Add(i.ToString());
                }
                var cb = new ComboBox
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };
                cb.ItemsSource = items;

                var txt = new TextBox
                {
                    TextWrapping = TextWrapping.Wrap,
                    HorizontalContentAlignment = HorizontalAlignment.Stretch
                };



                panel.Children.Add(cb);
                panel.Children.Add(txt);
                dialog.Content = panel;

                // Add Buttons
                dialog.PrimaryButtonText = "Ok";
                dialog.PrimaryButtonClick += async delegate
                {
                    double rating;
                    string text = cb.SelectedValue.ToString();
                    string comment = txt.Text;

                    double.TryParse(text, out rating);


                    item.Rating = rating;

                    Response res = await TripRepository.AddRating(item);
                    var ok = res.Success;

                    if (ok == true || ok == false)
                    {
                        Libraries.Socket socketSendToUser = new Libraries.Socket()
                        {
                            To = MainViewVM.USER.ID,
                            Status = true,
                        };

                        MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToUser));
                        
                        this.Map.MapElements.Clear();
                    }

                       
                 

                };



                // Show Dialog
                var result = await dialog.ShowAsync();
                if (result == ContentDialogResult.None)
                {

                }
            });
        }
        private async void CancelTrip()
        {
            if (timer != null)
            {
                timer.Stop();
            }

            SetStatus(5);


            Bob.All bob = Task.FromResult<Bob.All>(await BobsRepository.GetBobById(MainViewVM.CurrentTrip.Bobs_ID)).Result;
            Libraries.Socket socketSend = new Libraries.Socket() { From = MainViewVM.USER.ID, To = bob.User.ID, Status = true };
            MainViewVM.socket.Emit("trip_UPDATE:send", JsonConvert.SerializeObject(socketSend));

            BobisDone("Trip is geannuleerd");



            this.IsEnabledOffer = true;
            this.VisibleCancel = Visibility.Collapsed;
            this.VisibleOffer = Visibility.Collapsed;
            VindRitBobVM.Request -= 1;
            this.Loading = false;
            this.Status = null;
            SetStatus(0);

            RaiseAll();


        }
        private async void BobisDone(string text)
        {
            this.Map.MapElements.Clear();
            ClearAllMapItems();

            Bobs_Parties bobs_parties = new Bobs_Parties()
            {
                Bobs_ID = MainViewVM.CurrentTrip.Bobs_ID,
                Party_ID = MainViewVM.CurrentTrip.Party_ID,
                Trips_ID = MainViewVM.CurrentTrip.ID,
                Users_ID = MainViewVM.CurrentTrip.Users_ID

            };


            Response active = Task.FromResult<Response>(await TripRepository.PutActive(MainViewVM.CurrentTrip.ID, false)).Result;

            if (active.Success == true)
            {

                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From = MainViewVM.CurrentTrip.Users_ID,
                    To = MainViewVM.USER.ID,
                    Status = true,
                    Object = JsonConvert.SerializeObject(bobs_parties),
                    Object2 = false

                };
                Libraries.Socket socketSendToUser = new Libraries.Socket()
                {
                    From = MainViewVM.USER.ID,
                    To = MainViewVM.CurrentTrip.Users_ID,
                    Status = true,
                    Object = JsonConvert.SerializeObject(bobs_parties),
                    Object2 = true
                };

                await UserRepository.PostPoint();

                this.Map.MapElements.Clear();

                MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToUser));
                MainViewVM.socket.Emit("trip_DONE:send", JsonConvert.SerializeObject(socketSendToBob));


                var dialog = new MessageDialog(text);
                dialog.Commands.Add(new UICommand("Ok") { Id = 0 });
                dialog.DefaultCommandIndex = 0;
                var result = await dialog.ShowAsync();
                int id = int.Parse(result.Id.ToString());

                this.IsEnabledArrived = true;
                this.IsEnabledCancel = true;

                this.IsEnabledOffer = true;
                this.VisibleCancel = Visibility.Collapsed;
                this.VisibleOffer = Visibility.Collapsed;
                VindRitBobVM.Request -= 1;
                this.Loading = false;
                this.Status = null;
                SetStatus(0);




                canShowDialog = true;
                RaiseAll();


            }
        }
        private async void SetStatus(int statusID)
        {
            VindRitVM.StatusID = statusID;
            this.Status = GetStatusName(statusID);
            RaiseAll();

            if (MainViewVM.CurrentTrip != null)
            {
                if (LocationService.LastLocation != null && statusID!=0)
                {
                    Trips_Locations item = new Trips_Locations()
                    {
                        Trips_ID = MainViewVM.CurrentTrip.ID,
                        Location = JsonConvert.SerializeObject(LocationService.LastLocation),
                        Statuses_ID = VindRitVM.StatusID
                    };
                    Response ok = Task.FromResult<Response>(await TripRepository.PostLocation(item)).Result;

                    if (ok.Success == true)
                    {
                        Libraries.Socket socketSend = new Libraries.Socket()
                        {
                            From = MainViewVM.USER.ID,//from bob
                            To = MainViewVM.CurrentTrip.Users_ID,//to user
                            Status = true,
                            ID = VindRitBobVM.FindID
                        };

                        if (MainViewVM.socket != null)
                        {
                            MainViewVM.socket.Emit("status_UPDATE:send", JsonConvert.SerializeObject(socketSend));
                        }
                        
                    }
                }
               


                var party = Task.FromResult<Party>(await PartyRepository.GetPartyById(MainViewVM.CurrentTrip.Party_ID)).Result;
                var destination = Task.FromResult<Users_Destinations>(await DestinationRepository.GetDestinationById(MainViewVM.CurrentTrip.Destinations_ID)).Result;

                Toast.Tile("Party: " + party.Name, "Bestemming: " + destination.Name, "Status " + this.Status);

            }

            RaiseAll();
        }
        private async void bob_accepted(bool accepted, float id)
        {

            VindRitBobVM.FindID = id;
            this.Loading = false;
            RaiseAll();

            if (accepted == true)
            {
                SetStatus(1);

                //verstuur trip
                User.All user = Task.FromResult<User.All>(await UsersRepository.GetUserById(VindRitVM.SelectedUser.ID)).Result;
                Libraries.Socket socketSend = new Libraries.Socket()
                {
                    From = MainViewVM.USER.ID,//from bob
                    To = user.User.ID,//to user
                    Status = true,
                    Object = user,
                    ID = id
                };
               

                MainViewVM.socket.Emit("trip_MAKE:send", JsonConvert.SerializeObject(socketSend));
                this.Loading = true;
                RaiseAll();
            }

        }
        private void StartSocket()
        {


            //to bob
            MainViewVM.socket.On("bob_ACCEPT", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    MainViewVM.LatestSocket = _socket;
                    VindRitBobVM.Request = VindRitBobVM.Request + 1;

                    Bob_Accept(_socket.From, _socket.ID);

                }

            });

            MainViewVM.socket.On("disconnect", (msg) =>
            {
                LogOff();
            });
            //not implemented
            MainViewVM.socket.On("user_location_NEW", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {

                    Messenger.Default.Send<NavigateTo>(new NavigateTo()
                    {
                        Name = "map_reload",
                    });

                }

            });
            //to bob
            MainViewVM.socket.On("trip_START", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {

                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    Trip currentTrip = JsonConvert.DeserializeObject<Trip>(_socket.Object.ToString());

                    TripSave(currentTrip);

                }

            });
            //to bob
            MainViewVM.socket.On("trip_DONE", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    if (fromUser != null)
                    {
                        if (fromUser.User.IsBob.Value == true && (bool)_socket.Object2 == true)
                        {
                            Messenger.Default.Send<NavigateTo>(new NavigateTo()
                            {
                                Name = "rating_dialog",
                                View = typeof(VindRit),
                                Data = _socket.Object
                            });

                        }
                        else
                        {
                            TripDone();
                        }
                    }
                    else
                    {
                        TripDone();
                    }

                }

            });
            //to bob and user
            MainViewVM.socket.On("friend_REQUEST", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    FriendRequest(fromUser);
                }

            });
            MainViewVM.socket.On("friend_ADDED", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send<Dialog>(new Dialog()
                    {
                        Message = fromUser.User.ToString() + " heeft u vriendschapsverzoek geaccepteerd",
                        ViewOk=typeof(ZoekVrienden)
                    });
                }

            });



            MainViewVM.socket.On("status_UPDATE", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {
                        Messenger.Default.Send<NavigateTo>(new NavigateTo()
                        {
                            Name = "get_trip",
                            View = typeof(VindRit)
                        });


                    }
                }

            });

            //to user
            MainViewVM.socket.On("trip_MAKE", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {

                        User.All fromBob = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                        User.All user = JsonConvert.DeserializeObject<User.All>(_socket.Object.ToString());
                        Trip newTrip = (Trip)GetTripObject();

                        if (newTrip != null)
                        {
                            MakeTrip(newTrip, fromBob.Bob.ID.Value);
                        }

                    }
                }

            });
            //to bob and user
            MainViewVM.socket.On("chatroom_OPEN", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add

                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    int bobsID = JsonConvert.DeserializeObject<int>(_socket.Object.ToString());


                    OpenChatroom(bobsID);


                }
            });

            MainViewVM.socket.On("chatroom_COMMENT", async (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject<Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult<User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send<NavigateTo>(new NavigateTo()
                    {
                        Name = "newComment"
                    });


                    if ((bool)_socket.Object2 == true && fromUser != null)
                    {
                        Messenger.Default.Send<Dialog>(new Dialog()
                        {
                            Message = fromUser.User.ToString() + " zegt: " + _socket.Object.ToString(),
                            Ok = "Antwoord",
                            Nok = "Negeer",
                            ViewOk = typeof(VindRitChat),
                            ViewNok = null,
                            ParamView = false,
                            Cb = null,
                            IsNotification = true
                        });
                    }
                }



            });
        }
        private async void MakeChatroom(int bobs_ID)
        {
            Response res = Task.FromResult<Response>(await ChatRoomRepository.PostChatRoom(bobs_ID)).Result;

            if (res.Success == true)
            {
                VindRitChatVM.ID = res.NewID.Value;

                Bob.All bob = VindRitVM.SelectedBob;
                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From = MainViewVM.USER.ID,//from user
                    To = bob.User.ID,//to bob
                    Status = true,
                    Object = res.NewID.Value
                };

                Libraries.Socket socketSendToUser = new Libraries.Socket()
                {
                    From = bob.User.ID,//from bob
                    To = MainViewVM.USER.ID,//to user
                    Status = true,
                    Object = res.NewID.Value
                };


                MainViewVM.socket.Emit("chatroom_OPEN:send", JsonConvert.SerializeObject(socketSendToBob)); //bob
                MainViewVM.socket.Emit("chatroom_OPEN:send", JsonConvert.SerializeObject(socketSendToUser)); //bob
            }

        }
        //by user
        //wanneer bob accepteer, wordt door gebruiker die aanvraagd aangemaakt
        private async void MakeTrip(Trip trip, int bobID)
        {
            Response res = Task.FromResult<Response>(await TripRepository.PostTrip(trip)).Result;

            if (res.Success == true)
            {
                VindRitVM.StatusID = 1;
                Location location = await LocationService.GetCurrent();
                Trips_Locations tripL = new Trips_Locations()
                {
                    Trips_ID = res.NewID.Value,
                    Location = JsonConvert.SerializeObject(location),
                    Statuses_ID = VindRitVM.StatusID
                };

                Response okTripL = await TripRepository.PostLocation(tripL);


                Trip currentTrip = Task.FromResult<Trip>(await TripRepository.GetCurrentTrip()).Result;


                Bob.All bob = VindRitVM.SelectedBob;
                Libraries.Socket socketSendToBob = new Libraries.Socket()
                {
                    From = MainViewVM.USER.ID,//from user
                    To = bob.User.ID,//to bob
                    Status = true,
                    Object = currentTrip
                };


                MainViewVM.socket.Emit("trip_START:send", JsonConvert.SerializeObject(socketSendToBob)); //bob
                StartTrip(currentTrip); //user
                TripSave(currentTrip);


                MakeChatroom(bobID);

            }
        }
Example #16
0
        private void StartSocket()
        {
            //to bob
            MainViewVM.socket.On("bob_ACCEPT", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    MainViewVM.LatestSocket = _socket;
                    VindRitBobVM.Request    = VindRitBobVM.Request + 1;

                    Bob_Accept(_socket.From, _socket.ID);
                }
            });

            MainViewVM.socket.On("disconnect", (msg) =>
            {
                LogOff();
            });
            //not implemented
            MainViewVM.socket.On("user_location_NEW", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    Messenger.Default.Send <NavigateTo>(new NavigateTo()
                    {
                        Name = "map_reload",
                    });
                }
            });
            //to bob
            MainViewVM.socket.On("trip_START", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    Trip currentTrip  = JsonConvert.DeserializeObject <Trip>(_socket.Object.ToString());

                    TripSave(currentTrip);
                }
            });
            //to bob
            MainViewVM.socket.On("trip_DONE", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    if (fromUser != null)
                    {
                        if (fromUser.User.IsBob.Value == true && (bool)_socket.Object2 == true)
                        {
                            Messenger.Default.Send <NavigateTo>(new NavigateTo()
                            {
                                Name = "rating_dialog",
                                View = typeof(VindRit),
                                Data = _socket.Object
                            });
                        }
                        else
                        {
                            TripDone();
                        }
                    }
                    else
                    {
                        TripDone();
                    }
                }
            });
            //to bob and user
            MainViewVM.socket.On("friend_REQUEST", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    FriendRequest(fromUser);
                }
            });
            MainViewVM.socket.On("friend_ADDED", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send <Dialog>(new Dialog()
                    {
                        Message = fromUser.User.ToString() + " heeft u vriendschapsverzoek geaccepteerd",
                        ViewOk  = typeof(ZoekVrienden)
                    });
                }
            });



            MainViewVM.socket.On("status_UPDATE", (msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {
                        Messenger.Default.Send <NavigateTo>(new NavigateTo()
                        {
                            Name = "get_trip",
                            View = typeof(VindRit)
                        });
                    }
                }
            });

            //to user
            MainViewVM.socket.On("trip_MAKE", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);

                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //from bob
                    if (VindRitVM.FindID == _socket.ID)
                    {
                        User.All fromBob = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                        User.All user    = JsonConvert.DeserializeObject <User.All>(_socket.Object.ToString());
                        Trip newTrip     = (Trip)GetTripObject();

                        if (newTrip != null)
                        {
                            MakeTrip(newTrip, fromBob.Bob.ID.Value);
                        }
                    }
                }
            });
            //to bob and user
            MainViewVM.socket.On("chatroom_OPEN", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    //friend add

                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;
                    int bobsID        = JsonConvert.DeserializeObject <int>(_socket.Object.ToString());


                    OpenChatroom(bobsID);
                }
            });

            MainViewVM.socket.On("chatroom_COMMENT", async(msg) =>
            {
                Libraries.Socket _socket = JsonConvert.DeserializeObject <Libraries.Socket>((string)msg);
                if (_socket.Status == true && _socket.To == MainViewVM.USER.ID)
                //if (_socket.Status == true)
                {
                    User.All fromUser = Task.FromResult <User.All>(await UsersRepository.GetUserById(_socket.From)).Result;

                    Messenger.Default.Send <NavigateTo>(new NavigateTo()
                    {
                        Name = "newComment"
                    });


                    if ((bool)_socket.Object2 == true && fromUser != null)
                    {
                        Messenger.Default.Send <Dialog>(new Dialog()
                        {
                            Message        = fromUser.User.ToString() + " zegt: " + _socket.Object.ToString(),
                            Ok             = "Antwoord",
                            Nok            = "Negeer",
                            ViewOk         = typeof(VindRitChat),
                            ViewNok        = null,
                            ParamView      = false,
                            Cb             = null,
                            IsNotification = true
                        });
                    }
                }
            });
        }