public async Task <JsonResult> saveClassification(ClassificationVM model) { if (model.Id == 0) { //if (ModelState.IsValid) //{ model.InsertDate = DateTime.UtcNow; model.InsertUser = USERNAME; var newObjectForSave = mapper.Map <Classification>(model); var result = await classification.AddAndLogAsync(newObjectForSave, USERNAME); if (result > 0) { return(Json(new { status = JsonStatus.Success, link = "جيد", color = NotificationColor.success.ToString().ToLower(), msg = "تم الحفظ بنجاح", ObjectID = newObjectForSave.Id })); } else { return(Json(new { status = JsonStatus.Error, link = "يوجد خطا", color = NotificationColor.error.ToString().ToLower(), ObjectID = newObjectForSave.Id, msg = "يوجد خطا في عملية الحفظ", })); } //} //return Json(new //{ // status = JsonStatus.Error, // link = "", // color = NotificationColor.error.ToString().ToLower(), // msg = ModelState.Keys.SelectMany(k => ModelState[k].Errors) // .Select(m => m.ErrorMessage).ToArray() //}); } else { if (ModelState.IsValid) { var getClassifiction = await classification.GetAsync(x => x.Id == model.Id); var firstClassifiction = getClassifiction.FirstOrDefault(); firstClassifiction.ClassificationName = model.ClassificationName; firstClassifiction.UpdateUser = USERNAME; firstClassifiction.UpdatedDate = DateTime.UtcNow; var result = await classification.UpdateAndLogAsync(firstClassifiction, USERNAME); if (result > 0) { return(Json(new { status = JsonStatus.Success, link = "جيد", color = NotificationColor.success.ToString().ToLower(), msg = "تم الحفظ نجاح", ObjectID = model.Id })); } else { return(Json(new { status = JsonStatus.Error, link = "يوجد خطا", color = NotificationColor.error.ToString().ToLower(), ObjectID = model.Id, msg = "يوجد خطا في عملية الحفظ", })); } } return(Json(new { status = JsonStatus.Error, link = "", color = NotificationColor.error.ToString().ToLower(), msg = ModelState.Keys.SelectMany(k => ModelState[k].Errors) .Select(m => m.ErrorMessage).ToArray() })); } }