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 static async Task <bool> Remove(RequestViewModel requestViewModel)
        {
            var request = ReturnRequest(requestViewModel);

            try
            {
                var messi = await App.MobileService.GetTable <Message>().Where(m => m.RequestId == request.Id).ToListAsync();

                foreach (var item in messi)
                {
                    await App.MobileService.GetTable <Message>().DeleteAsync(item);
                }
                await App.MobileService.GetTable <Request>().DeleteAsync(request);

                //await App.MobileService.SyncContext.PushAsync();
                await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("ALERT", "Request Deleted", "OK");

                return(true);
            }
            catch (Exception)
            {
                await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("ERROR", "Failed to Delete", "OK");

                return(false);
            }
        }
        public async void UpdateRequests(string _searchFilter = null)
        {
            var req = await RequestViewModel.GetAll();

            if (req != null)
            {
                Requests.Clear();
                if (_searchFilter.Contains("Pending"))
                {
                    foreach (var request in req.Where(s => s.Status.Name.Contains("nostatus")))
                    {
                        Requests.Add(request);
                    }
                }
                else if (!_searchFilter.Contains("All"))
                {
                    foreach (var request in req.Where(s => s.Status.Name.Contains(_searchFilter)))
                    {
                        Requests.Add(request);
                    }
                }
                else
                {
                    foreach (var request in req)
                    {
                        Requests.Add(request);
                    }
                }
            }
        }
Beispiel #4
0
        public RequestDetailsViewModel(RequestViewModel request)
        {
            if (request.DateMade != null)
            {
                DateMade = request.DateMade;
            }
            if (request.DateRequested != null && request.DateRequested != new DateTime())
            {
                DateRequested = request.DateRequested;
            }
            else
            {
                DateRequested = RoundUp(DateTime.Now, TimeSpan.FromMinutes(15));
            }
            ID              = request.Id;
            Duration        = request.Duration;
            ProjectName     = request.ProjectName;
            ProjectDescript = request.ProjectDescript;
            ProjectFilePath = request.ProjectFilePath;
            PersonalUse     = request.PersonalUse;
            Request         = request;
            Status          = request.Status;
            Printer         = request.Printer;
            User            = request.User;

            PrintTimeLabel       = "Print Time: " + DateRequested.ToString();
            SaveOrUpdateCommand  = new SaveOrUpdateCommand(this);
            DeleteCommand        = new DeleteCommand(this);
            PushChatPagesCommand = new PushChatPagesCommand(this);
            FilePickerCommand    = new FilePickerCommand(this);
            SetDateCommand       = new SetDateCommand(this);
        }
        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 <MessageViewModel> GetForeignKeys(MessageViewModel obj)
 {
     if (obj.SenderId != null)
     {
         obj.Sender = await UserViewModel.SearchByID(obj.SenderId);
     }
     if (obj.RequestId != null)
     {
         obj.Request = await RequestViewModel.SearchByID(obj.RequestId);
     }
     return(obj);
 }
        public static async Task <RequestViewModel> SearchProjectNameByUser(RequestViewModel requestViewModel)
        {
            var sortedRequests = (await App.MobileService.GetTable <Request>().Where(r => r.ApplicationUserId == requestViewModel.ApplicationUserId && r.ProjectName.Contains(requestViewModel.ProjectName)).ToListAsync()).FirstOrDefault();

            if (sortedRequests != null)
            {
                return(ReturnRequestViewModel(sortedRequests));
            }
            else
            {
                return(null);
            }
        }
        public async Task RefreshRequests()
        {
            var req = await RequestViewModel.GetAll();

            if (req != null)
            {
                Requests.Clear();
                foreach (var request in req)
                {
                    Requests.Add(request);
                }
            }
        }
