public void Edit(DiscountModel model) { string commandText = @"UPDATE DISCOUNT SET D_NAME = " + SQLString(model.Name) + @" , VALID_FROM_DATE = " + SQLDateTime(model.ValidFrom) + @" , VALID_TO_DATE = " + SQLDateTime(model.ValidTo) + @" , DISCOUNT_KIND_ID = " + SQLInt(model.DiscountKindId) + @" , D_VALUE = " + SQLDecimal(model.Value) + @" WHERE ID = " + SQLInt(model.DiscountId); ExecuteNonQuery(commandText); }
public void Add(DiscountModel model) { string commandText = @"INSERT INTO DISCOUNT ( D_NAME, VALID_FROM_DATE, VALID_TO_DATE, DISCOUNT_KIND_ID, D_VALUE ) VALUES (" + SQLString(model.Name) + ", " + SQLDateTime(model.ValidFrom) + ", " + SQLDateTime(model.ValidTo) + ", " + SQLInt(model.DiscountKindId) + ", " + SQLDecimal(model.Value) + ")"; ExecuteNonQuery(commandText); }
public ActionResult Edit(DiscountModel model) { if (!ModelState.IsValid) { using (DiscountContext context = new DiscountContext()) { ViewBag.DiscountKinds = context.GetDiscountKinds(); } return View("Edit", model); } else { using (DiscountContext context = new DiscountContext()) { context.Edit(model); } return RedirectToAction("Index"); } }
public DiscountModel GetDiscount(int id) { DiscountModel model = null; string commandText = @"SELECT d.ID AS DISCOUNT_ID , d.D_NAME , d.VALID_FROM_DATE , d.VALID_TO_DATE , d.DISCOUNT_KIND_ID , dk.DK_NAME , d.D_VALUE FROM DISCOUNT d LEFT JOIN DISCOUNT_KIND dk ON dk.ID = d.DISCOUNT_KIND_ID WHERE d.ID = " + SQLInt(id); using (DataTable dtDiscounts = FillDataTable(commandText)) { if( dtDiscounts.Rows.Count > 0) { DataRow drDiscount = dtDiscounts.Rows[0]; model = new DiscountModel() { DiscountId = TryParse.ToInt32(drDiscount["DISCOUNT_ID"]), Name = TryParse.ToString(drDiscount["D_NAME"]), DiscountKindId = TryParse.ToInt32(drDiscount["DISCOUNT_KIND_ID"]), DiscountKindName = TryParse.ToString(drDiscount["DK_NAME"]), ValidFrom = TryParse.ToDateTime(drDiscount["VALID_FROM_DATE"]), ValidTo = TryParse.ToDateTime(drDiscount["VALID_TO_DATE"]), Value = TryParse.ToDecimal(drDiscount["D_VALUE"]), }; } } return model; }
public ActionResult New() { DiscountModel model = new DiscountModel() { DiscountId = 0, Name = "", ValidFrom = DateTime.Now, ValidTo = DateTime.Now }; using (DiscountContext context = new DiscountContext()) { ViewBag.DiscountKinds = context.GetDiscountKinds(); } return View("Edit", model); }