Exemplo n.º 1
0
        public async Task <bool> GetListEmail(int _UserId, int _BoxId)
        {
            try
            {
                List <ProfileEmail> listEmail = new List <ProfileEmail>();
                var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
                listEmail = await this.apiService.GetListByUser <ProfileEmail>(
                    apiSecurity,
                    "/api",
                    "/ProfileEmails",
                    _UserId);

                foreach (ProfileEmail ItemEmail in listEmail)
                {
                    Box_ProfileEmail RelationEmail;
                    RelationEmail = new Box_ProfileEmail
                    {
                        BoxId          = _BoxId,
                        ProfileEmailId = ItemEmail.ProfileEmailId
                    };

                    var response = await this.apiService.Get(
                        apiSecurity,
                        "/api",
                        "/Box_ProfileEmail/GetBox_ProfileEmail",
                        RelationEmail);

                    ItemEmail.Exist = response.IsSuccess;

                    if (ItemEmail.Exist == true)
                    {
                        var foreingProfile = new ForeingProfile
                        {
                            BoxId       = _BoxId,
                            UserId      = ItemEmail.UserId,
                            ProfileName = ItemEmail.Name,
                            value       = ItemEmail.Email,
                            ProfileType = "Email"
                        };
                        //Crear perfil de correo de box local predeterminada
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Insert(foreingProfile);
                        }
                    }
                }
                NotNull1 = true;
                return(NotNull1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                NotNull1 = false;
                return(NotNull1);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> GetListWhatsapp(int _UserId, int _BoxId)
        {
            try
            {
                List <ProfileWhatsapp> listWhatsapp = new List <ProfileWhatsapp>();
                var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
                listWhatsapp = await this.apiService.GetListByUser <ProfileWhatsapp>(
                    apiSecurity,
                    "/api",
                    "/ProfileWhatsapps",
                    _UserId);

                foreach (ProfileWhatsapp ItemWhatsapp in listWhatsapp)
                {
                    Box_ProfileWhatsapp RelationWhatsapp;
                    RelationWhatsapp = new Box_ProfileWhatsapp
                    {
                        BoxId             = _BoxId,
                        ProfileWhatsappId = ItemWhatsapp.ProfileWhatsappId
                    };
                    //apiSecurity = Application.Current.Resources["APISecurity"].ToString();
                    var response = await this.apiService.Get(
                        apiSecurity,
                        "/api",
                        "/Box_ProfileWhatsapp/GetBox_ProfileWhatsapp",
                        RelationWhatsapp);

                    ItemWhatsapp.Exist = response.IsSuccess;
                    if (ItemWhatsapp.Exist == true)
                    {
                        ForeingProfile foreingProfile = new ForeingProfile
                        {
                            BoxId       = _BoxId,
                            UserId      = ItemWhatsapp.UserId,
                            ProfileName = ItemWhatsapp.Name,
                            value       = ItemWhatsapp.Number,
                            ProfileType = "Whatsapp"
                        };
                        //Crear perfil de whatsapp de box local predeterminada
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Insert(foreingProfile);
                        }
                    }
                }
                NotNull4 = true;
                return(NotNull4);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                NotNull4 = false;
                return(NotNull4);
            }
        }
Exemplo n.º 3
0
        public async Task <bool> GetListPhone(int _UserId, int _BoxId)
        {
            try
            {
                List <ProfilePhone> listPhone = new List <ProfilePhone>();
                var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
                listPhone = await this.apiService.GetListByUser <ProfilePhone>(
                    apiSecurity,
                    "/api",
                    "/ProfilePhones",
                    _UserId);

                foreach (ProfilePhone ItemPhone in listPhone)
                {
                    Box_ProfilePhone RelationPhone;
                    RelationPhone = new Box_ProfilePhone
                    {
                        BoxId          = _BoxId,
                        ProfilePhoneId = ItemPhone.ProfilePhoneId
                    };

                    var response = await this.apiService.Get(
                        apiSecurity,
                        "/api",
                        "/Box_ProfilePhone/GetBox_ProfilePhone",
                        RelationPhone);

                    ItemPhone.Exist = response.IsSuccess;
                    if (ItemPhone.Exist == true)
                    {
                        var foreingProfile = new ForeingProfile
                        {
                            BoxId       = _BoxId,
                            UserId      = ItemPhone.UserId,
                            ProfileName = ItemPhone.Name,
                            value       = ItemPhone.Number,
                            ProfileType = "Phone"
                        };
                        //Crear perfil de teléfono de box local predeterminada
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Insert(foreingProfile);
                        }
                    }
                }
                NotNull2 = true;
                return(NotNull2);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                NotNull2 = false;
                return(NotNull2);
            }
        }
