private async void Next()
        {
            this.IsRunning = true;
            CheckConnectionInternet.checkConnectivity();

            if (string.IsNullOrEmpty(this.Name))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Name.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            if (string.IsNullOrEmpty(this.Last_Name))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Last Name.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            if (string.IsNullOrEmpty(this.Nickname))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Nickname.",
                    "Accept");

                this.IsRunning = false;
                return;
            }
            if (this.Nickname.Length < 4)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "The length of Nickname most be greather than 3 letters.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            var nick = await App.MobileService.GetTable <User>().Where(p => p.Nickname == this.Nickname).ToListAsync();

            if (nick.Count > 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "This nickname has been taken.",
                    "Try Another");

                this.IsRunning = false;
                return;
            }


            if (string.IsNullOrEmpty(this.Phone))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Phone.",
                    "Accept");

                this.IsRunning = false;
                return;
            }
            if (this.Phone.Length < 10)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a Phone with 10 digits.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            if (string.IsNullOrEmpty(this.Address))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Address.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            if (string.IsNullOrEmpty(this.City))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an City.",
                    "Accept");

                return;
            }

            if (string.IsNullOrEmpty(this.State))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an State.",
                    "Accept");

                return;
            }

            if (string.IsNullOrEmpty(this.Zip_Code))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Zip Code.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            if (SelectedGender == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select an Gender.",
                    "Accept");

                this.IsRunning = false;
                return;
            }


            if (SelectedCountry == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select an Country.",
                    "Accept");

                this.IsRunning = false;
                return;
            }


            int len = RandomId.length.Next(5, 10);

            Address newAddress = new Address()
            {
                Id       = RandomId.RandomString(len),
                Phone    = this.Phone.TrimEnd(),
                Address1 = this.Address.TrimEnd(),
                Address2 = string.Empty,
                City     = this.City.TrimEnd(),
                State    = this.State.TrimEnd(),
                Country  = this.SelectedCountry.Name.TrimEnd(),
                Zipcode  = this.Zip_Code.TrimEnd()
            };

            User newUSer = new User()
            {
                Id            = RandomId.RandomString(len),
                Name          = this.Name.TrimEnd(),
                Last_Name     = this.Last_Name.TrimEnd(),
                Nickname      = this.Nickname.TrimEnd(),
                Gender        = this.SelectedGender.Name.Substring(0, 1),
                Birthdate     = this.Birthdate.Date,
                IsAdmin       = false,
                Locked        = false,
                Address_Id_FK = newAddress.Id
            };

            /*
             * try
             * {
             *
             *      await App.MobileService.GetTable<Address>().InsertAsync(newAddress);
             *      await Application.Current.MainPage.DisplayAlert("Exito", "El contacto fue insertado", "Ok");
             *      await Application.Current.MainPage.Navigation.PushAsync(new EndRegisterPage());
             * }
             * catch (Exception ex)
             * {
             *      await Application.Current.MainPage.DisplayAlert("Error ", ex.Message, "Ok");
             * }
             */

            //new EndRegisterViewModel(newAddress);
            //MainViewModel.GetInstance().EndRegister = new EndRegisterViewModel();
            //await Application.Current.MainPage.Navigation.PushAsync(new EndRegisterPage(newAddress, newUSer));

            MainViewModel.GetInstance().EndRegister = new EndRegisterViewModel(newAddress, newUSer);
            await Application.Current.MainPage.Navigation.PushAsync(new EndRegisterPage());

            this.IsRunning = false;
        }
        public async void Assign()
        {
            this.IsRunning = true;

            //SetValue(ref this.selectedActivity, null);
            //LoadActivity();
            var action = await Application.Current.MainPage.DisplayAlert("Sure?", "Are you sure want to add " + SelectedUser.Nickname, "No", "Yes");

            if (!action)            //yess
            {
                var checkFriend = await App.MobileService.GetTable <Friend>().Where(p => p.User_Id_FK1 == user[0].Id &&
                                                                                    p.User_Friend_Id_FK2 == SelectedUser.Requested_By_FK1).ToListAsync();

                if (checkFriend.Count > 0)
                {
                    await Application.Current.MainPage.DisplayAlert("Warning", "You have already be a friend of  " + SelectedUser.Nickname, "ok");

                    return;
                }

                int    len     = RandomId.length.Next(5, 10);
                Friend pending = new Friend
                {
                    Id                 = RandomId.RandomString(len),
                    User_Id_FK1        = user[0].Id,
                    User_Friend_Id_FK2 = SelectedUser.Requested_By_FK1,
                    Type               = 1
                };
                int    nl     = RandomId.length.Next(5, 10);
                Friend friend = new Friend
                {
                    Id                 = RandomId.RandomString(nl),
                    User_Id_FK1        = SelectedUser.Requested_By_FK1,
                    User_Friend_Id_FK2 = user[0].Id,
                    Type               = 1
                };
                try
                {
                    await App.MobileService.GetTable <Friend>().InsertAsync(pending);

                    await App.MobileService.GetTable <Friend>().InsertAsync(friend);

                    await App.MobileService.GetTable <Pending_Friend>().DeleteAsync(SelectedUser);

                    await Application.Current.MainPage.DisplayAlert("Succesfuly!", "DONE!", "ok");

                    LoadPendingFriends();
                    MainViewModel.GetInstance().FriendList = new FriendListViewModel(user);
                    await Application.Current.MainPage.Navigation.PushAsync(new FriendsPage());
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
                }
            }
            else
            {
                try
                {
                    await App.MobileService.GetTable <Pending_Friend>().DeleteAsync(SelectedUser);

                    await Application.Current.MainPage.DisplayAlert("Alert", "You have rejected the request", "ok");

                    LoadPendingFriends();
                    MainViewModel.GetInstance().FriendList = new FriendListViewModel(user);
                    await Application.Current.MainPage.Navigation.PushAsync(new FriendsPage());
                }
                catch (Exception ex)
                {
                }
            }

            this.IsRunning = false;



            // note name is property in my model (say : GeneralDataModel )
        }
