private async Task GetTrips() { bool canRun = true; this.Loading = true; RaisePropertyChanged("Loading"); await Task.Run(async() => { List <Trip> trips = await TripRepository.GetTrips(); trips_all = new List <Trip.All>(); if (trips == null || trips.Count == 0) { this.Error = "Geen trips gevonden"; canRun = false; this.Loading = false; RaiseAll(); return; } var count = trips.Count; if ((trips.Count >= 10) && canRun == true) { count = 10; } for (int i = 0; i < count; i++) { Task <User.All> user = Task.FromResult <User.All>(await UsersRepository.GetUserById(trips[i].Users_ID)); Task <Bob.All> bob = Task.FromResult <Bob.All>(await BobsRepository.GetBobById(trips[i].Bobs_ID)); Task <Users_Destinations> destination = Task.FromResult <Users_Destinations>(await DestinationRepository.GetDestinationById((trips[i].Destinations_ID))); Task <Party> party = Task.FromResult <Party>(await PartyRepository.GetPartyById(trips[i].Party_ID)); Trip.All newTrip = new Trip.All(); newTrip.Trip = trips[i]; newTrip.User = user.Result; newTrip.Bob = bob.Result; newTrip.Party = party.Result; newTrip.Destination = destination.Result; trips_all.Add(newTrip); } this.Trips = trips_all; canRun = false; this.Loading = false; RaiseAll(); }); }
//Methods private async Task GetCurrentTrip() { this.Loading = true; RaisePropertyChanged("Loading"); await Task.Run(async() => { Trip currenttrip = Task.FromResult <Trip>(await TripRepository.GetCurrentTrip()).Result; if (currenttrip != null) { if (currenttrip.Active == true) { Trip.All trips_all = new Trip.All(); User.All user = await UsersRepository.GetUserById(currenttrip.Users_ID); Bob.All bob = await BobsRepository.GetBobById(currenttrip.Bobs_ID); Users_Destinations destination = await DestinationRepository.GetDestinationById((currenttrip.Destinations_ID)); Party party = await PartyRepository.GetPartyById(currenttrip.Party_ID); Trip.All newTrip = new Trip.All(); newTrip.Trip = currenttrip; newTrip.Party = party; newTrip.User = user; newTrip.Bob = bob; newTrip.Destination = destination; MoveCar(newTrip.Trip.Status_Name); this.CurrentTrip = newTrip; } else { this.CurrentTrip = null; //geen current trip nu } } RaiseAll(); }); }
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); }