Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I went ahead and implemented the 1st option of the answer. </p> <p>It would of definitely been easier to stick to the traditional add and edit scenarios, and made use of the standard asp mvc pattern. But it was a good learning experience. </p> <p>Heres the code and markup, it still needs some more work but you get the idea. Any comments/suggestion would be appreciated. </p> <pre><code> function validate() { // Need to do form validation var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/validate" , balance , function (data) { if (data.valid) { $("#existCheck").val("Valid"); checkBalanceExist(); } else { $("#existCheck").val("Not Valid"); $("#errorMessage").text(data.message); } } , 'json' ); }; function checkBalanceExist() { $("#existCheck").val($("#bal_Date").val()); // Do ajax call to see if balance exist var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/doesBalanceExist" , balance , balanceCheckPost , 'json' ); }; balanceCheckPost = function (data) { $("#existCheck").val(data); if (data) { // Does Exist $("#existCheck").val("Exist"); // raise confirmation popup $('#dialog').dialog('open'); } else { // Does Not Exist $("#existCheck").val("NOT Exist"); // insert Item var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/insert", balance, confirmChange ); } }; function overWriteBalance() { // insert Item var balance = {}; balance.date = $("#bal_Date").val(); balance.amount = $("#bal_Amount").val(); $.post("balance/edit", balance, confirmChange ); }; confirmChange = function () { $("#existCheck").val("Changed"); }; </code></pre> <p>and</p> <pre><code> public JsonResult validate(Balance bal) { if (ModelState.IsValid) { return Json(new { valid = true }); } else { var errorMessage = ""; foreach (var key in ModelState.Keys) { errorMessage += ModelState[key].Errors.FirstOrDefault().ErrorMessage; } return Json(new { valid = false, message = errorMessage }); } } public JsonResult doesBalanceExist(Balance bal) { var dataContext = new DataDataContext(); return Json(dataContext.Balances.ToList().Contains(bal, new BalanceEquality())); } public ActionResult Index() { var dataContext = new DataDataContext(); compModel myModel = new compModel(); myModel.bal = new Balance(); myModel.allBalances = dataContext.Balances.OrderBy(bal =&gt; bal.Date).ToList(); return View(myModel); } [HttpPost] public ActionResult Index(Balance bal) { var dataContext = new DataDataContext(); compModel myModel = new compModel(); myModel.bal = new Balance(); myModel.allBalances = dataContext.Balances.OrderBy(ball =&gt; ball.Date).ToList(); return View(myModel); } public void insert(Balance bal) { var dataContext = new DataDataContext(); dataContext.Balances.InsertOnSubmit(bal); dataContext.SubmitChanges(); } public void edit(Balance bal) { var dataContext = new DataDataContext(); var balToEdit = dataContext.Balances.Single(b =&gt; b.Date == bal.Date); balToEdit.Amount = bal.Amount; dataContext.SubmitChanges(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload