function updateOrder() {
var count = 10;
var url = '@Url.Action("Update", new { Controller = "CustomerOrders" })';
var customerOrders = new Array();
var data={};
for (var j = 0; j < count; j++) {
data.GoodsValue = $("#Results_" + j + "__GoodsValue").val();
data.Quantity = $("#Results_" + j + "__Quantity").val();
data.ID = $("#Results_" + j + "__ID").val();
data.Comments = $("#Results_" + j + "__Comments").val();
data.PaymentStatus = $("#Results_" + j + "__PaymentStatus").val();
data.Price = $("#Results_" + j + "__Price").val();
customerOrders.push(data);
data={};
}
customerOrders = JSON.stringify({ 'Params': customerOrders });
$.ajax({
contentType:'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: url,
data: customerOrders,
success: function (info) {
.....
},
error: function (e, x) {
.....
}
});
}
public JsonResult Update(List<CustomerOrders> Params)
{
try
{
foreach (var order in Params)
{
var orderInfo = repository.CustomerOrders.Where(i => i.ID == order.ID).FirstOrDefault();
orderInfo.UpdatedBy = User.Identity.Name;
orderInfo.Updated = DateTime.Now;
orderInfo.Quantity = order.Quantity;
orderInfo.GoodsValue = order.GoodsValue;
orderInfo.Comments = order.Comments;
orderInfo.Price = order.Price;
orderInfo.Date = DateTime.Now;
orderInfo.PaymentStatus = order.PaymentStatus;
orderInfo.IsApproved = true;
repository.Update(orderInfo);
}
result.Message = "ثبت سفارش با موفقیت انجام شد.";
result.Successfull = true;
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
result.Successfull = false;
result.Message = ex.Message;
}
return Json(result);
}
برچسب:
نویسنده: خنج