Beispiel #9
0
        public async void DeleteData()
        {
            bool answer = await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("ALERT", "Are you sure you would like to delete this request?", "OK", "Cancel");

            if (answer)
            {
                var passed = await RequestViewModel.Remove(Request);

                if (passed)
                {
                    await Xamarin.Forms.Application.Current.MainPage.Navigation.PopAsync();
                }
            }
        }
Beispiel #10
0
        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);
        }
Beispiel #11
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 <int> Update(RequestViewModel requestViewModel)
        {
            var request = ReturnRequest(requestViewModel);
            var test    = await SearchByID(requestViewModel.Id);

            if (test != null)
            {
                await App.MobileService.GetTable <Request>().UpdateAsync(request);

                //await App.MobileService.SyncContext.PushAsync();

                return(1);
            }
            else
            {
                return(0);
            }
        }
 public ChatRoomViewModel(RequestViewModel request = null)
 {
     Messages = new ObservableCollection <MessageViewModel>();
     //When you send a message where the SenderID is equal to the App.LoggedInUser.ID then the message will be blue
     //Messages.Insert(0, new MessageViewModel() { Body = "Hi" });
     //Messages.Insert(0, new MessageViewModel() { Body = "How are you?", Sender = App.LoggedInUser, SenderId = App.LoggedInUser.ID });
     MessageAppearingCommand    = new Command <MessageViewModel>(OnMessageAppearing);
     MessageDisappearingCommand = new Command <MessageViewModel>(OnMessageDisappearing);
     OnSendCommand = new Command(() =>
     {
         SendMessage();
     });
     if (request != null)
     {
         SetMessages(request);
         _request = request;
     }
 }
        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 RequestViewModel ReturnRequestViewModel(Request request)
        {
            var requestViewModel = new RequestViewModel()
            {
                Id                = request.Id,
                PrinterId         = request.PrinterId,
                StatusId          = request.StatusId,
                ApplicationUserId = request.ApplicationUserId,
                DateMade          = request.DateMade,
                DateRequested     = request.DateRequested,
                Duration          = request.Duration,
                ProjectName       = request.ProjectName,
                ProjectDescript   = request.ProjectDescript,
                ProjectFilePath   = request.ProjectFilePath,
                PersonalUse       = request.PersonalUse,
            };

            return(requestViewModel);
        }
        public static async Task Insert(RequestViewModel requestViewModel)
        {
            var     request = ReturnRequest(requestViewModel);
            JObject jo      = new JObject();

            jo.Add("PrinterId", requestViewModel.PrinterId);
            jo.Add("StatusId", requestViewModel.StatusId);
            jo.Add("ApplicationUserId", requestViewModel.ApplicationUserId);
            jo.Add("DateMade", DateTime.Now);
            jo.Add("DateRequested", requestViewModel.DateRequested);
            jo.Add("Duration", requestViewModel.Duration);
            jo.Add("ProjectName", requestViewModel.ProjectName);
            jo.Add("ProjectDescript", requestViewModel.ProjectDescript);
            jo.Add("ProjectFilePath", requestViewModel.ProjectFilePath);
            jo.Add("PersonalUse", requestViewModel.PersonalUse);
            await App.MobileService.GetTable <Request>().InsertAsync(jo);

            //await App.MobileService.SyncContext.PushAsync();
        }
        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);
        }
        public async void SearchRequests(string _searchFilter = null)
        {
            var req = await RequestViewModel.GetAll();

            if (req != null)
            {
                Requests.Clear();
                if (_searchFilter != null)
                {
                    foreach (var request in req.Where(r => r.ProjectName.Contains(_searchFilter) ||
                                                      r.User.First_Name.Contains(_searchFilter)))
                    {
                        Requests.Add(request);
                    }
                }
                else
                {
                    foreach (var request in req)
                    {
                        Requests.Add(request);
                    }
                }
            }
        }
 public async void SetMessages(RequestViewModel request)
 {
     Messages = new ObservableCollection <MessageViewModel>(await MessageViewModel.SearchByUserID(request.ApplicationUserId));
 }