public JsonResult SaveData(string strDevise) { JavaScriptSerializer serializer = new JavaScriptSerializer(); Devise_DTO devise = serializer.Deserialize <Devise_DTO>(strDevise); bool status = false; string message = string.Empty; //add new employee if id = 0 if (devise.codeDevise == null) { status = false; } else { if (devise.Id == 0) { try { _DeviseAppService.Add(devise); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } else { //update existing DB //save db var entity = _DeviseAppService.GetById(devise.Id); entity.codeDevise = devise.codeDevise; entity.Designation = devise.Designation; entity.nb = devise.nb; entity.decimale = devise.decimale; entity.Id = devise.Id; try { _DeviseAppService.Update(entity); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } } return(Json(new { status = status, message = message })); }
public ActionResult Add(Devise_DTO obj) { if (!ModelState.IsValid) { return(Json(false)); } else { _DeviseAppService.Add(obj); return(Json(true)); } }