Exemplo n.º 1
0
        private async void sendCode()
        {
            this.IsRunning = true;

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

            token     = RandomId.RandomString(len);
            userQuery = await App.MobileService.GetTable <User>().Where(p => p.Email == Email).ToListAsync();

            if (userQuery.Count > 0)
            {
                try
                {
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                    SmtpServer.Port                  = 587;
                    SmtpServer.Host                  = "smtp.gmail.com";
                    SmtpServer.EnableSsl             = true;
                    SmtpServer.UseDefaultCredentials = false;
                    SmtpServer.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "leones1234");

                    SmtpServer.SendAsync("*****@*****.**", this.Email, "Reset Password", "Copy this token and go back to ActivityMaps!: " + token, "xyz123d");
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
                }


                Reset_Password_Token reset = new Reset_Password_Token
                {
                    Id         = RandomId.RandomString(len),
                    Token      = token,
                    IsUsed     = false,
                    User_Id_FK = userQuery[0].Id
                };
                await App.MobileService.GetTable <Reset_Password_Token>().InsertAsync(reset);

                this.IsRunning = false;
                this.Step2     = true;
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Invalid Email.",
                    "Accept");

                this.IsRunning = false;
                return;
            }
            this.FirstButton = false;
        }
Exemplo n.º 2
0
        private async void fillEquipment()
        {
            int len = RandomId.length.Next(5, 10);

            equipment = new User_Equipment
            {
                Id = RandomId.RandomString(len),
                Phone_Model_Num = CrossDeviceInfo.Current.Platform.ToString(),
                Phone_Name      = CrossDeviceInfo.Current.DeviceName,
                Phone_Version   = CrossDeviceInfo.Current.Version,
                User_Id_FK      = userQuery[0].Id
            };

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

            userLog = new User_Log
            {
                Id                  = RandomId.RandomString(len),
                LogDateTime         = DateTime.Today,
                User_LogType_Id_FK1 = logType,
                User_Equipment_code = equipment.Id,
                User_Id_FK2         = userQuery[0].Id
            };

            try
            {
                await App.MobileService.GetTable <User_Log>().InsertAsync(userLog);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }
        }
        private async void Next()
        {
            this.IsFeedbackRunning = true;
            this.IsFeedbackEnable  = false;
            CheckConnectionInternet.checkConnectivity();

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

                this.IsFeedbackRunning = false;
                this.IsFeedbackEnable  = true;
                return;
            }


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

                this.IsFeedbackRunning = false;
                this.IsFeedbackEnable  = true;
                return;
            }


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

            Feedback feedback = new Feedback()
            {
                Id         = RandomId.RandomString(len),
                Comment    = this.FeedbackDescription.TrimEnd(),
                Rating     = this.SelectedFeedbcakRating.FeedbackName,
                User_Id_FK = user[0].Id
            };

            try
            {
                await App.MobileService.GetTable <Feedback>().InsertAsync(feedback);

                await Application.Current.MainPage.DisplayAlert("Exito", "Done!", "Ok");

                this.IsFeedbackVisible = true;


                //MainViewModel.GetInstance().Feedback = new FeedbackViewModel(user);
                //await Application.Current.MainPage.Navigation.PushAsync(new FeedbackPage());
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error ", ex.Message, "Ok");
            }

            this.IsFeedbackRunning = false;
        }
        //private async void getLocation()
        //{


        //	try
        //	{
        //		CheckConnectionInternet.checkConnectivity();
        //		queryLocation = await App.MobileService.GetTable<Activity_Location>().Where(p => p.Nameplace == SelectedLocation.Nameplace).ToListAsync();
        //		if (queryLocation.Count == 0)
        //		{
        //			await Application.Current.MainPage.DisplayAlert("Warning", "The location was not found ", "Ok");
        //			return;
        //		}


        //		this.LocationNick = queryLocation[0].Nameplace;

        //	}
        //	catch (Exception ex)
        //	{
        //		await Application.Current.MainPage.DisplayAlert("Error ", ex.Message, "Ok");
        //	}

        //}

        public async void sendFeedback()
        {
            this.IsUserRunning = true;
            this.IsUserEnable  = false;
            if (string.IsNullOrEmpty(this.UserNick))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a real User.",
                    "Accept");

                this.IsUserRunning = false;
                this.IsUserEnable  = true;
                return;
            }
            if (string.IsNullOrEmpty(this.Usertxt))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter an User in Search Bar.",
                    "Accept");

                this.IsUserRunning = false;
                this.IsUserEnable  = true;
                return;
            }
            if (string.IsNullOrEmpty(this.UserDescription))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a Description.",
                    "Accept");

                this.IsUserRunning = false;
                this.IsUserEnable  = true;
                return;
            }


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

                this.IsUserRunning = false;
                this.IsUserEnable  = true;
                return;
            }


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

            User_Rating feedback = new User_Rating()
            {
                Id                  = RandomId.RandomString(len),
                Comment             = this.UserDescription.TrimEnd(),
                Rating              = this.SelectedUserRating.FeedbackName,
                User_IdReporter_FK1 = user[0].Id,
                User_IdReported_FK2 = query[0].Id
            };

            try
            {
                await App.MobileService.GetTable <User_Rating>().InsertAsync(feedback);

                await Application.Current.MainPage.DisplayAlert("Exito", "Done!", "Ok");

                this.IsUserVisible = true;
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error ", ex.Message, "Ok");
            }

            this.IsUserRunning = false;
        }
        public async void sendFeedbackLocation()
        {
            this.IsLocationRunning = true;
            this.IsLocationEnable  = false;
            if (string.IsNullOrEmpty(this.LocationNick))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a real Location.",
                    "Accept");

                this.IsLocationRunning = false;
                this.IsLocationEnable  = true;
                return;
            }
            if (SelectedLocation == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must select a Location.",
                    "Accept");

                this.IsLocationRunning = false;
                this.IsLocationEnable  = true;
                return;
            }
            if (string.IsNullOrEmpty(this.LocationDescription))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a Description.",
                    "Accept");

                this.IsLocationRunning = false;
                this.IsLocationEnable  = true;
                return;
            }


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

                this.IsLocationRunning = false;
                this.IsLocationEnable  = true;
                return;
            }


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

            Location_Rating feedback = new Location_Rating()
            {
                Id                 = RandomId.RandomString(len),
                Comment            = this.LocationDescription.TrimEnd(),
                Rating             = this.SelectedLocationRating.FeedbackName,
                User_Id            = user[0].Id,
                Activity_Loc_Id_FK = SelectedLocation.Id
            };

            try
            {
                await App.MobileService.GetTable <Location_Rating>().InsertAsync(feedback);

                await Application.Current.MainPage.DisplayAlert("Exito", "Done!", "Ok");

                this.IsLocationVisible = true;
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error ", ex.Message, "Ok");
            }

            this.IsLocationRunning = false;
        }
