public static async Task Insert(StatusViewModel statusViewModel) { var status = ReturnStatus(statusViewModel); await App.MobileService.GetTable <Status>().InsertAsync(status); await App.MobileService.SyncContext.PushAsync(); }
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 StatusViewModel ReturnStatusViewModel(Status status) { var statusViewModel = new StatusViewModel() { ID = status.ID, Name = status.Name, }; return(statusViewModel); }
private static Status ReturnStatus(StatusViewModel statusViewModel) { var status = new Status() { ID = statusViewModel.ID, Name = statusViewModel.Name, }; return(status); }
//This function sorts the requests by statusID public static async Task <List <RequestViewModel> > SortByStatus(string searchText = null) { var status = await StatusViewModel.SearchByName(searchText); List <Request> sortedRequests = await App.MobileService.GetTable <Request>().Where(sr => sr.StatusId.Contains(status.ID)).ToListAsync(); if (sortedRequests != null) { return(ReturnListRequestViewModel(sortedRequests)); } else { return(null); } }
public async void SaveData() { var user = await UserViewModel.SearchByEmail(User.Email); var printer = await PrinterViewModel.SearchByName(Printer.Name); var status = new StatusViewModel(); try { status = await StatusViewModel.SearchByName(Status.Name); } catch (NullReferenceException) { status = await StatusViewModel.SearchByName("Pending"); } var request = Request; request.User = user; request.Printer = printer; request.Status = status; request.ApplicationUserId = user.ID; request.PrinterId = printer.ID; request.StatusId = status.ID; var exists = await RequestViewModel.SearchProjectNameByUser(request); if (exists == null && insert == true) { await RequestViewModel.Insert(request); await Xamarin.Forms.Application.Current.MainPage.Navigation.PopAsync(); } else if (!insert) { request.Id = exists.Id; await RequestViewModel.Update(request); await Xamarin.Forms.Application.Current.MainPage.Navigation.PopAsync(); } else if (exists != null && insert == true) { await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("ERROR", "Project Name already Used. Please choose another", "OK"); } else { await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("ERROR", "Could not save details of Request", "OK"); } }
public static async Task <PrinterViewModel> PopulateForeignKeys(PrinterViewModel printer) { if (printer.StatusID != null) { printer.Status = await StatusViewModel.SearchByID(printer.StatusID); } if (printer.ColorID != null) { printer.PrintColor = await PrintColorViewModel.SearchByID(printer.ColorID); } var requests = await RequestViewModel.SearchByPrinter(printer); if (requests != null) { printer.Requests = requests; } return(printer); }
private static async Task <RequestViewModel> GetForeignKeys(RequestViewModel requestViewModel) { if (requestViewModel.PrinterId != null) { requestViewModel.Printer = await PrinterViewModel.SearchByID(requestViewModel.PrinterId); } if (requestViewModel.StatusId != null) { requestViewModel.Status = await StatusViewModel.SearchByID(requestViewModel.StatusId); } if (requestViewModel.ApplicationUserId != null) { requestViewModel.User = await UserViewModel.SearchByID(requestViewModel.ApplicationUserId); } if (requestViewModel.Id != null) { requestViewModel.Messages = await MessageViewModel.SearchByRequestID(requestViewModel.Id); } return(requestViewModel); }