/// <summary>
        /// Change Password of account
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="newPWD"></param>
        public void ChangePassword(string userName, string newPWD)
        {
            Account ac = db.Accounts.Where(p => p.ac_userName == userName).SingleOrDefault();

            ac.ac_pwd = MyUtil.Encryptor.SHA256_Encrypt(newPWD);
            db.SaveChanges();
        }
예제 #2
0
        /// <summary>
        /// Delete - Inactive Pet
        /// </summary>
        /// <param name="id"></param>
        public void InactivePet(string id)
        {
            Pet p = db.Pets.Where(pet => pet.p_id == id).SingleOrDefault();

            p.p_status = "Inactive";
            db.SaveChanges();
        }
예제 #3
0
        public void SeedCountries(int countriesCount)
        {
            Console.WriteLine("Seeding Countries");

            var randomCountryName = randomGenerator.GetRandomString(5, 50);
            var countriesNames    = db.Countries.Select(d => d.Name).ToList();

            for (int i = 0; i < countriesCount; i++)
            {
                while (countriesNames.Contains(randomCountryName))
                {
                    randomCountryName = randomGenerator.GetRandomString(10, 50);
                }

                countriesNames.Add(randomCountryName);

                var country = new Country()
                {
                    Name = randomCountryName
                };

                db.Countries.Add(country);

                OptimizedDbSave();
            }

            db.SaveChanges();
        }
예제 #4
0
        public static void ImportCategories(int count)
        {
            Console.WriteLine("ImportCategories");
            var categoriesNames = new HashSet <string>();

            do
            {
                categoriesNames.Add(RandomGenerator.RandomString(5, 20));
            }while (categoriesNames.Count < count);

            var data    = new PetStoreEntities();
            var counter = 0;

            foreach (var category in categoriesNames)
            {
                var newcategory = new Category()
                {
                    Name = category
                };

                data.Categories.Add(newcategory);
                counter++;

                if (counter % 100 == 0)
                {
                    data.SaveChanges();
                    data.Dispose();
                    data = new PetStoreEntities();
                    Console.Write(".");
                }
            }

            data.SaveChanges();
            data.Dispose();
        }
예제 #5
0
        public static void GenerateSpecies(PetStoreEntities data, int amount = 100)
        {
            var countries = data.Countries.OrderBy(e => Guid.NewGuid());

            var hash = new HashSet <string>();

            Console.WriteLine("Importing species for each country...");
            foreach (var country in countries)
            {
                // Average of 5, as per Ivaylo's video... or as per Basic Maths
                var numberOfSpecies = RandomGenerator.GetNumber(2, 8);

                for (int i = 0; i < numberOfSpecies; i++)
                {
                    var speciesName = RandomGenerator.GetString(5, 50);

                    if (hash.Contains(speciesName.ToLower()))
                    {
                        i--;
                        continue;
                    }

                    hash.Add(speciesName.ToLower());

                    var species = new Species
                    {
                        Name = speciesName
                    };

                    country.Species.Add(species);
                }
            }

            data.SaveChanges();
        }
예제 #6
0
        public static void Import(PetStoreEntities db, int count)
        {
            var categoriesIds = db.Categories.OrderBy(c => Guid.NewGuid()).Select(c => c.Id).ToList();
            var generator = RandomGenerator.Instance;

            Console.WriteLine("Adding products");

            for (int i = 0; i < count; i++)
            {
                var numberOfSpeciesTheProductIsSuitableFor = generator.GetRandomNumber(2, 10);

                var speciesForCurrentProduct = db.Species.OrderBy(s => Guid.NewGuid()).Take(numberOfSpeciesTheProductIsSuitableFor).ToList();

                db.Products.Add(new Product()
                {
                    Price = generator.GetRandomNumber(10, 1000),
                    Name = generator.GetRandomString(5, 25),
                    CategoryId = categoriesIds[generator.GetRandomNumber(0, categoriesIds.Count - 1)],
                    Species = speciesForCurrentProduct
                });

                if (i % 100 == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new PetStoreEntities();
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    Console.Write(".");
                }
            }

            db.SaveChanges();
        }
