protected void Remove_Click(object sender, EventArgs e) { Control item = (sender as System.Web.UI.WebControls.Button).Parent; string product = (item.FindControl("spnPromotedProduct") as HtmlGenericControl).InnerText; long productId; if (!string.IsNullOrEmpty(product) && product != "0" && long.TryParse(product, out productId)) { HtmlGenericControl lblWeight = item.FindControl("lblWeight") as HtmlGenericControl; string section = (item.FindControl("spnSection") as HtmlGenericControl).InnerText; int weight = lblWeight != null?int.Parse(lblWeight.InnerText) : MAX_WEIGHT; int areaId = int.Parse((item.FindControl("spnAreaId") as HtmlGenericControl).InnerText); if (areaId == 0) { weight += MAX_WEIGHT; } int id = int.Parse((item.FindControl("spnID") as HtmlGenericControl).InnerText); PromotedProduct promotedProduct = new PromotedProduct() { Id = id, AreaId = areaId, Deleted = DateTime.Now, IsNewRecord = false, ProductId = productId, Section = section.Trim(), Weight = weight, }; promotedProduct.Update(); LoadItems(); } }
protected void Save_Click(object sender, EventArgs e) { Control item = (sender as System.Web.UI.WebControls.Button).Parent; string product = hfProductSelectedValue.Value; if (!string.IsNullOrEmpty(product) && product != "0") { string section = hfSectionSelectedValue.Value; int? weight = hfWeightSelectedValue != null && !string.IsNullOrEmpty(hfWeightSelectedValue.Value) ? (int?)int.Parse(hfWeightSelectedValue.Value) : null; if (weight != null) { int areaId = int.Parse((item.FindControl("spnAreaId") as HtmlGenericControl).InnerText); if (areaId == 0) { weight += MAX_WEIGHT; } int id = int.Parse((item.FindControl("spnID") as HtmlGenericControl).InnerText); var productItem = Product.FetchByCode(product); PromotedProduct promotedProduct = new PromotedProduct() { AreaId = areaId, ProductId = productItem.ProductId, Section = section.Trim(), Weight = (int)weight, }; if (id == 0) { promotedProduct.IsNewRecord = true; promotedProduct.Insert(); } else { promotedProduct.Id = id; promotedProduct.IsNewRecord = false; promotedProduct.Update(); } LoadItems(); } } }