public async void SendMessage() { var re = (await RequestViewModel.SearchByUser(App.LoggedInUser.ID)).Count(); if (!string.IsNullOrEmpty(TextToSend) && re > 0) { var messi = new MessageViewModel() { Body = TextToSend, SenderId = App.LoggedInUser.ID, }; Messages.Insert(0, messi); TextToSend = string.Empty; messi.Sender = App.LoggedInUser; messi.Request = (await RequestViewModel.SearchByUser(App.LoggedInUser.ID)).OrderByDescending(r => r.DateMade).FirstOrDefault(); messi.RequestId = messi.Request.Id; messi.TimeSent = new DateTime(DateTime.Now.Ticks, DateTimeKind.Local); var user = await UserViewModel.SearchByID(App.LoggedInUser.ID); user.LatestMessage = DateTime.Now; await UserViewModel.UpdateUser(user); await MessageViewModel.Insert(messi); } else if (re == 0) { await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Alert", "You have not made a request! Go create one to message an admin.", "OK"); } }
public async void UpdateRequestsList() { RefreshList = true; var temp = await RequestViewModel.SearchByUser(App.LoggedInUser.ID); if (temp != null) { requests.Clear(); foreach (var req in temp) { if (req.PrinterId != null) { req.Printer = await PrinterViewModel.SearchByID(req.PrinterId); } if (req.StatusId != null) { req.Status = await StatusViewModel.SearchByID(req.StatusId); } if (req.ApplicationUserId != null) { req.User = await UserViewModel.SearchByID(req.ApplicationUserId); } if (req.Id != null) { req.Messages = await MessageViewModel.SearchByRequestID(req.Id); } requests.Add(req); } } RefreshList = false; }
private static async Task <UserViewModel> GetForeignKeys(UserViewModel userViewModel) { if (userViewModel.ID != null) { userViewModel.Messages = await MessageViewModel.SearchByUserID(userViewModel.ID); var requests = await RequestViewModel.SearchByUser(userViewModel.ID); userViewModel.Requests = requests; } return(userViewModel); }