我已经为评论和反馈创建了一个创建控制器我有一个问题,我无法使用该控制器添加新评论,即如果我已经添加了针对某个 ID 的评论,它将给我编辑该评论的选项。但我希望它保存旧评论并允许我针对该 ID 添加新评论。请帮助我在这里粘贴我的控制器。
public ActionResult CreateNote(int id)
{
YelloAdminDbContext db = new YelloAdminDbContext();
var feedBack = db.SaveFeedBack.Find(id);
if (feedBack != null && feedBack.feedback.FeedBackDrpDown == "Interested - Call Back After 1 month")
{
var temp = db.Note.Find(id);
if (temp != null)
{
temp.CallBAckDate = DateTime.Now.AddDays(36);
return View(temp);
}
else
{
return View(new CallNote { LoginId = id, FormFillDate = DateTime.Now, CallBAckDate = DateTime.Now.AddDays(30) });
}
}
if (feedBack != null && feedBack.feedback.FeedBackDrpDown == "Not Available - Call Back After One Day")
{
var temp = db.Note.Find(id);
if (temp != null)
{
temp.CallBAckDate = DateTime.Now.AddHours(15);
return View(temp);
}
else
{
return View(new CallNote { LoginId = id, FormFillDate = DateTime.Now, CallBAckDate = DateTime.Now.AddDays(1) });
}
}
if (feedBack != null && feedBack.feedback.FeedBackDrpDown == "Currently using yello - Call Back After Two Months")
{
var temp = db.Note.Find(id);
if (temp != null)
{
temp.CallBAckDate = DateTime.Now.AddDays(10);
return View(temp);
}
else
{
return View(new CallNote { LoginId = id, FormFillDate = DateTime.Now, CallBAckDate = DateTime.Now.AddMonths(2) });
}
}
return View(new CallNote { LoginId = id, FormFillDate = DateTime.Now, CallBAckDate = null});
}
public bool DoesExist(int loginId)
{
YelloAdminDbContext db = new YelloAdminDbContext();
if (db.Note.Find(loginId) == null)
{
return false;
}
return true;
}
[HttpPost]
public ActionResult CreateNote(CallNote callnote)
{
YelloAdminDbContext db = new YelloAdminDbContext();
//if (DoesExist(callnote.LoginId))
//{
// db.Entry(callnote).State = EntityState.Modified;
// db.SaveChanges();
// return JavaScript("alert('success');");
//}
//else
if (ModelState.IsValid)
{
db.Note.Add(callnote);
db.SaveChanges();
return Content("Success");
}
return Content("Error");
}
这是创建笔记视图
@model MyYello.Admin.Models.CallNote
@{
ViewBag.Title = "CreateNote";
}
@*<body onload="JavaScript:AutoRefresh(30000);">*@
<body>
<h2>Comments and Feed Back</h2>
<div>
<h3>Curent Feed Back Value
<br />
@{Html.RenderAction("DisplayFeedBack", "Admin");}
</h3>
@{Html.RenderAction("SelectFeedBack", "Admin");}
</div>
@using (Html.BeginForm("CreateNote", "Admin", FormMethod.Post))
{@Html.ValidationSummary(true);
<fieldset>
@Html.HiddenFor(item => item.LoginId)
@Html.HiddenFor(item => item.FormFillDate)
<legend>Comments and Feedback</legend>
<div class="editor-label">
@Html.LabelFor(item => item.Comments, "Staff Comments")
</div>
<div class="editor-field">
@Html.TextAreaFor(item => item.Comments)
@Html.ValidationMessageFor(item => item.Comments)
</div>
<div class="editor-label">
@Html.LabelFor(item => item.FeedBackBox, "Custommer Feedback")
</div>
<div class="editor-field">
@Html.TextAreaFor(item => item.FeedBackBox)
@Html.ValidationMessageFor(item => item.FeedBackBox)
</div>
<div class="editor-label">
@Html.LabelFor(item => item.CallBAckDate, "Call Back Date")
</div>
<div class="editor-label">
@Html.TextBoxFor(item => item.CallBAckDate)
@Html.ValidationMessageFor(item => item.CallBAckDate)
</div>
<p>
<input type="Submit" value="Create" id="Create" />
</p>
</fieldset>
}
</body>
<script type="text/JavaScript">
<!--
function AutoRefresh(t) {
setTimeout("location.reload(true);", t);
}
</script>