恥ずかしそうに手に負えなくなっている問題があります。
私はMVCとEFを使用しており、ユーザーが編集できるモデルを持っています。編集した場合、編集したプロパティが他のユーザーに表示されるようにビューに赤で表示されるという新しい要件があります。
私のモデルには多くのプロパティがありますが、主キーはGUID
であり、モデルには複数parentID
のを含めることができます。したがって、ある特定のプロパティについて、変更されたプロパティを見つけたいと思いますGUID
。ParentID
これまでのところ、これは間違っていると感じていますが、私のビューには次のようなjqueryがあります
$("[name*='Request.']")
.not(":hidden")
.each(function () {
var $this = $(this);
$.ajax({
url: '@Url.Action("IsChanged", "Shared")',
data: { fieldName: $this.attr("name"), parentID: @Model.Request.ID },
success: function (data) {
if (data) {
if ($this.is(":radio")) {
$this.parent().addClass("isChanged");
} else
$this.addClass("isChanged");
}
}
});
});
このスクリプトは、ajax関数からtrueを返すだけで試してみると、正常に機能します。ただし、問題となるのはajax関数です。変更を見つけるにはどうすればよいですか?私がこれまでに得たものはこれです:
public ActionResult IsChanged(string fieldName, int parentID)
{
using (MyEntities _db = new MyEntities())
{
string[] aName = fieldName.Split('.');
// Count the number of version
int versionCount = _db.SubRequests.Count(r => r.ParentID == parentID);
// Get the first version
SubRequest sr = _db.SubRequests.FirstOrDefault(r => r.ParentID == parentID);
// Check if the count is the same for the specific value
int changeCount = _db.ExecuteStoreQuery<int>("select count(parentID) from "+aName[0]+" where parentID = " + parentID + " and " + aName[1] +"='{0}'", THEVALUEINORIGINAL);
bool isChanged = changeCount == versionCount;
return Json(isChanged, JsonRequestBehavior.AllowGet);
}
}
私がこれまでに行ったことは正しくないと感じており、明らかにこれは機能しませんが、私は道に迷っています。
これが理解できるかどうか、またはさらに情報が必要な場合はお知らせください。このアイデアを破棄して、まったく異なるものを構築する必要がありますか(おそらく)、それとも私を救う方法はありますか?