public JsonResult Create(SysSampleModel model) { if (SysSampleBll.Create(ref errors, model)) { SysLogBLL.WriteServiceLog("虚拟用户", "Id:" + model.ID + ",Name:" + model.Name, "成功", "创建", "样例程序"); return Json(JsonHandler.CreateMessage(1, "插入成功"), JsonRequestBehavior.AllowGet); } else { string ErrorCol = errors.Error; SysLogBLL.WriteServiceLog("虚拟用户", "Id:" + model.ID + ",Name:" + model.Name + "," + ErrorCol, "失败", "创建", "样例程序"); return Json(JsonHandler.CreateMessage(0, "插入失败" + ErrorCol), JsonRequestBehavior.AllowGet); } }
/// <summary> /// 创建一个实体 /// </summary> /// <param name="errors">持久的错误信息</param> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Create(ref ValidationErrors errors,SysSampleModel model) { try { SysSample entity = Rep.GetById(model.ID); if (entity != null) { errors.Add("主键重复"); return false; } entity = new SysSample(); entity.ID = model.ID; entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreatTime = model.CreatTime; if (Rep.Create(entity) == 1) { return true; } else { errors.Add("插入失败"); return false; } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return false; } }
public JsonResult Edit(SysSampleModel model) { if (SysSampleBll.Edit(model)) { return Json(1, JsonRequestBehavior.AllowGet); } else { return Json(0, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 根据ID获得一个实体 /// </summary> /// <param name="id">id</param> /// <returns>实体</returns> public SysSampleModel GetById(string id) { if (IsExist(id)) { SysSample entity = Rep.GetById(id); SysSampleModel model = new SysSampleModel(); model.ID = entity.ID; model.Name = entity.Name; model.Age = entity.Age; model.Bir = entity.Bir; model.Photo = entity.Photo; model.Note = entity.Note; model.CreatTime = entity.CreatTime; return model; } else { return new SysSampleModel(); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="errors">持久的错误信息</param> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Edit(SysSampleModel model) { try { SysSample entity = Rep.GetById(model.ID); if (entity == null) { return false; } entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; if (Rep.Edit(entity) == 1) { return true; } else { return false; } } catch (Exception ex) { //ExceptionHander.WriteException(ex); return false; } }