Beispiel #3
0
        //public ObservableCollection<Activity_Location> ActivityLocation { get; private set; }


        private async void Quit()
        {
            bool            isNotEntered = true;
            List <User_Log> userLogged;
            User_Log        current  = null;
            int             userQuit = 0;

            var queue = await App.MobileService.GetTable <User_Entered>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id).ToListAsync();

            var userStr = await App.MobileService.GetTable <Entered_History>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id).ToListAsync();

            if (queue.Count > 0)
            {
                for (int i = 0; i < queue.Count; i++)
                {
                    userLogged = await App.MobileService.GetTable <User_Log>().Where(p => p.Id == queue[i].User_Log_Id_FK1 && (p.User_LogType_Id_FK1 == "4" || p.User_LogType_Id_FK1 == "3")).ToListAsync();

                    if (userLogged[0].User_Id_FK2.Equals(userJoining[0].Id))
                    {
                        userQuit = i;
                        current  = new User_Log
                        {
                            Id                  = userLogged[0].Id,
                            LogDateTime         = DateTime.Now,
                            User_Id_FK2         = userLogged[0].User_Id_FK2,
                            Activity_code       = selectedActivity.Id,
                            User_Equipment_code = userLogged[0].User_Equipment_code,
                            User_LogType_Id_FK1 = "5"                             // quit activity
                        };
                        isNotEntered = false;
                    }
                }
            }

            if (!isNotEntered)
            {
                Entered_History entered = null;
                try
                {
                    if (!queue[userQuit].IsCreator)
                    {
                        await App.MobileService.GetTable <User_Log>().UpdateAsync(current);

                        entered = new Entered_History
                        {
                            Id = queue[userQuit].Id,
                            Activity_Code_FK2 = queue[userQuit].Activity_Code_FK2,
                            Status            = "Aborting",
                            IsCreator         = queue[userQuit].IsCreator,
                            UserJoin          = userJoining[0].Id,
                            UserCreator       = userCreatorActivity[0].Id,
                        };
                        await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                        await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[userQuit]);

                        entered = null;
                        await Application.Current.MainPage.DisplayAlert("Success", " You are now out of the activity", "Ok");

                        getFileUserEntry();
                    }
                    else
                    {
                        await App.MobileService.GetTable <User_Log>().UpdateAsync(current);

                        if (queue.Count > 1)
                        {
                            for (int i = 0; i < queue.Count; i++)
                            {
                                entered = new Entered_History
                                {
                                    Id = queue[i].Id,
                                    Activity_Code_FK2 = queue[i].Activity_Code_FK2,
                                    Status            = "Out",
                                    IsCreator         = queue[i].IsCreator,
                                    UserJoin          = userStr[i].UserJoin,
                                    UserCreator       = userCreatorActivity[0].Id,
                                };
                                await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                                await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[i]);

                                entered = null;
                            }
                        }
                        else
                        {
                            entered = new Entered_History
                            {
                                Id = queue[0].Id,
                                Activity_Code_FK2 = queue[0].Activity_Code_FK2,
                                Status            = "Out",
                                IsCreator         = queue[0].IsCreator,
                                UserJoin          = userJoining[0].Id,
                                UserCreator       = userCreatorActivity[0].Id,
                            };
                            await App.MobileService.GetTable <Entered_History>().UpdateAsync(entered);

                            await App.MobileService.GetTable <User_Entered>().DeleteAsync(queue[0]);

                            entered = null;
                        }



                        await App.MobileService.GetTable <Activity>().DeleteAsync(selectedActivity);

                        await Application.Current.MainPage.DisplayAlert("Success", " You are deleted the activity", "Ok");

                        MainViewModel.GetInstance().Activity_Child = new ActivityViewModel(userCreatorActivity);
                        await Application.Current.MainPage.Navigation.PushAsync(new ActivityPage());
                    }
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");

                    return;
                }
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Error", "You are not on the lobby", "Ok");

                return;
            }
            getFileUserEntry();
        }
