public static void CategoriesMenu() { int?choice = UtilsFunctions.GetIntChoice(UtilsMenus.CategoriesMenuChoices(), 1, 2); switch (choice) { case 1: using (var db = new SellItContext()) { foreach (var item in db.DbCategory.Include(x => x.Brand)) { Console.WriteLine(item); } Console.WriteLine("\n"); } break; case 2: MainMenu(); break; default: break; } }
public static long CreateCategoryByConsole(long brandId) { Category category = null; long result = -1; string schoice = null; int count; bool tag = false; /* * private float tva; * private float price;*/ using (var db = new SellItContext()) { do { count = 0; schoice = GetString("Enter a name category"); foreach (var item in db.DbCategory.ToList()) { if (item.Name.Equals(schoice)) { break; } else { count++; } } if (count.Equals(db.DbCategory.Count())) { tag = true; } } while (!tag); category.Name = schoice; category.Description = GetString("Enter a description"); category.Tva = GetFloatLimitsIncluded("Enter a tva", 0F, 20F); category.Price = GetFloatLimitsIncluded("Enter a tva", 0F, 20F); category.Brand = db.DbBrand.Find(brandId); db.DbCategory.Add(category); db.SaveChanges(); foreach (var item in db.DbCategory.ToList()) { if (item.Name.Equals(schoice)) { result = item.CategoryId; } } } return(result); }
public static long CreateBrandByConsole() { long result = 0; Brand brand = new Brand(); Console.WriteLine("Create Brand :\n"); using (var db = new SellItContext()) { // On vérifie que le nom n'est pas utilisé par une autre marque: bool tag = false; // sortie de do si tag (tag==true) string choice = null; do { choice = GetString("Enter a new brand name :"); int count = 0; foreach (var item in db.DbBrand.ToList()) { if (choice.Equals(item.Name)) { // choice est déjà pris, pas la peine de tester les autres break; } else { count++; } } if (count == db.DbBrand.Count()) // Si count vaut la taille de la liste de brand, c'est qu'on a parcouru DbBrand sans rencontrer choice { tag = true; // -> sortie de boucle, choice est valide } //else : count < taille : on s'est arrêté dans le foreach car choice est déja pris comme nom, tag reste false pour boucler } while (!tag); brand.Name = choice; brand.Description = GetString("\nEnter a description :"); db.DbBrand.Add(brand); db.SaveChanges(); foreach (var item in db.DbBrand.ToList()) { if (item.Name.Equals(choice)) { result = item.BrandId; break; } } } return(result); }
public static List <Category> GetCategories() { List <Category> maListe = new List <Category>(); using (var ctx = new SellItContext()) { foreach (var item in ctx.DbCategory.ToList()) { maListe.Add(item); } } return(maListe); }
public static List <Seller> GetSellers() { List <Seller> maListe = new List <Seller>(); using (var ctx = new SellItContext()) { foreach (var item in ctx.Sellers) { maListe.Add(item); } } return(maListe); }
public static List <Brand> GetBrands() { List <Brand> maListe = new List <Brand>(); using (var ctx = new SellItContext()) { foreach (var item in ctx.DbBrand.ToList()) { maListe.Add(item); } } return(maListe); }
public static List <string> getCarTypeList() { List <string> liste = new List <string>(); using (var db = new SellItContext()) { foreach (var item in db.DbCategory.ToList()) { liste.Add(item.Name); } } liste.Sort(); IEnumerable <string> iListe = liste.Distinct(); liste = iListe.ToList(); return(liste); }
public static void DisplayCarsMenu() { int? choice = UtilsFunctions.GetIntChoice(UtilsMenus.DisplayCarsMenuChoices(), 1, 7); string schoice = null; switch (choice) { case 1: // Display all cars using (var db = new SellItContext()) { foreach (var item in db.DbCar.Include(x => x.Category).Include(x => x.Category.Brand).ToList()) { Console.WriteLine(item); } Console.WriteLine("\n"); DisplayCarsMenu(); } break; case 2: // Display cars by category using (var db = new SellItContext()) { // On affiche les Id de categories pour pouvoir choisir foreach (var item in db.DbCategory.Include(x => x.Brand).ToList()) { Console.WriteLine("Id : " + item.CategoryId + " : " + item.Name + " of " + item.Brand.Name); } Console.WriteLine("\n"); int? choice2 = null; bool tag = false; // Condition de sortie de do do { choice2 = UtilsFunctions.GetIntChoice("Choose Category by Id :", 1, int.MaxValue); foreach (var item in db.DbCategory.ToList()) { if (choice2 == item.CategoryId) { tag = true; break; } } } while (!tag); foreach (var item in db.DbCar.Include(x => x.Category).Include(x => x.Category.Brand).Where(x => x.Category.CategoryId == choice2).ToList()) { Console.WriteLine(item); } Console.WriteLine("\n"); DisplayCarsMenu(); } break; case 3: // Display Cars by brand using (var db = new SellItContext()) { foreach (var item in db.DbBrand.ToList()) { Console.WriteLine("Id : " + item.BrandId + " " + item.Name); } Console.WriteLine("\n"); int? choice2 = null; bool tag = false; do { choice2 = UtilsFunctions.GetIntChoice("Choose Brand by Id :", 1, int.MaxValue); foreach (var item in db.DbBrand.ToList()) { if (choice2 == item.BrandId) { tag = true; break; } } } while (!tag); foreach (var item in db.DbCar.Include(x => x.Category).Include(x => x.Category.Brand).Where(x => x.Category.Brand.BrandId == choice2).ToList()) { Console.WriteLine(item); } Console.WriteLine("\n"); DisplayCarsMenu(); } break; case 4: // Display Cars by name using (var db = new SellItContext()) { schoice = UtilsFunctions.GetString("enter a car name"); foreach (var item in db.DbCar.Where(x => x.Name.Contains(schoice)).ToList()) // J'ai pas inclu brand et Category c'est plus lisible { Console.WriteLine(item); } } Console.WriteLine("\n"); DisplayCarsMenu(); break; case 5: // Display Cars by availability using (var db = new SellItContext()) { foreach (var item in db.DbCar.ToList()) // J'ai pas inclu brand et Category c'est plus lisible { if (item.Avalaible) { Console.WriteLine(item); } } } Console.WriteLine("\n"); DisplayCarsMenu(); break; case 6: // Display Cars by year using (var db = new SellItContext()) { int?choice2 = UtilsFunctions.GetIntChoice("Enter a year", 1, int.MaxValue); foreach (var item in db.DbCar.ToList()) // J'ai pas inclu brand et Category c'est plus lisible { if (item.Year == choice2) { Console.WriteLine(); } } } Console.WriteLine("\n"); DisplayCarsMenu(); break; case 7: // Display Cars by color using (var db = new SellItContext()) { schoice = UtilsFunctions.GetString("enter a color"); foreach (var item in db.DbCar.Where(x => x.Color.Contains(schoice)).ToList()) // J'ai pas inclu brand et Category c'est plus lisible { Console.WriteLine(item); } } Console.WriteLine("\n"); DisplayCarsMenu(); break; case 8: CarsMenu(); break; default: break; } }
public static long CreateCarByConsole() { Car car = new Car(); long categoryId = -1; long brandId = -1; long carId = -1; int? choice = null; int? choice2 = null; bool tag = false; Console.WriteLine("Creating a new car\n"); car.Name = GetString("Enter a car name\n"); car.Year = GetIntLimitsIncluded("Enter a year", 1980, 2019); car.Color = GetString("Enter a color\n"); car.Year = GetIntLimitsIncluded("Enter a Time assurancy", 0, 5); car.DelayExchange = GetIntLimitsIncluded("Enter a delay of exchange", 0, 5); car.Avalaible = true; Console.WriteLine("Category choice\n"); using (var db = new SellItContext()) { Console.WriteLine("List of existing categories :\n"); foreach (var item in db.DbCategory.Include(x => x.Brand).ToList()) { Console.WriteLine("Id : " + item.CategoryId + ". " + item.Name + " of " + item.Brand.Name + "\n"); } Console.WriteLine("\n"); tag = false; do { choice = UtilsFunctions.GetIntChoice("Choose Category by Id or -1 if category does not exist:", 1, int.MaxValue); foreach (var item in db.DbCategory.ToList()) { if ((choice == item.CategoryId) | (choice == -1)) { tag = true; break; } } } while (!tag); if (choice == -1) // Creation d'une nouvelle catégorie { Console.WriteLine("List of existing brands :\n"); foreach (var item in db.DbBrand.ToList()) { Console.WriteLine("Id : " + item.BrandId + " " + item.Name); } Console.WriteLine("\n"); tag = false; do { choice2 = UtilsFunctions.GetIntChoice("Choose Brand by Id or -1 if brand does not exist:", 1, int.MaxValue); foreach (var item in db.DbCategory.ToList()) { if ((choice2 == item.CategoryId) | (choice2 == -1)) { tag = true; break; } } } while (!tag); if (choice2 == -1) { brandId = CreateBrandByConsole(); } else { brandId = (long)choice2; } Console.WriteLine("For Info, here are existing categories of car in the database :"); foreach (var item in getCarTypeList()) { Console.WriteLine(item); } categoryId = CreateCategoryByConsole(brandId); car.Category = db.DbCategory.Find(categoryId); db.DbCar.Add(car); foreach (var item in db.DbCar.ToList()) { if (item.Name.Equals(car.Name)) { carId = item.CarId; } } } } return(carId); }