public static Toy Create(string toyCategory) { ToyCategory toyCategoryEnum = (ToyCategory)Enum.Parse(typeof(ToyCategory), toyCategory); switch (toyCategoryEnum) { case ToyCategory.Car: return(new Car() { }); case ToyCategory.Plane: return(new Plane() { }); case ToyCategory.Submarine: return(new Submarine() { }); case ToyCategory.Computer: return(new Computer() { }); default: throw new Exception($"Class of type {toyCategory} not implemented"); } }
public void AddToyCategory() { using (var toyapp = new ToyApplicationDbContext()) { string CategoryName; Console.WriteLine("Enter CategoryName"); CategoryName = Console.ReadLine(); var toycategory = new ToyCategory { ToyCategoryName = CategoryName, }; toyapp.ToyCategory.Add(toycategory); toyapp.SaveChanges(); Console.WriteLine(" Toy Category Successfully Added"); } }
private void AddBindingsForCategory(string selectedCategory) { ToyCategory toyCategoryEnum = (ToyCategory)Enum.Parse(typeof(ToyCategory), selectedCategory); switch (toyCategoryEnum) { case ToyCategory.Car: this.speedValue.DataBindings.Add("Text", SelectedToy, "Speed"); break; case ToyCategory.Plane: this.speedValue.DataBindings.Add("Text", SelectedToy, "Speed"); this.heightValue.DataBindings.Add("Text", SelectedToy, "Height"); break; case ToyCategory.Submarine: this.speedValue.DataBindings.Add("Text", SelectedToy, "Speed"); this.depthValue.DataBindings.Add("Text", SelectedToy, "Depth"); break; } }