예제 #7
0
        public static void Import(PetStoreEntities db, int count)
        {
            var speciesIds = db.Species.OrderBy(s => Guid.NewGuid()).Select(s => s.Id).ToList();
            var generator = RandomGenerator.Instance;
            var colorIds = db.Colors.OrderBy(c => Guid.NewGuid()).Select(c => c.Id).ToList();

            Console.WriteLine("Adding pets");

            for (int i = 0; i < count; i++)
            {
                db.Pets.Add(new Pet()
                {
                    Breed = generator.GetRandomString(5, 30),
                    Price = generator.GetRandomNumber(5, 2500),
                    ColorId = colorIds[generator.GetRandomNumber(0, colorIds.Count - 1)],
                    DateOfBirth = generator.GetRandomDate(new DateTime(2010, 1, 1), DateTime.Now.AddDays(-60)),
                    SpeciesId = speciesIds[generator.GetRandomNumber(0, speciesIds.Count - 1)]
                });

                if (i % 100 == 0)
                {
                    db.SaveChanges();
                    db.Dispose();
                    db = new PetStoreEntities();
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    Console.Write(".");
                }
            }

            db.SaveChanges();
        }
예제 #8
0
        public static void GenerateCountries(PetStoreEntities data, int amount = 20)
        {
            var hash = new HashSet <string>();

            Console.WriteLine("Importing countries...");
            for (int i = 0; i < amount; i++)
            {
                var countryName = RandomGenerator.GetString(5, 50);

                if (hash.Contains(countryName.ToLower()))
                {
                    i--;
                    continue;
                }

                hash.Add(countryName.ToLower());

                data.Countries.Add(new Country
                {
                    Name = countryName
                });
            }

            data.SaveChanges();
        }
예제 #9
0
        public static void GeneratePets(PetStoreEntities data)
        {
            var species   = data.Species.OrderBy(e => Guid.NewGuid());
            var colors    = data.Colors.Select(c => c.Id).ToList();
            var colorsLen = colors.Count;

            Console.WriteLine("Importing pets for each species...");
            foreach (var entry in species)
            {
                // Average of 50
                var numberOfPets = RandomGenerator.GetNumber(20, 80);

                for (int i = 0; i < numberOfPets; i++)
                {
                    var pet = new Pet
                    {
                        Price       = RandomGenerator.GetDecimal(5, 2500),
                        ColorId     = colors[RandomGenerator.GetNumber(0) % colorsLen],
                        DateOfBirth = RandomGenerator.GetDate(DateTime.Now.AddYears(-5), DateTime.Now.AddDays(-60)),
                        Breed       = RandomGenerator.GetString(5, 15)
                    };

                    entry.Pets.Add(pet);
                }

                Console.Write(".");
            }

            Console.WriteLine();

            data.SaveChanges();
        }
예제 #10
0
        public static void ImportSpecies(int count)
        {
            Console.WriteLine("ImportSpecies");
            var data = new PetStoreEntities();

            var coutriesIds    = data.Countries.Select(c => c.Id).ToList();
            var countriesCount = coutriesIds.Count;

            // generate 100 ids list
            var countriesRandomCountryIds = new List <int>();

            // add the unique 20
            countriesRandomCountryIds.AddRange(coutriesIds);

            // add the rest to count
            for (int i = 0; i < count - countriesCount; i++)
            {
                var randomCountryIndex = RandomInstance.Next(0, countriesCount);
                var randomId           = coutriesIds[randomCountryIndex];
                countriesRandomCountryIds.Add(randomId);
            }

            // randomize
            var shuffledCountryIds = countriesRandomCountryIds.OrderBy(g => Guid.NewGuid()).ToList();

            var speciesNames = new HashSet <string>();

            do
            {
                speciesNames.Add(RandomGenerator.RandomString(5, 50));
            }while (speciesNames.Count < count);

            var counter = 0;

            foreach (var specie in speciesNames)
            {
                var id = shuffledCountryIds[0];
                shuffledCountryIds.RemoveAt(0);
                var newSpecie = new Species()
                {
                    Name      = specie,
                    CountryId = id
                };

                data.Species.Add(newSpecie);
                counter++;

                if (counter % 100 == 0)
                {
                    data.SaveChanges();
                    data.Dispose();
                    data = new PetStoreEntities();
                    Console.Write(".");
                }
            }

            data.SaveChanges();
            data.Dispose();
        }
 public void RestorePetMedicine(String pm_id)
 {
     using (var db = new PetStoreEntities())
     {
         var PetMedicine = db.PetMedicines.Find(pm_id);
         PetMedicine.pm_status = "Active";
         db.SaveChanges();
     }
 }
