我有一个保存按钮,它将在我的“IncidentActions”表中添加新数据,同时更新我的“事件”表中的 3 列。
我该怎么做
这是我用来尝试完成此任务的 C# 代码。
protected void cmdSave_Click(object sender, EventArgs e)
{
Context db = new Context();
// This will check the Action from the actions table and
var actionID = (from i in db.Actions
where i.Actions == tbActionType.Text
select i.ActionsID).First();
long ID = Convert.ToInt64(Request.QueryString["IncidentID"]);
// TODO: update the incident table accordingly
IncidentAction act = new IncidentAction
{
IncidentID = ID,
ActionDate = (DateTime)dpActionDate.SelectedDate,
ActionsID = Convert.ToInt32(actionID),
StatusID = statID,
IsPublic = false,
Title = tbTitle.Text.Trim(),
PeriodValue = Convert.ToInt64(txtDuration.Text),
Description = txtDescription.Text.Trim(),
EstimatedCost = txtEstimatedCost.Text == string.Empty ? (decimal?)null : Convert.ToDecimal(txtEstimatedCost.Text),
ActualCost = txtActualCost.Text == string.Empty ? (decimal?)null : Convert.ToDecimal(txtActualCost.Text),
LastUpdated = DateTime.Now,
UpdatedBy = Convert.ToString(loggedInUserName),
CreatedByUserID = Convert.ToInt32(loggedInUserID),
Active = true
};
db.IncidentActions.Add(act);
db.SaveChanges();
Incident inc = new Incident
{
IncidentID = ID,
StatusID = statID_new,
IncidentPendingDate = DateTime.Now
};
db.SaveChanges();
}
}