public JsonResult Save(DepartmentEntity newObj) { JsonResult result = new JsonResult(); try { string strUserId = HttpContext.ApplicationInstance.Context.Request.Cookies["UserId"].Value; if (string.IsNullOrEmpty(newObj.DepId)) { string Condition = " and DepName='" + newObj.DepName + "'"; int itemCount = depLogic.Count(Condition); if (itemCount > 0) { string json = JsonHelper.RtnJson("300", "此名称已经存在!"); return(Json(json)); } newObj.DepId = strUserId + "-Dep-" + DateTime.Now.ToString("yyMMddHHmmssff"); // SetOrgCode(newObj.UpperId, OrgId); newObj.CreateDate = DateTime.Now; newObj.UpdateDate = DateTime.Now; newObj.CreateUser = strUserId; newObj.DepTypeName = "部门"; newObj.DepType = "部门"; newObj.Flag = (newObj.Flag == null ? "0" : newObj.Flag); bool isOK = depLogic.Save(newObj); if (isOK == true) { string json = JsonHelper.RtnJson("100", ""); return(Json(json)); } else { string json = JsonHelper.RtnJson("200", ""); return(Json(json)); } } else { newObj.UpdateDate = DateTime.Now; newObj.UpdateUser = strUserId; newObj.Flag = (newObj.Flag == null ? "0" : newObj.Flag); bool isOK = depLogic.Update(newObj); if (isOK == true) { return(Json("ok")); } else { return(Json("no")); } } } catch { return(Json("no")); } }
//modification d'entité avec fourniture de l'Id obligatoire public ActionResult <DepartmentDTO> Put([FromBody] DepartmentDTO objet) { if (ModelState.IsValid && objet.Id.HasValue) { try { DepartmentDTO resultat = _logic.Update(objet); return(resultat); } catch { return(null); } } else { return(BadRequest("DepartmentDTO invalide")); } }