Beispiel #4
0
        private async void CreateActivity()
        {
            CheckConnectionInternet.checkConnectivity();

            //if ((this.StartDay.Date + this.StartHour) < DateTime.Now)
            //{
            //    await Application.Current.MainPage.DisplayAlert(
            //        "Message",
            //        "Past date is not allowed.",
            //        "Ok");
            //    return;
            //}

            //if (this.StartDay.Date + this.StartHour > this.FinishDay.Date + this.FinishHour)
            //{
            //    await Application.Current.MainPage.DisplayAlert(
            //        "Message",
            //        "The Start Date is greater than Finish Date",
            //        "Ok");
            //    this.FinishDay = this.StartDay;
            //    this.FinishHour = this.StartHour;
            //    return;

            //}
            ValidateDatetime();

            if (string.IsNullOrEmpty(this.ActivityName))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Activity Name.",
                    "Accept");

                return;
            }
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a description.",
                    "Accept");

                return;
            }
            if (SelectedCategory == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Category.",
                    "Accept");

                return;
            }


            if (loc == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Location.",
                    "Accept");

                return;
            }

            if ((this.StartDay.Date + this.StartHour) < DateTime.Now)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Message",
                    "Past date is not allowed.",
                    "Ok");

                this.StartHour = DateTime.Now.TimeOfDay;
                return;
            }


            string[] addrSplit = this.Placename.Split(',');
            for (int i = 0; i < addrSplit.Length; i++)
            {
                addrSplit[i] = addrSplit[i].Trim();
            }
            int len = RandomId.length.Next(5, 10);
            Activity_Location activity_location = new Activity_Location()
            {
                Id        = RandomId.RandomString(len),
                Nameplace = addrSplit[0],
                City      = addrSplit.Length == 5 ? addrSplit[2] : addrSplit[1],
                State     = "PR",//Cambiarlo luego con IF dinamico
                Country   = addrSplit.Length == 5 ? addrSplit[4] : addrSplit[3],
                ZipCode   = addrSplit.Length == 5 ? addrSplit[3] : addrSplit[2],
                IsSecure  = false,
                Latitude  = (decimal)this.loc.Latitude,
                Longitude = (decimal)this.loc.Longitude,
                CreatorOriginalPinLatitude  = (decimal)this.origLoc.Latitude,
                CreatorOriginalPinLongitude = (decimal)this.origLoc.Longitude
            };

            try
            {
                //find duplicate
                var query = await App.MobileService.GetTable <Activity_Location>().Where(
                    p => p.Nameplace == activity_location.Nameplace &&
                    p.City == activity_location.City &&
                    p.ZipCode == activity_location.ZipCode
                    ).ToListAsync();

                if (query.Count == 0)
                {
                    await App.MobileService.GetTable <Activity_Location>().InsertAsync(activity_location);
                }
                else
                {
                    var location = query?.FirstOrDefault();
                    activity_location.Id = location.Id;
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }

            Activity activity = new Activity()
            {
                Id                 = RandomId.RandomString(len),
                Name               = this.ActivityName,
                Created_Date       = DateTime.Now,
                IsPrivate          = false,//todo
                Start_Act_Datetime = this.StartDay.Date + this.StartHour,
                End_Act_Datetime   = this.FinishDay.Date + this.FinishHour,
                Description        = this.Description.TrimEnd().TrimStart(),
                Status             = 1,//check
                IsService          = this.IsService,
                Activity_Cat_Code  = SelectedCategory.Id,
                Activity_Loc_Id    = activity_location.Id
            };

            //ctivity history
            Activity_History activityHistory = new Activity_History()
            {
                Id = RandomId.RandomString(len),
                Activity_Code_Id   = activity.Id,
                Name               = this.ActivityName,
                Created_Date       = DateTime.Now,
                IsPrivate          = false,//todo
                Start_Act_Date     = this.StartDay.Date + this.StartHour,
                End_Act_Date       = this.FinishDay.Date + this.FinishHour,
                Description        = this.Description,
                Status             = 1,//check
                IsService          = this.IsService,
                Activity_Cat_code  = SelectedCategory.Id,
                Activity_Loc_Id_FK = activity_location.Id
            };

            userCreating = User_LogType.userLogTypesAsync(userQuery[0].Id, usLog);
            User_Entered entry = new User_Entered()
            {
                Id                = RandomId.RandomString(len),
                Status            = "in",
                IsCreator         = true,
                User_Log_Id_FK1   = userCreating.Id,
                Activity_Code_FK2 = activityHistory.Activity_Code_Id
            };
            Entered_History entryHistory = new Entered_History()
            {
                Id                = entry.Id,
                Status            = "in",
                IsCreator         = true,
                Activity_Code_FK2 = activityHistory.Activity_Code_Id,
                UserJoin          = userQuery[0].Id,
                UserCreator       = userQuery[0].Id
            };

            try
            {
                await App.MobileService.GetTable <Activity>().InsertAsync(activity);

                await App.MobileService.GetTable <Activity_History>().InsertAsync(activityHistory);

                await App.MobileService.GetTable <User_Log>().InsertAsync(userCreating);

                await App.MobileService.GetTable <User_Entered>().InsertAsync(entry);

                await App.MobileService.GetTable <Entered_History>().InsertAsync(entryHistory);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }

            MainViewModel.GetInstance().Activity_Child = new ActivityViewModel(userQuery, entry);
            await Application.Current.MainPage.Navigation.PushAsync(new ActivityPage());
        }