Exemplo n.º 6
0
        private async void NextActivityPage()
        {
            CheckConnectionInternet.checkConnectivity();


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

                return;
            }
            if (!IsValid(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must enter a real Email.",
                    "Accept");

                return;
            }

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

            if (checkEmail.Count > 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "This email has been registered.",
                    "Try Another");

                return;
            }

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

                return;
            }

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

                return;
            }

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

                return;
            }

            if (!(Password.Equals(ReEnterPassword)))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Passwords not match.",
                    "Accept");

                return;
            }
            if (!this.isReady)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You must take a picture or select one",
                    "Accept");

                return;
            }

            this.IsRunning = true;

            CurrentUser.Email        = Email;
            CurrentUser.IsActive     = true;
            CurrentUser.Created_Date = DateTime.Now;


            byte[] encryted = System.Text.Encoding.Unicode.GetBytes(Password);
            var    result   = System.Convert.ToBase64String(encryted);
            int    len      = RandomId.length.Next(5, 10);

            User_Password password = new User_Password
            {
                Id         = RandomId.RandomString(len),
                Password   = result,
                User_Id_FK = CurrentUser.Id
            };

            byteData         = AzureStorage.Convert.ToByteArray(source);
            uploadedFilename = await AzureStorage.AzureStorage.UploadFileAsync(AzureStorage.ContainerType.Image, new MemoryStream(byteData));

            string[] arr = source.Split('/');

            File_Path filepath = new File_Path
            {
                Id         = RandomId.RandomString(len),
                Type       = "Image",
                Path       = uploadedFilename,
                Filename   = arr[arr.Length - 1],
                FileUrl    = source,
                Saved_Date = DateTime.Today,
                User_Id_FK = CurrentUser.Id
            };

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

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

            try
            {
                await App.MobileService.GetTable <User_Password>().InsertAsync(password);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }
            try
            {
                await App.MobileService.GetTable <File_Path>().InsertAsync(filepath);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }

            /*
             * //logic azure upload blob
             * string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=lioncode;AccountKey=oY4jZN5nSf4g/4ATkgHIPAgjVRxF3fYS/R1BfhT1k9Li98e7vEYq4/DY4y38LHQ9zjvsvIXI8qEDYQWeeHbxHQ==;EndpointSuffix=core.windows.net";
             * CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
             * CloudBlobClient blobClient = account.CreateCloudBlobClient();
             * CloudBlobContainer blobContainer = blobClient.GetContainerReference("activitymaps");
             * blobContainer.CreateIfNotExists();
             * string sourcePath = this.source;
             * CloudBlockBlob destBlob = blobContainer.GetBlockBlobReference("activitymaps");
             *
             * // Setup the number of the concurrent operations
             * TransferManager.Configurations.ParallelOperations = 64;
             * // Setup the transfer context and track the upload progress
             * SingleTransferContext context = new SingleTransferContext();
             * // Upload a local blob
             * var task = TransferManager.UploadAsync(
             *      sourcePath, destBlob, null, context, CancellationToken.None);
             * task.Wait();
             */



            this.IsRunning = false;

            MainViewModel.GetInstance().Login = new LoginViewModel(CurrentUser.Email);
            await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
        }
