public List <SubCategoryEntity> ViewSubCategories() { List <SubCategoryEntity> se = new List <SubCategoryEntity>(); try { if (con.State != ConnectionState.Open) { con.Open(); } com = con.CreateCommand(); string query = "select s.SubCatID,s.SubCatName,c.CategoryName from SubCategoryTable s join CategoryTable c on s.CatID=c.CategoryID"; com.CommandText = query; r = com.ExecuteReader(); while (r.Read()) { SubCategoryEntity sce = new SubCategoryEntity(); sce.SubCatID = Convert.ToInt32(r[0]); sce.SubCategoryName = r[1].ToString(); sce.CatName = r[2].ToString(); se.Add(sce); } } catch (Exception ex) { throw ex; } finally { con.Close(); } return(se); }
private void AddSubCategory() { try { SubCategoryEntity sbe = new SubCategoryEntity(); Console.WriteLine("Enter Sub Category Name"); sbe.SubCategoryName = Console.ReadLine(); var res = bal.GetCategories(); foreach (KeyValuePair <int, string> kvp in res) { Console.WriteLine(kvp.Key + ".\t" + kvp.Value); } Console.WriteLine("Enter Category ID "); sbe.CatID = int.Parse(Console.ReadLine()); var add = bal.AddSubCategory(sbe); if (add) { Console.WriteLine("Sub Category Added Successfully"); var scat = bal.ViewSubCategories(); Console.WriteLine("{0,10}{1,20}{2,20}", "ID", "SubCategory Name", "CategoryName"); foreach (var s in scat) { Console.WriteLine("{0,10}{1,20}{2,20}", s.SubCatID, s.SubCategoryName, s.CatName); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Handle(CreateEntityCommand <SubCategoryModel> command) { var mainCategory = this.mainCategoryRepository.FindById(command.Model.MainCategoryId); var entity = new SubCategoryEntity { Name = command.Model.Name, MainCategory = mainCategory, }; this.subCategoryRepository.Add(entity); }
public bool AddSubCategory(SubCategoryEntity sce) { if (string.IsNullOrEmpty(sce.SubCategoryName) || string.IsNullOrWhiteSpace(sce.SubCategoryName)) { throw new Exception("SubCategoryName cannot be Blank or empty"); } if (sce.CatID <= 0) { throw new Exception("Please Enter the CategoryID Displaying Above. ID cannot be zero or NULL"); } return(dal.AddSubCategory(sce)); }
protected void UpdateSubCatagory(object parameter) { int Sub_category_id = 0; TextBox tb = (TextBox)parameter; int.TryParse(tb.Text, out Sub_category_id); if ((Sub_category_id > 0) && (SelectedCategory != null)) { SubCategoryEntity ob_sub_Category = _lstSubCategory.Where(s => s.id == Sub_category_id).FirstOrDefault(); List <sub_category> temp_list = SubCategoryServices.GetAllSubCategoryByName(ob_sub_Category.sub_category_name.Trim(), SelectedCategory.id); if (temp_list.Count == 0 || temp_list.Count == 1) { if (temp_list.Count == 1) { sub_category temp = temp_list.FirstOrDefault(); if (temp.id != ob_sub_Category.id) { BindGrid(); //RaisedPropertyChanged("Category"); //MessageBox.Show("SubCategory Name alredy Exist."); InventoryHelper.SimpleAlert("Warning", "SubCategory Name alredy Exist."); return; } } sub_category temp_ob_sub_Category = SubCategoryServices.GetSubCategory(ob_sub_Category.id); temp_ob_sub_Category.subcategory_name = ob_sub_Category.sub_category_name; int temp_sub_Category_id = SubCategoryServices.AddUpdateSubCategory(temp_ob_sub_Category); if (temp_sub_Category_id == ob_sub_Category.id) { //MessageBox.Show("Sub-Category " + ob_sub_Category.sub_category_name + " is Updated"); InventoryHelper.SuccessAlert("Success", "Sub-Category " + ob_sub_Category.sub_category_name + " is Updated"); BindGrid(); //RaisedPropertyChanged("Category"); } } else { // MessageBox.Show("Category Name already Exist"); InventoryHelper.SimpleAlert("Warning", "Category Name already Exist"); } } }
public bool AddSubCategory(SubCategoryEntity sce) { bool result = false; try { if (con.State != ConnectionState.Open) { con.Open(); } com = con.CreateCommand(); string query = "insert into SubCategoryTable values(@scatname,@catid)"; com.CommandText = query; IDataParameter scatname = com.CreateParameter(); scatname.ParameterName = "@scatname"; scatname.Value = sce.SubCategoryName; com.Parameters.Add(scatname); IDataParameter catid = com.CreateParameter(); catid.ParameterName = "@catid"; catid.Value = sce.CatID; com.Parameters.Add(catid); var res = com.ExecuteNonQuery(); if (res > 0) { result = true; } } catch (Exception ex) { throw ex; } finally { con.Close(); } return(result); }
protected override void Seed(SportsbookDbContext context) { // Categories string[] catNames = new string[] { "Football", "Basketball", "Ice Skating", "Baseball", "Badminton", "Swimming", "American Football", "Boxing", "Biking", "Running" }; foreach (string catName in catNames) { var cat = new CategoryEntity() { Name = catName }; var subCat = new SubCategoryEntity() { Name = "SubCat" + catName, Category = cat }; context.SubCategoryEntities.Add(subCat); } context.SaveChanges(); // Events for (int x = 0; x < 10; x++) { var ev = new EventEntity() { Name = "A" + x.ToString() + " - B" + x.ToString(), StartDate = DateTime.Now, EndDate = DateTime.Now.Add(TimeSpan.FromDays(1)), SubCategory = context.SubCategoryEntities.ToList()[x] }; var market = new MarketEntity() { MarketGroupName = "Match Winner", StartDate = DateTime.Now, EndDate = DateTime.Now.Add(TimeSpan.FromDays(1)), Event = ev, MarketSelections = new Collection <MarketSelectionEntity>() { new MarketSelectionEntity() { Odds = 1.1, DisplayName = "1" }, new MarketSelectionEntity() { Odds = 1.2, DisplayName = "X" }, new MarketSelectionEntity() { Odds = 1.3, DisplayName = "2" }, } }; context.MarketEntities.Add(market); } context.SaveChanges(); }