Exemplo n.º 4
0
        public async Task <bool> GetListSM(int _UserId, int _BoxId)
        {
            try
            {
                List <ProfileSM> listSM = new List <ProfileSM>();
                var apiSecurity         = Application.Current.Resources["APISecurity"].ToString();

                listSM = await this.apiService.GetListByUser <ProfileSM>(
                    apiSecurity,
                    "/api",
                    "/ProfileSMs",
                    _UserId);

                foreach (ProfileSM ItemSM in listSM)
                {
                    Box_ProfileSM RelationSM;
                    RelationSM = new Box_ProfileSM
                    {
                        BoxId       = _BoxId,
                        ProfileMSId = ItemSM.ProfileMSId
                    };

                    var response = await this.apiService.Get(
                        apiSecurity,
                        "/api",
                        "/Box_ProfileSM/GetBox_ProfileSM",
                        RelationSM);

                    ItemSM.Exist = response.IsSuccess;

                    if (ItemSM.Exist == true)
                    {
                        var profileSM = await this.apiService.GetRS(
                            apiSecurity,
                            "/api",
                            "/RedSocials",
                            ItemSM.RedSocialId);

                        var foreingProfileSM = new ForeingProfile
                        {
                            BoxId       = _BoxId,
                            UserId      = ItemSM.UserId,
                            ProfileName = ItemSM.ProfileName,
                            value       = ItemSM.link,
                            ProfileType = profileSM.Name,
                        };
                        //Crear perfil de redes sociales de box local predeterminada
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Insert(foreingProfileSM);
                        }
                    }
                }
                NotNull3 = true;
                return(NotNull3);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                NotNull3 = false;
                return(NotNull3);
            }
        }