예제 #12
0
 /// <summary>
 /// Restore gift
 /// </summary>
 /// <param name="g_id"></param>
 public void RestoreGift(String g_id)
 {
     using (var db = new PetStoreEntities())
     {
         var Gift = db.Gifts.Find(g_id);
         Gift.g_status = "Active";
         db.SaveChanges();
     }
 }
 public void DeletePetAccessories(String pa_id)
 {
     using (var db = new PetStoreEntities())
     {
         var PetAccessories = db.PetAccessories.Find(pa_id);
         PetAccessories.pa_status = "Inactive";
         db.SaveChanges();
     }
 }
예제 #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cmt_id"></param>
 public void DeleteComment(int cmt_id)
 {
     using (var db = new PetStoreEntities())
     {
         var cmt = db.Comments.Find(cmt_id);
         cmt.cmt_status = "Inactive";
         db.SaveChanges();
     }
 }
예제 #15
0
 public void RestorePetFood(String pf_id)
 {
     using (var db = new PetStoreEntities())
     {
         var Petfood = db.PetFoods.Find(pf_id);
         Petfood.pf_status = "Active";
         db.SaveChanges();
     }
 }
예제 #16
0
 public void RestorePetToys(String pt_id)
 {
     using (var db = new PetStoreEntities())
     {
         var PetToys = db.PetToys.Find(pt_id);
         PetToys.pt_status = "Active";
         db.SaveChanges();
     }
 }
예제 #17
0
 /// <summary>
 /// delete comment reply by id
 /// </summary>
 /// <param name="cmtd_id"></param>
 public void RestoreCommentDetail(int cmtd_id)
 {
     using (var db = new PetStoreEntities())
     {
         var cmt = db.CommentDetails.Find(cmtd_id);
         cmt.cmtd_status = "Active";
         db.SaveChanges();
     }
 }
예제 #18
0
 /// <summary>
 /// Update gift
 /// </summary>
 /// <param name="gID"></param>
 /// <param name="gName"></param>
 /// <param name="gStatus"></param>
 /// <param name="gImage"></param>
 public void UpdateGift(String gID, String gName, String gStatus, String gImage)
 {
     using (var db = new PetStoreEntities())
     {
         var Gift = db.Gifts.Find(gID);
         Gift.g_name   = gName;
         Gift.g_image  = gImage;
         Gift.g_status = gStatus;
         db.SaveChanges();
     }
 }
예제 #19
0
        public static void GenerateProducts(PetStoreEntities data, int amountPerCategory = 400)
        {
            var categories   = data.Categories.OrderBy(e => Guid.NewGuid()).Select(x => x.Id).ToList();
            var species      = data.Species.OrderBy(e => Guid.NewGuid());
            var speciesCount = species.Count();

            data.Configuration.AutoDetectChangesEnabled = false;
            data.Configuration.ValidateOnSaveEnabled    = false;

            Console.WriteLine("Importing products in each category.");
            foreach (var category in categories)
            {
                for (int j = 0; j < amountPerCategory; j++)
                {
                    var product = new Product
                    {
                        CategoryId = category,
                        Name       = RandomGenerator.GetString(5, 25),
                        Price      = RandomGenerator.GetDecimal(10, 1000)
                    };

                    var suitableSpecies = RandomGenerator.GetNumber(2, 10);

                    for (int i = 0; i < suitableSpecies; i++)
                    {
                        var toSkip = RandomGenerator.GetNumber(0, speciesCount - 1);
                        product.Species.Add(species.Skip(toSkip).Take(1).First());
                    }

                    data.Products.Add(product);
                }

                Console.Write(".");
                data.SaveChanges();
            }

            Console.WriteLine();

            data.SaveChanges();
        }