Exemplo n.º 7
0
        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 check = await App.MobileService.GetTable <Pending_Friend>().Where(p => p.Requested_By_FK1 == user[0].Id &&
                                                                                      p.Requested_To_FK2 == SelectedUser.Id).ToListAsync();

                if (check.Count > 0)
                {
                    await Application.Current.MainPage.DisplayAlert("Warning", "You have already sent a friend request to  " + SelectedUser.Nickname, "ok");

                    this.Usertxt = "";
                    LoadActivity();
                    return;
                }

                var checkFriend = await App.MobileService.GetTable <Friend>().Where(p => p.User_Id_FK1 == user[0].Id &&
                                                                                    p.User_Friend_Id_FK2 == SelectedUser.Id).ToListAsync();

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

                    this.Usertxt = "";
                    LoadActivity();
                    return;
                }

                int            len     = RandomId.length.Next(5, 10);
                Pending_Friend pending = new Pending_Friend
                {
                    Id = RandomId.RandomString(len),
                    Requested_By_FK1 = user[0].Id,
                    Requested_To_FK2 = SelectedUser.Id,
                    Status           = "Requested"
                };

                try
                {
                    await App.MobileService.GetTable <Pending_Friend>().InsertAsync(pending);

                    await Application.Current.MainPage.DisplayAlert("Succesfuly!", "DONE!", "ok");
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
                }
            }
            else
            {
                this.Usertxt = "";
                LoadActivity();
                return;
            }
            this.IsRunning = false;



            // note name is property in my model (say : GeneralDataModel )
        }
        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;
        }
