protected void btnAddMainCategory_Click(object sender, EventArgs e) { string name = ((TextBox)gvMainCategory.FooterRow.FindControl("txtAddCategory")).Text; using (MasterCategoryRepository repository = new MasterCategoryRepository()) { MainCategoryMaster newMaster = new MainCategoryMaster { Name = name, }; repository.Add(newMaster); } BindMasterCategory(); }
public bool SaveNewMainCategory(string data) { bool status = false; try { _dataContext = new LONDataClassesDataContext(); var dbObject = new MainCategoryMaster(); var mainCategory = new MainCategoryModel(); serialize = new JavaScriptSerializer(); mainCategory = serialize.Deserialize <MainCategoryModel>(data); mainCategory.CreatedDate = DateTime.Now; mainCategory.ModifiedDate = DateTime.Now; mainCategory.ModifiedBy = "tempModifiedName"; //Id is auto increamented. No need to pass value. //// dbObject.MainCategoryId = 1; dbObject.MainCategoryName = mainCategory.CategoryName; dbObject.MainCategoryImage = mainCategory.ImagePath; dbObject.CreatedBy = mainCategory.CreatedBy; dbObject.CreatedDate = mainCategory.CreatedDate; dbObject.ModifiedDate = mainCategory.ModifiedDate; dbObject.ModifiedBy = mainCategory.ModifiedBy; _dataContext.MainCategoryMasters.InsertOnSubmit(dbObject); _dataContext.SubmitChanges(); status = true; } catch (Exception exp) { status = false; } return(status); }