public ActionResult EditTransaction(string TransID) { TransactionHistoryTableAdapter adapter = new TransactionHistoryTableAdapter(); EditTransaction model = new EditTransaction(); TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter(); DataTable tranTypeDT = tranTypeAdapter.GetData(); List<SelectListItem> items = new List<SelectListItem>(); foreach (DataRow row in tranTypeDT.Rows) { items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() }); } ViewData["TransType"] = items; try { int transactionID = int.Parse(TransID); DataTable result = adapter.GetDataByKey(transactionID); if (result.Rows.Count != 0) { model.Username = result.Rows[0].Field<string>("Username"); model.TransactionTypeID = result.Rows[0].Field<int>("TransactionTypeID"); model.Value = result.Rows[0].Field<int>("Value"); model.TransactionContent = result.Rows[0].Field<string>("TransactionContent"); model.ScheduleMealSetDetailID = result.Rows[0].Field<int?>("ScheduleMealSetDetailID"); model.IsAuto = result.Rows[0].Field<Boolean>("IsAuto"); model.InsertedDate = result.Rows[0].Field<DateTime>("InsertedDate"); model.UpdatedBy = result.Rows[0].Field<string>("UpdatedBy"); model.LastUpdated = result.Rows[0].Field<DateTime>("LastUpdated"); model.TransactionHistoryID = result.Rows[0].Field<int>("TransactionHistoryID"); } } catch (Exception ex) { Log.ErrorLog(ex.Message); } return View(model); }
public ActionResult EditTransaction(EditTransaction model) { TransactionTypeTableAdapter tranTypeAdapter = new TransactionTypeTableAdapter(); DataTable tranTypeDT = tranTypeAdapter.GetData(); List<SelectListItem> items = new List<SelectListItem>(); foreach (DataRow row in tranTypeDT.Rows) { items.Add(new SelectListItem { Text = row["Name"].ToString(), Value = row["TransactionTypeID"].ToString() }); } ViewData["TransType"] = items; if (!ModelState.IsValid) { return View(model); } int transactionHistoryID = model.TransactionHistoryID; string username = model.Username; int transactionTypeID = model.TransactionTypeID; int value = model.Value; string transactionContent = model.TransactionContent; int? scheduleMealSetDetailID = model.ScheduleMealSetDetailID; Boolean isAuto = model.IsAuto; DateTime insertedDate = model.InsertedDate; string updatedBy = model.UpdatedBy; DateTime lastUpdated = DateTime.Now; TransactionHistoryTableAdapter transAdapter = new TransactionHistoryTableAdapter(); try { transAdapter.UpdateTransactionHistory(username, transactionTypeID, value, transactionContent , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated , transactionHistoryID); XmlSync.SaveTransactionHistoryXml(transactionHistoryID, username, transactionTypeID, value, transactionContent , scheduleMealSetDetailID, isAuto, insertedDate, AccountInfo.GetUserName(Request), lastUpdated, null); } catch (Exception ex) { Log.ErrorLog(ex.Message); } return RedirectToAction("ListTransaction", "Transaction"); }