Пример #1
0
        public static async void ReadBouquetConsist()
        {
            var bouquetConsist = await ProductAPI_Logic.GetBouquetConsist();

            int count = bouquetConsist.Count;

            for (int i = 0; i < count; i++)
            {
                BouquetConsistPost post = new BouquetConsistPost()
                {
                    Id             = bouquetConsist[i].id,
                    Flower_type_id = bouquetConsist[i].flower_type_id,
                    Bouquet_id     = bouquetConsist[i].bouquet_id
                };

                using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                {
                    conn.CreateTable <BouquetConsistPost>();
                    int rows = conn.InsertOrReplace(post);
                    if (rows > 0)
                    {
                        //success++;
                    }
                    else
                    {
                        //fail++;
                    }
                }
            }
            //Tikrinimas ar yra pašalintų įrašų duombazėje
            using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
            {
                conn.CreateTable <BouquetConsistPost>();
                var apiLast  = bouquetConsist.Last().id;
                var apiCount = bouquetConsist.Count;
                var posts    = conn.Table <BouquetConsistPost>().ToList();
                var dbLast   = posts.Last().Id;
                int dbCount  = posts.Count;
                if (apiLast != dbLast && dbCount != apiCount)
                {
                    foreach (var a in posts)
                    {
                        if (!bouquetConsist.Any(n => n.id == a.Id))
                        {
                            conn.Delete <BouquetConsistPost>(a.Id);
                        }
                    }
                }
                conn.Close();
            }
        }
Пример #2
0
        public static async void ReadOccasionTypes()
        {
            var occasionTypes = await ProductAPI_Logic.GetOccasionTypes();

            int count = occasionTypes.Count;

            for (int i = 0; i < count; i++)
            {
                Occasion_TypePost post = new Occasion_TypePost()
                {
                    Id   = occasionTypes[i].id,
                    Name = occasionTypes[i].name
                };

                using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                {
                    conn.CreateTable <Occasion_TypePost>();
                    int rows = conn.InsertOrReplace(post);
                    if (rows > 0)
                    {
                        //success++;
                    }
                    else
                    {
                        //fail++;
                    }
                }
            }
            //Tikrinimas ar yra pašalintų įrašų duombazėje
            using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
            {
                conn.CreateTable <Occasion_TypePost>();
                var apiLast  = occasionTypes.Last().id;
                var apiCount = occasionTypes.Count;
                var posts    = conn.Table <Occasion_TypePost>().ToList();
                var dbLast   = posts.Last().Id;
                int dbCount  = posts.Count;
                if (apiLast != dbLast && dbCount != apiCount)
                {
                    foreach (var a in posts)
                    {
                        if (!occasionTypes.Any(n => n.id == a.Id))
                        {
                            conn.Delete <Occasion_TypePost>(a.Id);
                        }
                    }
                }
                conn.Close();
            }
        }
Пример #3
0
        //---
        public static async void ReadFlowers()
        {
            var flowers = await ProductAPI_Logic.GetFlowers("flowers");

            int count = flowers.Count;

            using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
            {
                for (int i = 0; i < count; i++)
                {
                    conn.CreateTable <FlowerPost>();
                    FlowerPost post = new FlowerPost()
                    {
                        Id             = flowers[i].id,
                        Name           = flowers[i].flower_name,
                        Quantity       = flowers[i].quantity,
                        Price          = flowers[i].price,
                        Description    = flowers[i].description,
                        Discount       = flowers[i].discount,
                        Gender         = flowers[i].gender,
                        Flower_type_id = flowers[i].flower_type_id
                    };
                    try
                    {
                        var imageFromDatabase = conn.Find <FlowerPost>(post.Id);                                            //Nuskaitoma puokste is sqlite
                        post.Favorite = imageFromDatabase.Favorite;
                        if (imageFromDatabase.Image_sh != flowers[i].flower_image_sh || imageFromDatabase.Image_sh == null) // tikrinamas gautas sh is api su turimu db
                        {
                            //nuskaitomas ir priskiriamas naujas paveikslelis bei sh kodas
                            string newImage = await ProductAPI_Logic.GetProductImage(flowers[i].id, "flowers");

                            post.Image_sh = flowers[i].flower_image_sh;
                            post.Image    = newImage;
                        }
                        else
                        {
                            //Paliekamas senas paveikslelis ir sh kodas
                            post.Image_sh = imageFromDatabase.Image_sh;
                            post.Image    = imageFromDatabase.Image;
                        }
                    }
                    catch (NullReferenceException ex)
                    {
                        string newImage = await ProductAPI_Logic.GetProductImage(flowers[i].id, "flowers");

                        post.Image_sh = flowers[i].flower_image_sh;
                        post.Image    = newImage;
                        post.Favorite = false;
                    }

                    conn.CreateTable <FlowerPost>();
                    int rows = conn.InsertOrReplace(post);
                    if (rows > 0)
                    {
                        //success++;
                    }
                    else
                    {
                        //fail++;
                    }
                }
                conn.CreateTable <FlowerPost>();
                var apiLast  = flowers.Last().id;
                var apiCount = flowers.Count;
                var posts    = conn.Table <FlowerPost>().ToList();
                var dbLast   = posts.Last().Id;
                int dbCount  = posts.Count;
                if (apiLast != dbLast && dbCount != apiCount)
                {
                    foreach (var a in posts)
                    {
                        if (!flowers.Any(n => n.id == a.Id))
                        {
                            conn.Delete <FlowerPost>(a.Id);
                        }
                    }
                }
                conn.Close();
            }
        }
Пример #4
0
        public static async void ReadAssignedOccasion()
        {
            var assignedOccasions = await ProductAPI_Logic.GetAssignedOccasions();

            int count = assignedOccasions.Count;

            for (int i = 0; i < count; i++)
            {
                int gelyte    = 0;
                int puokstyte = 0;

                if (assignedOccasions[i].flower_id != null)
                {
                    gelyte = Convert.ToInt32(assignedOccasions[i].flower_id);
                }
                if (assignedOccasions[i].bouquet_id != null)
                {
                    puokstyte = Convert.ToInt32(assignedOccasions[i].bouquet_id);
                }
                AssignedOccasionsPost post = new AssignedOccasionsPost()
                {
                    Id          = assignedOccasions[i].id,
                    Bouquet_id  = puokstyte,
                    Flower_id   = gelyte,
                    Occasion_id = assignedOccasions[i].occasion_id
                };


                using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                {
                    conn.CreateTable <AssignedOccasionsPost>();
                    int rows = conn.InsertOrReplace(post);
                    if (rows > 0)
                    {
                        //success++;
                    }
                    else
                    {
                        //fail++;
                    }
                }
            }
            //Tikrinimas ar yra pašalintų įrašų duombazėje
            using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
            {
                conn.CreateTable <AssignedOccasionsPost>();
                var apiLast  = assignedOccasions.Last().id;
                var apiCount = assignedOccasions.Count;
                var posts    = conn.Table <AssignedOccasionsPost>().ToList();
                var dbLast   = posts.Last().Id;
                int dbCount  = posts.Count;
                if (apiLast != dbLast && dbCount != apiCount)
                {
                    foreach (var a in posts)
                    {
                        if (!assignedOccasions.Any(n => n.id == a.Id))
                        {
                            conn.Delete <AssignedOccasionsPost>(a.Id);
                        }
                    }
                }
                conn.Close();
            }
        }