예제 #20
0
        private void bbiRestore_ItemClick(object sender, ItemClickEventArgs e)
        {
            int index = gridView.FocusedRowHandle;
            int id    = int.Parse(gridView.GetRowCellValue(index, "u_id").ToString());

            using (var db = new PetStoreEntities())
            {
                var update = (from u in db.Users where u.u_id == id select u).Single();
                update.u_status = "Active";
                db.SaveChanges();
            }
            bbiRestore.Enabled = false;
        }
예제 #21
0
 public void UpdateUser(int uID, string uName, string uGender, string uMail, string uPhone, string uAddress)
 {
     using (var db = new PetStoreEntities())
     {
         var User = db.Users.Find(uID);
         User.u_name    = uName;
         User.u_gender  = uGender;
         User.u_email   = uMail;
         User.u_phone   = uPhone;
         User.u_address = uAddress;
         db.SaveChanges();
     }
 }
예제 #22
0
        public static void Import(PetStoreEntities db, int count)
        {
            for (int i = 0; i < count; i++)
            {
                db.Categories.Add(new Category()
                {
                    Name = RandomGenerator.Instance.GetRandomString(5, 20)
                });
            }

            db.SaveChanges();
            Console.WriteLine("Categories added!");
        }
예제 #23
0
        public static void GenerateCategories(PetStoreEntities data, int amount = 50)
        {
            Console.WriteLine("Importing categories...");

            for (int i = 0; i < amount; i++)
            {
                data.Categories.Add(new Category
                {
                    Name = RandomGenerator.GetString(5, 20)
                });
            }

            data.SaveChanges();
        }
        /// <summary>
        /// update food by food id
        /// </summary>
        /// <param name="pmID"></param>
        /// <param name="pmName"></param>
        /// <param name="pmPrice"></param>
        /// <param name="pmPriceSell"></param>
        /// <param name="pmAmount"></param>

        public void UpdateMedicint(String pmID, String pmName, String pmImage, int pmPrice, int pmSalePrices, int pmAmount, String pmDescription, String pmStatus)
        {
            using (var db = new PetStoreEntities())
            {
                var PetMedicine = db.PetMedicines.Find(pmID);
                PetMedicine.pm_name        = pmName;
                PetMedicine.pm_image       = pmImage;
                PetMedicine.pm_prices      = pmPrice;
                PetMedicine.pm_salePrice   = pmSalePrices;
                PetMedicine.pm_amount      = pmAmount;
                PetMedicine.pm_description = pmDescription;
                PetMedicine.pm_status      = pmStatus;
                db.SaveChanges();
            }
        }
예제 #25
0
 /// <summary>
 /// update food by food id
 /// </summary>
 /// <param name="pfID"></param>
 /// <param name="pfName"></param>
 /// <param name="pfPrice"></param>
 /// <param name="pfPriceSell"></param>
 /// <param name="pfAmount"></param>
 /// <param name="typeID"></param>
 public void UpdateFood(String pfID, String pfName, int pfPrice, int pfPriceSell, int pfAmount, int typeID, String pfStatus, String pfImage)
 {
     using (var db = new PetStoreEntities())
     {
         var Petfood = db.PetFoods.Find(pfID);
         Petfood.pf_name      = pfName;
         Petfood.pf_prices    = pfPrice;
         Petfood.pf_image     = pfImage;
         Petfood.pf_salePrice = pfPriceSell;
         Petfood.pf_amount    = pfAmount;
         Petfood.t_id         = typeID;
         Petfood.pf_status    = pfStatus;
         db.SaveChanges();
     }
 }