Exemplo n.º 5
0
        private void GoToTestPage()
        {
            /*MainViewModel.GetInstance().Testing = new TestingViewModel();
             * Navigation.PushAsync(new Testing());
             * //await Launcher.OpenAsync(new Uri("https://www.facebook.com/roy.a.mustang"));*/

            //insertar box foranea
            System.Text.StringBuilder sb;
            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;
            int            BoxId  = 44; //44
            int            UserId = 3;  //3

            //Inicializar la box foranea
            foreingBox = new ForeingBox
            {
                BoxId      = BoxId,
                UserId     = UserId,
                Time       = DateTime.Now,
                ImagePath  = MainViewModel.GetInstance().User.ImageFullPath,
                UserTypeId = 1,
                FirstName  = "Rodrigo",
                LastName   = "Rodriguez"
            };

            //Insertar la box foranea
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.Insert(foreingBox);
            }

            string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";
            string queryGetPhones = "select dbo.Boxes.BoxId, dbo.ProfilePhones.ProfilePhoneId, dbo.ProfilePhones.Name, " +
                                    "dbo.ProfilePhones.Number from dbo.Box_ProfilePhone Join dbo.Boxes " +
                                    "on(dbo.Boxes.BoxId = dbo.Box_ProfilePhone.BoxId) " +
                                    "Join dbo.ProfilePhones on(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " +
                                    "where dbo.Boxes.BoxId = " + BoxId;
            string queryGetEmails = "select dbo.Boxes.BoxId, dbo.ProfileEmails.ProfileEmailId, dbo.ProfileEmails.Name, " +
                                    "dbo.ProfileEmails.Email from dbo.Box_ProfileEmail " +
                                    "Join dbo.Boxes on(dbo.Boxes.BoxId = dbo.Box_ProfileEmail.BoxId) " +
                                    "Join dbo.ProfileEmails on(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " +
                                    "where dbo.Boxes.BoxId = " + BoxId;
            string queryGetSMProfiles = "select * from dbo.Box_ProfileSM " +
                                        "join dbo.ProfileSMs on(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " +
                                        "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " +
                                        "where dbo.Box_ProfileSM.BoxId = " + BoxId;
            string queryGetWhatsapp = "select dbo.Boxes.BoxId, dbo.ProfileWhatsapps.ProfileWhatsappId, dbo.ProfileWhatsapps.Name, " +
                                      "dbo.ProfileWhatsapps.Number from dbo.Box_ProfileWhatsapp Join dbo.Boxes " +
                                      "on(dbo.Boxes.BoxId = dbo.Box_ProfileWhatsapp.BoxId) " +
                                      "Join dbo.ProfileWhatsapps on(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " +
                                      "where dbo.Boxes.BoxId =" + BoxId;

            //Recorrer la lista de perfiles para insertarlos
            //Emails
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetEmails);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Email"],
                                ProfileType = "Email"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //PHones
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetPhones);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Number"],
                                ProfileType = "Phone"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //Whatsapp
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetWhatsapp);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["Name"],
                                value       = (string)reader["Number"],
                                ProfileType = "Whatsapp"
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }
            //Social media
            using (SqlConnection connection = new SqlConnection(cadenaConexion))
            {
                sb = new System.Text.StringBuilder();
                sb.Append(queryGetSMProfiles);

                string sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int IdRedSocial = (int)reader["RedSocialId"];
                            var Name        = string.Empty;
                            switch (IdRedSocial)
                            {
                            case 1:
                                Name = "Facebook";
                                break;

                            case 2:
                                Name = "Instagram";
                                break;

                            case 3:
                                Name = "Twitter";
                                break;

                            case 4:
                                Name = "Snapchat";
                                break;

                            case 5:
                                Name = "LinkedIn";
                                break;

                            case 6:
                                Name = "TikTok";
                                break;

                            case 7:
                                Name = "Youtube";
                                break;

                            case 8:
                                Name = "Spotify";
                                break;

                            case 9:
                                Name = "Twitch";
                                break;

                            case 10:
                                Name = "WebPage";
                                break;

                            default:
                                break;
                            }
                            ;
                            foreingProfile = new ForeingProfile
                            {
                                BoxId       = BoxId,
                                UserId      = UserId,
                                ProfileName = (string)reader["ProfileName"],
                                value       = (string)reader["link"],
                                ProfileType = Name
                            };

                            //Insertar la box foranea
                            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                            {
                                connSQLite.Insert(foreingProfile);
                            }
                        }
                    }

                    connection.Close();
                }
            }

            MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
            MainViewModel.GetInstance().ListForeignBox.GetList();
            //Enviar a detalles de la box foranea cuando se inserta
            App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
            //App.Current.MainPage = new Xamarin.Forms.NavigationPage(new Mynfo.Views.ForeingBoxPage(foreingBox, true));
        }