Exemplo n.º 9
0
        private async void isNotChangePassword(int len)
        {
            var query = await App.MobileService.GetTable <User_Setting>().Where(p => p.User_Id_FK2 == user[0].Id).ToListAsync();

            if (query.Count > 0)
            {
                User_Setting setting = new User_Setting
                {
                    Id               = query[0].Id,
                    AlertSound       = query[0].AlertSound,
                    SendNotification = this.IsNotification,
                    Lang_Id_FK1      = query[0].Lang_Id_FK1,
                    User_Id_FK2      = query[0].User_Id_FK2
                };

                await App.MobileService.GetTable <User_Setting>().UpdateAsync(setting);
            }
            else
            {
                User_Setting setting = new User_Setting
                {
                    Id               = RandomId.RandomString(len),
                    AlertSound       = true,
                    SendNotification = this.IsNotification,
                    Lang_Id_FK1      = "1",
                    User_Id_FK2      = user[0].Id
                };

                await App.MobileService.GetTable <User_Setting>().InsertAsync(setting);
            }

            var fav = await App.MobileService.GetTable <Activity_Preference>().Where(p => p.User_Id_FK == user[0].Id).ToListAsync();

            if (query.Count > 0)
            {
                Activity_Preference act = new Activity_Preference();
                if (this.SelectedCategory == null)
                {
                    act = new Activity_Preference
                    {
                        Id = fav[0].Id,
                        Activity_Cat_code = fav[0].Activity_Cat_code,
                        User_Id_FK        = fav[0].User_Id_FK
                    };
                }
                else
                {
                    act = new Activity_Preference
                    {
                        Id = fav[0].Id,
                        Activity_Cat_code = this.SelectedCategory.Id,
                        User_Id_FK        = fav[0].User_Id_FK
                    };
                }

                await App.MobileService.GetTable <Activity_Preference>().UpdateAsync(act);
            }
            else
            {
                Activity_Preference act = new Activity_Preference
                {
                    Id = RandomId.RandomString(len),
                    Activity_Cat_code = this.SelectedCategory.Id,
                    User_Id_FK        = user[0].Id
                };

                await App.MobileService.GetTable <Activity_Preference>().InsertAsync(act);
            }
        }
        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 )
        }
Exemplo n.º 11
0
        private async void Join()
        {
            var queue = await App.MobileService.GetTable <User_Entered>().Where(p => p.Activity_Code_FK2 == selectedActivity.Id && !p.IsCreator).ToListAsync();

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

                    if (userLogged[0].User_Id_FK2.Equals(userJoining[0].Id))
                    {
                        await Application.Current.MainPage.DisplayAlert(
                            "Error",
                            "You are in the lobby",
                            "Accept");

                        return;
                    }
                }
            }

            int len     = RandomId.length.Next(5, 10);
            var userLog = new User_Log
            {
                Id                  = RandomId.RandomString(len),
                LogDateTime         = DateTime.Today,
                User_LogType_Id_FK1 = logtypeJoin,
                User_Equipment_code = equipment.Id,
                Activity_code       = selectedActivity.Id,
                User_Id_FK2         = userJoining[0].Id
            };
            User_Entered entry = new User_Entered()
            {
                Id                = RandomId.RandomString(len),
                Status            = "in",
                IsCreator         = false,
                User_Log_Id_FK1   = userLog.Id,
                Activity_Code_FK2 = selectedActivity.Id
            };
            Entered_History entryHistory = new Entered_History()
            {
                Id                = entry.Id,
                Status            = "in",
                IsCreator         = false,
                Activity_Code_FK2 = selectedActivity.Id,
                UserJoin          = userJoining[0].Id,
                UserCreator       = userCreatorActivity[0].Id
            };

            if (userJoining[0].Id.Equals(userCreatorActivity[0].Id))
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "You are the Creator!!",
                    "Accept");

                return;
            }

            try
            {
                await App.MobileService.GetTable <User_Log>().InsertAsync(userLog);

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

                await App.MobileService.GetTable <Entered_History>().InsertAsync(entryHistory);

                getFileUserEntry();
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");

                return;
            }
            await Application.Current.MainPage.DisplayAlert("Success", " You are now on the queue", "Ok");
        }
Exemplo n.º 12
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());
        }