예제 #26
0
        /// <summary>
        /// update food by food id
        /// </summary>
        /// <param name="ptID"></param>
        /// <param name="ptName"></param>
        /// <param name="ptPrice"></param>
        /// <param name="ptPriceSell"></param>
        /// <param name="ptAmount"></param>

        public void UpdateToys(String ptID, String ptName, String ptImage, int ptPrice, int ptSalePrices, int ptAmount, String ptDescription, String ptStatus)
        {
            using (var db = new PetStoreEntities())
            {
                var PetToys = db.PetToys.Find(ptID);
                PetToys.pt_name        = ptName;
                PetToys.pt_image       = ptImage;
                PetToys.pt_prices      = ptPrice;
                PetToys.pt_salePrice   = ptSalePrices;
                PetToys.pt_amount      = ptAmount;
                PetToys.pt_description = ptDescription;
                PetToys.pt_status      = ptStatus;
                db.SaveChanges();
            }
        }
예제 #27
0
 /// <summary>
 /// Update Pet
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="Name"></param>
 /// <param name="OPrice"></param>
 /// <param name="SPrice"></param>
 /// <param name="image"></param>
 /// <param name="description"></param>
 /// <param name="status"></param>
 /// <param name="tID"></param>
 public void UpdatePet(string ID, string Name, int OPrice, int SPrice, string image,
                       string description, string status, int tID)
 {
     using (var db = new PetStoreEntities())
     {
         var Pet = db.Pets.Find(ID);
         Pet.p_name        = Name;
         Pet.p_prices      = OPrice;
         Pet.p_image       = image;
         Pet.p_salePrice   = SPrice;
         Pet.t_id          = tID;
         Pet.p_status      = status;
         Pet.p_description = description;
         db.SaveChanges();
     }
 }
예제 #28
0
        public static void Import(PetStoreEntities db, int count)
        {
            // using hashset because we must have unique names
            var countryNames = new HashSet<string>();

            while (countryNames.Count < count)
            {
                var name = RandomGenerator.Instance.GetRandomString(5, 50);
                countryNames.Add(name);
            }

            foreach (var countryName in countryNames)
            {
                db.Countries.Add(new Country() { Name = countryName });
            }

            db.SaveChanges();
            Console.WriteLine("Countries added!");
        }
예제 #29
0
        public static void Import(PetStoreEntities db, int count)
        {
            var countryIds = db.Countries.OrderBy(c => Guid.NewGuid()).Select(c => c.Id).ToList();

            // using hashset because we must have unique names
            var speciesNames = new HashSet<string>();

            while (speciesNames.Count < count)
            {
                var name = RandomGenerator.Instance.GetRandomString(5, 50);
                speciesNames.Add(name);
            }

            var speciesNamesAsList = speciesNames.ToList();

            // ensure there is atleast one species per country
            for (int i = 0; i < countryIds.Count; i++)
            {
                db.Species.Add(new Species()
                {
                    Name = speciesNamesAsList[i],
                    OriginCountryId = countryIds[i],
                });
            }

            // assign country to other species at random
            for (int i = countryIds.Count; i < speciesNamesAsList.Count; i++)
            {
                db.Species.Add(new Species()
                {
                    Name = speciesNamesAsList[i],
                    OriginCountryId = countryIds[RandomGenerator.Instance.GetRandomNumber(0, countryIds.Count - 1)],
                });
            }

            db.SaveChanges();
            Console.WriteLine("Species added!");
        }
