public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            
            //if (IsPlayServicesAvailable())
            //{
            //    var intentRegistration = new Intent(this, typeof(RegistrationIntentService));
            //    StartService(intentRegistration);
            //}

            var bounds = UIScreen.MainScreen.Bounds;
            LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Loading events...");
            View.Add(loadingOverlay);

            await RefreshView();

            loadingOverlay.Hide();

            myEventList = recipientListItemAdapter.getEventsByEmployeeID(IoC.UserInfo.EmployeeID, eventItemAdapter);
            myEventList = filterEvents();
            notificationEventList = filterNotificationEvents(myEventList);
            createNotifications();
            sortByDate(myEventList);

            table = new UITableView(View.Bounds); // defaults to Plain style
            table.Source = new RecentEventTableSource(myEventList,this);
            table.ContentInset = new UIEdgeInsets(65, 0, 0, 0);
            Add(table);
            
        }
        private async void deleteEvents(int index)
        {
            var bounds = UIScreen.MainScreen.Bounds;
            LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Creating event...");
            owner.View.Add(loadingOverlay);

            await eventDeleter.deleteEvent(TableItems[index].EventID);

            loadingOverlay.Hide();
            UIAlertView _error = new UIAlertView("Success!", "Event deletion successful!", null, "Ok", null);
            _error.Show();
        }
        public override async void ViewDidAppear(bool animated)
        {
            var bounds = UIScreen.MainScreen.Bounds;
            LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Loading events...");
            View.Add(loadingOverlay);

            await RefreshView();

            loadingOverlay.Hide();

            myEventList = recipientListItemAdapter.getEventsByEmployeeID(IoC.UserInfo.EmployeeID, eventItemAdapter);

            //ThreadStart myThreadDelegate = new ThreadStart(createNotifications);
            //Thread setupNotifications = new Thread(myThreadDelegate);
            // setupNotifications.Start();

            myEventList = filterEvents();
            sortByDate(myEventList);
            base.ViewDidAppear(animated);
            table = new UITableView(View.Bounds); // defaults to Plain style
            table.Source = new RecentEventTableSource(myEventList, this);
            table.ContentInset = new UIEdgeInsets(65, 0, 0, 0);
            Add(table);
        }
        private async Task createEmployee(RootElement info)
        {
            if (!Validate())
            {
                return;
            }

            try
            {

                int EmployeeID = int.Parse(EditTextEmployeeID.Value);
                string fullName = EditTextFirstName.Value + " " + EditTextLastName.Value;
                string Email = EditTextEmail.Value;
                string Department = departments[SpinnerDepartment.Selected];
                string Privledege = privledges[SpinnerPrivledge.Selected];
                bool validID = await validateEmployeeID(EmployeeID);
                if (validID)
                {

                    var bounds = UIScreen.MainScreen.Bounds;
                    LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Creating Employee...");
                    View.Add(loadingOverlay);

                    await IoC.EmployeeFactory.createEmployee(fullName, Email, EmployeeID, Department, Privledege);

                    loadingOverlay.Hide();

                    UIAlertView _message = new UIAlertView("Success!", "Employee creation successful!", null, "Ok", null);
                    _message.Show();
                }
                else
                {
                    UIAlertView _message = new UIAlertView("Invalid EmployeeID", "EmployeeID is already used.", null, "Ok", null);
                    _message.Show();
                }
            }
            catch (MobileServicePushFailedException ex)
            {
                UIAlertView _message = new UIAlertView("Connection Failed", "Internet connection required for Event creation.", null, "Ok", null);
                _message.Show();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

        }
        public async void Login()
        {
            if (!Validate())
            {
                return;
            }

            loginButton.Enabled = false;

            string EmployeeID = EditTextEmployeeID.Text;
            string password = EditTextPassword.Text;

            var bounds = UIScreen.MainScreen.Bounds;
            LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Checking account info...");
            View.Add(loadingOverlay);

            bool authenticated = await AuthenticateUser(EmployeeID, password);
            if (authenticated)
            {
                IoC.UserInfo.EmployeeID = int.Parse(EmployeeID);
                await IoC.UserInfo.setEmployee();
                loadingOverlay.Hide();
                ParentController parent = this.Storyboard.InstantiateViewController("ParentController") as ParentController;
                if (parent != null)
                {
                    PresentViewController(parent, true, null);
                }
            }
            else
            {
                loadingOverlay.Hide();
                UIAlertView _error = new UIAlertView("Login Unsuccessful", "User credentials invalid or not a User", null, "Ok", null);
                _error.Show();
            }
            loginButton.Enabled = true;
        }
        private async Task createEvent(RootElement info)
        {
            string EventName = eventname.Value;
            string Recipients = recipients.Value;
            string Location = location.Value;
            string Category = categories[category.Selected];
            string Priority = priorities[priority.Selected];
            string EventDescription = description.Value;
            string time = timeelement.Value;
            int hours = parseTime(time);

            DateTime EventDateTime = new DateTime(date.DateValue.Year, date.DateValue.Month, date.DateValue.Day, hours, timeelement.DateValue.Minute, 0);
            

            if (string.IsNullOrEmpty(EventName))
            {
                UIAlertView _error = new UIAlertView("Error", "Event name is required", null, "Ok", null);
                _error.Show();
                return;
            }
            else if (EventDateTime == null || time == null)
            {
                UIAlertView _error = new UIAlertView("Error", "Event date and time are required", null, "Ok", null);
                _error.Show();
                return;
            }
            else if (EventDateTime.Date.CompareTo(DateTime.Now.Date) < 0 ||
                     (EventDateTime.Date.CompareTo(DateTime.Now.Date) == 0 && EventDateTime.Hour < DateTime.Now.Hour))
            {
                UIAlertView _error = new UIAlertView("Error", "Event is set to a past date.", null, "Ok", null);
                _error.Show();
                return;
            }
            else
            {
                try
                {
                    var bounds = UIScreen.MainScreen.Bounds;
                    LoadingOverlay loadingOverlay = new LoadingOverlay(bounds, "Creating event...");
                    View.Add(loadingOverlay);
                    await IoC.EventFactory.createEvent(EventName, Recipients, EventDateTime, time, Location, Category, Priority, EventDescription);

                    loadingOverlay.Hide();

                    UIAlertView _error = new UIAlertView("Success!", "Event creation successful!", null, "Ok", null);
                    _error.Show();

                }
                catch (MobileServicePushFailedException ex)
                {
                    UIAlertView _error = new UIAlertView("Connection Failed", "Internet connection required for Event creation.", null, "Ok", null);
                    _error.Show();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
            }

        }