//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);
            }
        }
Exemple #2
0
        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");
            }
        }