예제 #30
0
        public static void ImportPets(int count)
        {
            Console.WriteLine("ImportPets");
            var data = new PetStoreEntities();

            var speciesIds   = data.Species.Select(c => c.Id).ToList();
            var speciesCount = speciesIds.Count;

            // generate 5000 ids list
            var speciesRandomIds = new List <int>();

            // add the unique
            speciesRandomIds.AddRange(speciesIds);

            // add the rest to count
            for (int i = 0; i < count - speciesCount; i++)
            {
                var randomSpecieIndex = RandomInstance.Next(0, speciesCount);
                var randomId          = speciesIds[randomSpecieIndex];
                speciesRandomIds.Add(randomId);
            }

            // randomize
            var shuffledSpeciesIds = speciesRandomIds.OrderBy(g => Guid.NewGuid()).ToList();

            var colorsId    = data.Colors.Select(c => c.Id).ToList();
            var colorsCount = colorsId.Count;

            var counter = 0;

            foreach (var specieId in shuffledSpeciesIds)
            {
                var randomPrice      = (decimal)((RandomInstance.NextDouble() * (2500 - 5)) + 5);
                var randomColorIndex = RandomInstance.Next(0, colorsCount);
                var randomColorId    = colorsId[randomColorIndex];
                var randomDate       = RandomGenerator.RandomDate(new DateTime(2010, 1, 1), DateTime.Now.AddDays(-60));
                var randomBreed      = RandomGenerator.RandomString(0, 30);

                var newPet = new Pet()
                {
                    SpecieId    = specieId,
                    DateOfBirth = randomDate,
                    Price       = randomPrice,
                    ColorId     = randomColorId,
                    Breed       = randomBreed
                };

                data.Pets.Add(newPet);
                counter++;

                if (counter % 100 == 0)
                {
                    data.SaveChanges();
                    data.Dispose();
                    data = new PetStoreEntities();
                    Console.Write(".");
                }
            }

            data.SaveChanges();
            data.Dispose();
        }
예제 #31
0
        public static void ImportProducts(int count)
        {
            Console.WriteLine("ImportProducts");
            var data = new PetStoreEntities();

            var categoriesIds   = data.Categories.Select(c => c.Id).ToList();
            var categoriesCount = categoriesIds.Count;

            // generate 20000 ids list
            var categoriesRandomCountryIds = new List <int>();

            // add the unique 50
            categoriesRandomCountryIds.AddRange(categoriesIds);

            // add the rest to count
            for (int i = 0; i < count - categoriesCount; i++)
            {
                var randomCategoriesIndex = RandomInstance.Next(0, categoriesCount);
                var randomId = categoriesIds[randomCategoriesIndex];
                categoriesRandomCountryIds.Add(randomId);
            }

            // randomize
            var shuffledCategoryIds = categoriesRandomCountryIds.OrderBy(g => Guid.NewGuid()).ToList();

            var productsNames = new HashSet <string>();

            do
            {
                productsNames.Add(RandomGenerator.RandomString(5, 25));
            }while (productsNames.Count < count);
            var counter = 0;

            foreach (var product in productsNames)
            {
                var id = shuffledCategoryIds[0];
                shuffledCategoryIds.RemoveAt(0);
                var newProduct = new PetProduct()
                {
                    Name       = product,
                    CategoryId = id,
                    Price      = (decimal)((RandomInstance.NextDouble() * (1000 - 10)) + 10)
                };

                data.PetProducts.Add(newProduct);
                counter++;

                // add species match here
                var speciesCount = RandomInstance.Next(2, 11);
                var speciesToAdd = new HashSet <Species>();
                var species      = data.Species.OrderBy(s => Guid.NewGuid()).Take(speciesCount).ToList();
                while (speciesToAdd.Count != speciesCount)
                {
                    var specieIdRandomIndex = RandomInstance.Next(0, species.Count);
                    var randomSpecie        = species[specieIdRandomIndex];
                    speciesToAdd.Add(randomSpecie);
                }

                foreach (var specie in speciesToAdd)
                {
                    newProduct.Species.Add(specie);
                }

                if (counter % 10 == 0)
                {
                    data.SaveChanges();
                    data.Dispose();
                    data = new PetStoreEntities();
                    Console.Write(".");
                }
            }

            data.SaveChanges();
            data.Dispose();
        }