Beispiel #5
0
        private async void Location()
        {
            CheckConnectionInternet.checkConnectivity();
            if (string.IsNullOrEmpty(this.ActivityName))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Activity Name.",
                    "Accept");

                return;
            }
            if (string.IsNullOrEmpty(this.Description))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a description.",
                    "Accept");

                return;
            }
            if (SelectedCategory == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Category.",
                    "Accept");

                return;
            }

            //Permiso para usar el Mapa y GPS
            var LocationStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            if (LocationStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Location });

                LocationStatus = results[Permission.Location];
            }

            if (LocationStatus != PermissionStatus.Granted)
            {
                await Application.Current.MainPage.DisplayAlert("Permissions Denied", "Unable to choose Location.", "OK");
            }



            Activity act = new Activity()
            {
                Name = this.ActivityName,
                Start_Act_Datetime = this.StartDay + this.StartHour,
                End_Act_Datetime   = this.FinishDay + this.FinishHour,
                Description        = this.Description,
                IsService          = this.IsService,
                Activity_Cat_Code  = SelectedCategory.Id
            };

            MainViewModel.GetInstance().Location = new LocationViewModel(userQuery, userLog, categories, act, this.PickerCatIndex);
            await Application.Current.MainPage.Navigation.PushAsync(new LocationPage());
        }
Beispiel #6
0
        private async void setPassword()
        {
            this.IsRunning = true;

            var passwordQuerry = await App.MobileService.GetTable <User_Password>().Where(p => p.User_Id_FK == userQuery[0].Id).ToListAsync();

            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an Password.",
                    "Accept");

                this.IsRunning = false;
                return;
            }
            if (this.Password.Length < 7)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Your Password length must be greather than 6.",
                    "Accept");

                this.IsRunning = false;
                return;
            }
            if (!(Password.Equals(RePassword)))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Passwords not match.",
                    "Accept");

                this.IsRunning = false;
                return;
            }

            byte[] encryted = System.Text.Encoding.Unicode.GetBytes(Password);
            var    result   = System.Convert.ToBase64String(encryted);


            User_Password password = new User_Password
            {
                Id         = passwordQuerry[0].Id,
                Password   = result,
                User_Id_FK = userQuery[0].Id
            };

            await App.MobileService.GetTable <User_Password>().UpdateAsync(password);

            await Application.Current.MainPage.DisplayAlert(
                "Done",
                "Password has been changed.",
                "Accept");

            this.ThirdButton = false;
            this.IsRunning   = false;

            MainViewModel.GetInstance().Login = new LoginViewModel(this.Email);
            await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
        }