Exemplo n.º 6
0
        public static async void InsertForeignData(int user_id, int box_id)
        {
            ApiService apiService = new ApiService();

            int  user_I      = user_id;
            var  apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            User box_detail  = new User();

            AddViewToUser(user_I);
            box_detail = await apiService.GetUserId(apiSecurity,
                                                    "/api",
                                                    "/Users",
                                                    user_I);

            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.CreateTable <ForeingProfile>();
            }

            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;
            ForeingBox     A          = new ForeingBox();
            ForeingBox     oldForeing = new ForeingBox();;

            //Validar que la box no exista
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = " + box_id + " and ForeingBox.UserRecivedId = " + MainViewModel.GetInstance().User.UserId);
            }

            if (A == null)
            {
                //Inicializar la box foranea
                foreingBox = new ForeingBox
                {
                    BoxId  = box_id,
                    UserId = user_I,
                    //Time = Convert.ToDateTime(nfcData[0].time).ToUniversalTime(),
                    Time          = DateTime.Now,
                    ImagePath     = box_detail.ImagePath,
                    UserTypeId    = box_detail.UserTypeId,
                    FirstName     = box_detail.FirstName,
                    LastName      = box_detail.LastName,
                    Edad          = box_detail.Edad,
                    Ubicacion     = box_detail.Ubicacion,
                    Ocupacion     = box_detail.Ocupacion,
                    Conexiones    = box_detail.Conexiones,
                    UserRecivedId = MainViewModel.GetInstance().User.UserId
                };

                //Insertar la box foranea
                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    connSQLite.Insert(foreingBox);
                }
            }
            else
            {
                using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                {
                    oldForeing = A;
                    connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Conexiones = ? WHERE ForeingBox.UserId = ?", box_detail.Conexiones, box_detail.UserId);
                    connSQLite.ExecuteScalar <ForeingBox>("UPDATE ForeingBox SET Time = ? WHERE ForeingBox.BoxId = ?", DateTime.Now, A.BoxId);
                    A = connSQLite.FindWithQuery <ForeingBox>("select * from ForeingBox where ForeingBox.BoxId = ?", box_id);
                }
                foreingBox = A;
            }
            try
            {
                if (box_id != 0)
                {
                    //using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    //{
                    //    connSQLite.CreateTable<Profile_get>();
                    //}
                    if (A != null)
                    {
                        using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                        {
                            connSQLite.Execute("Delete from ForeingProfile Where ForeingProfile.BoxId = ?", A.BoxId);
                        }
                    }
                    #region ForeignProfiles
                    System.Text.StringBuilder sb;
                    string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    //string cadenaConexion = @"data source=serverappmynfo1.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    //Creación de perfiles locales de box local
                    string queryGetBoxEmail = "select * from dbo.ProfileEmails " +
                                              "join dbo.Box_ProfileEmail on" +
                                              "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " +
                                              "where dbo.Box_ProfileEmail.BoxId = " + box_id;
                    string queryGetBoxPhone = "select * from dbo.ProfilePhones " +
                                              "join dbo.Box_ProfilePhone on" +
                                              "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " +
                                              "where dbo.Box_ProfilePhone.BoxId = " + box_id;
                    string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " +
                                                   "join dbo.Box_ProfileSM on" +
                                                   "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " +
                                                   "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " +
                                                   "where dbo.Box_ProfileSM.BoxId = " + box_id;
                    string queryGetBoxWhatsappProfiles = "select * from dbo.ProfileWhatsapps " +
                                                         "join dbo.Box_ProfileWhatsapp on" +
                                                         "(dbo.ProfileWhatsapps.ProfileWhatsappId = dbo.Box_ProfileWhatsapp.ProfileWhatsappId) " +
                                                         "where dbo.Box_ProfileWhatsapp.BoxId = " + box_id;

                    //Consulta para obtener perfiles email
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxEmail);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["Name"],
                                        value       = (string)reader["Email"],
                                        ProfileType = "Email"
                                    };
                                    //Crear perfil de correo de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles teléfono
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxPhone);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["Name"],
                                        value       = (string)reader["Number"],
                                        ProfileType = "Phone"
                                    };
                                    //Crear perfil de teléfono de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles de redes sociales
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxSMProfiles);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["ProfileName"],
                                        value       = (string)reader["link"],
                                        ProfileType = (string)reader["Name"]
                                    };
                                    //Crear perfil de teléfono de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }
                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles Whatsapp
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxWhatsappProfiles);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["Name"],
                                        value       = (string)reader["Number"],
                                        ProfileType = "Whatsapp"
                                    };
                                    //Crear perfil de Whatsapp de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }
                    #endregion
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        //App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
                        MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(foreingBox);
                        //App.Navigator.PopAsync();
                        if (PopupNavigation.PopupStack.Count != 0)
                        {
                            PopupNavigation.Instance.PopAllAsync();
                        }
                        //PopupNavigation.Instance.PushAsync(new ForeingBoxPage(foreingBox, true));
                        if (A == null)
                        {
                            MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
                        }
                        else
                        {
                            //Box anterior
                            //oldForeing
                            MainViewModel.GetInstance().ListForeignBox.UpdateList(foreingBox.UserId);
                        }
                        PopupNavigation.Instance.PushAsync(new ForeingBoxPage(foreingBox, true));
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 7
0
        public static async void InsertForeignData(string user_id, int box_id)
        {
            ApiService apiService = new ApiService();

            int  user_I      = Convert.ToInt32(user_id);
            var  apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            User box_detail  = new User();

            box_detail = await apiService.GetUserId(apiSecurity,
                                                    "/api",
                                                    "/Users",
                                                    user_I);

            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.CreateTable <ForeingProfile>();
            }

            ForeingBox     foreingBox;
            ForeingProfile foreingProfile;

            //Validar que la box no exista
            //using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            //{
            //    connSQLite.CreateTable<ForeingBox>();
            //}



            //Inicializar la box foranea
            foreingBox = new ForeingBox
            {
                BoxId  = box_id,
                UserId = user_I,
                //Time = Convert.ToDateTime(nfcData[0].time).ToUniversalTime(),
                Time       = DateTime.Now,
                ImagePath  = box_detail.ImagePath,
                UserTypeId = box_detail.UserTypeId,
                FirstName  = box_detail.FirstName,
                LastName   = box_detail.LastName
            };

            //Insertar la box foranea
            using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
            {
                connSQLite.Insert(foreingBox);
            }
            try
            {
                if (box_id != 0)
                {
                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                    {
                        connSQLite.CreateTable <Profile_get>();
                    }


                    System.Text.StringBuilder sb;
                    //string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    string cadenaConexion = @"data source=serverappmynfo.database.windows.net;initial catalog=mynfo;user id=adminmynfo;password=4dmiNFC*Atx2020;Connect Timeout=60";

                    //Creación de perfiles locales de box local
                    string queryGetBoxEmail = "select * from dbo.ProfileEmails " +
                                              "join dbo.Box_ProfileEmail on" +
                                              "(dbo.ProfileEmails.ProfileEmailId = dbo.Box_ProfileEmail.ProfileEmailId) " +
                                              "where dbo.Box_ProfileEmail.BoxId = " + box_id;
                    string queryGetBoxPhone = "select * from dbo.ProfilePhones " +
                                              "join dbo.Box_ProfilePhone on" +
                                              "(dbo.ProfilePhones.ProfilePhoneId = dbo.Box_ProfilePhone.ProfilePhoneId) " +
                                              "where dbo.Box_ProfilePhone.BoxId = " + box_id;
                    string queryGetBoxSMProfiles = "select * from dbo.ProfileSMs " +
                                                   "join dbo.Box_ProfileSM on" +
                                                   "(dbo.ProfileSMs.ProfileMSId = dbo.Box_ProfileSM.ProfileMSId) " +
                                                   "join dbo.RedSocials on(dbo.ProfileSMs.RedSocialId = dbo.RedSocials.RedSocialId) " +
                                                   "where dbo.Box_ProfileSM.BoxId = " + box_id;

                    //Consulta para obtener perfiles email
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxEmail);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["Name"],
                                        value       = (string)reader["Email"],
                                        ProfileType = "Email"
                                    };
                                    //Crear perfil de correo de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles teléfono
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxPhone);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["Name"],
                                        value       = (string)reader["Number"],
                                        ProfileType = "Phone"
                                    };
                                    //Crear perfil de teléfono de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }

                            conn1.Close();
                        }
                    }

                    //Consulta para obtener perfiles de redes sociales
                    using (SqlConnection conn1 = new SqlConnection(cadenaConexion))
                    {
                        sb = new System.Text.StringBuilder();
                        sb.Append(queryGetBoxSMProfiles);

                        string sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, conn1))
                        {
                            conn1.Open();
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    foreingProfile = new ForeingProfile
                                    {
                                        BoxId       = box_id,
                                        UserId      = (int)reader["UserId"],
                                        ProfileName = (string)reader["ProfileName"],
                                        value       = (string)reader["link"],
                                        ProfileType = (string)reader["Name"]
                                    };
                                    //Crear perfil de teléfono de box local predeterminada
                                    using (var connSQLite = new SQLite.SQLiteConnection(App.root_db))
                                    {
                                        connSQLite.Insert(foreingProfile);
                                    }
                                }
                            }
                            conn1.Close();
                        }
                    }
                }
                Device.BeginInvokeOnMainThread(() =>
                {
                    //App.Navigator.PushAsync(new ForeingBoxPage(foreingBox, true));
                    MainViewModel.GetInstance().ForeingBox = new ForeingBoxViewModel(foreingBox, true);
                    Application.Current.MainPage.Navigation.PushModalAsync(new ForeingBoxPage(foreingBox, true));
                    MainViewModel.GetInstance().ListForeignBox.AddList(foreingBox);
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }