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;
        }
        public static async Task <List <RequestViewModel> > SearchByPrinter(PrinterViewModel printerViewModel)
        {
            List <Request> sortedRequests = (await App.MobileService.GetTable <Request>().Where(sr => sr.PrinterId.Contains(printerViewModel.ID)).ToListAsync());

            if (sortedRequests != null)
            {
                return(ReturnListRequestViewModel(sortedRequests));
            }
            else
            {
                return(null);
            }
        }
        private static PrinterViewModel ReturnPrinterViewModel(Printer printer)
        {
            var printerviewmodel = new PrinterViewModel()
            {
                ID = printer.ID,

                Name           = printer.Name,
                StatusID       = printer.StatusID,
                ColorID        = printer.ColorID,
                ProjectsQueued = printer.ProjectsQueued,
            };

            return(printerviewmodel);
        }
        public static async Task Insert(PrinterViewModel printerViewModel)
        {
            var printer = new Printer()
            {
                ID             = printerViewModel.ID,
                Name           = printerViewModel.Name,
                StatusID       = printerViewModel.StatusID,
                ColorID        = printerViewModel.ColorID,
                ProjectsQueued = printerViewModel.ProjectsQueued,
            };
            await App.MobileService.GetTable <Printer>().InsertAsync(printer);

            //await App.MobileService.SyncContext.PushAsync();
        }
Esempio n. 5
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");
            }
        }
        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);
        }