public void Delete(int id) { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var product = domain.FindById(id); if (product != null) { domain.Delete(product); ctx.SaveChanges(); } } }
public void SetDropDownList() { using (var ctx = new ProductMNEntities()) { var cateDomain = new CategoryDomain(ctx); var supDomain = new SupplierDomain(ctx); var suppliers = supDomain.GetAll().Select(s => new DropDownListVMs { Text = s.CompanyName, Value = s.SupplierID.ToString() }).ToList(); var categories = cateDomain.GetAll().Select(c => new DropDownListVMs { Text = c.CategoryName, Value = c.CategoryID.ToString() }).ToList(); var discontinueds = new List <DropDownListVMs> { new DropDownListVMs { Text = "True", Value = "true" }, new DropDownListVMs { Text = "False", Value = "false" }, }; Suppliers_ID.DataTextField = "Text"; Suppliers_ID.DataValueField = "Value"; Suppliers_ID.DataSource = suppliers; Suppliers_ID.DataBind(); Categories_ID.DataTextField = "Text"; Categories_ID.DataValueField = "Value"; Categories_ID.DataSource = categories; Categories_ID.DataBind(); Discountinued.DataTextField = "Text"; Discountinued.DataValueField = "Text"; Discountinued.DataSource = discontinueds; Discountinued.DataBind(); } }
public void DropDownListSelected() { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var product = domain.FindById(_productId); Categories_ID.ClearSelection(); Categories_ID.Items.FindByValue(product.CategoryID.ToString()).Selected = true; Suppliers_ID.ClearSelection(); Suppliers_ID.Items.FindByValue(product.SupplierID.ToString()).Selected = true; Discountinued.ClearSelection(); Discountinued.Items.FindByValue(product.Discontinued.ToString()).Selected = true; } }
public void SetForm() { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var product = domain.FindById(_productId); if (product != null) { Product_Id.Text = product.ProductID.ToString(); Product_Name.Text = product.ProductName; Unit_Price.Text = product.UnitPrice.ToString(); Units_In_Stock.Text = product.UnitsInStock.ToString(); Units_On_Order.Text = product.UnitsOnOrder.ToString(); Recorder_Level.Text = product.ReorderLevel.ToString(); Quantity_Per_Unit.Text = product.QuantityPerUnit; } } }
//public void LoadGrid() //{ // using (var ctx = new ProductMNEntities()) // { // var domain = new ProductDomain(ctx); // var list = domain.GetAll().ToList(); // ProductGrid.DataSource = list; // ProductGrid.DataBind(); // } //} public void SetDropDownList() { using (var ctx = new ProductMNEntities()) { var query = ctx.Suppliers.Select(s => new DropDownListVMs() { Text = s.CompanyName, Value = s.SupplierID.ToString() }).ToList(); query.Insert(0, new DropDownListVMs() { Text = "---Any---", Value = "" }); Suppliers.DataTextField = "Text"; Suppliers.DataValueField = "Value"; Suppliers.DataSource = query; Suppliers.DataBind(); } }
public void Create() { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var product = new Product(); product.ProductName = Product_Name.Text; product.SupplierID = int.Parse(Suppliers_ID.SelectedValue); product.CategoryID = int.Parse(Categories_ID.SelectedValue); product.UnitPrice = decimal.Parse(Unit_Price.Text); product.UnitsInStock = short.Parse(Units_In_Stock.Text); product.UnitsOnOrder = short.Parse(Units_On_Order.Text); product.ReorderLevel = short.Parse(Recorder_Level.Text); product.QuantityPerUnit = Quantity_Per_Unit.Text; product.Discontinued = bool.Parse(Discountinued.SelectedValue); domain.Create(product); ctx.SaveChanges(); } }
public void Search(string name, decimal?min_price, decimal?max_price, int page, int take, int?supplierId) { using (var ctx = new ProductMNEntities()) { var domain = new ProductDomain(ctx); var model = domain.QueryFilter(name, min_price, max_price, page, take, supplierId); ProductGrid.DataSource = model.list; ProductGrid.DataBind(); total_count = model.total_count; this.page = page; //LiteralControl pagination_elements = new LiteralControl(); //var pagination = Request.Form["pagination"]; //Console.WriteLine(pagination); //if (pagination != null) //{ // pagination_elements.Text += @"<li><a href='#'>1</a></li>"; // pagination.Controls.Add(pagination_elements); //} } }