public Tuple <bool, string> SaveModel(t_role sourceModel) { bool result = false; if (sourceModel == null) { return(Tuple.Create(false, "错误的请求对象!")); } if (sourceModel.p_id > 0)//修改 { sourceModel.p_updatetime = DateTime.Now; sourceModel.p_updateuserid = LZY.Code.OperatorProvider.Provider.GetCurrent().UserId; result = _service.Update(sourceModel) > 0; } else//新增 { sourceModel.p_createtime = DateTime.Now; sourceModel.p_deleted = false; sourceModel.p_createuserid = LZY.Code.OperatorProvider.Provider.GetCurrent().UserId; result = _service.Insert(sourceModel) > 0; } if (result) { return(Tuple.Create(true, "操作成功!")); } else { return(Tuple.Create(false, "操作失败!")); } }
public static ResponResultViewModel Deactive(RoleViewModel entity, long userid) { //untuk deactive ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_role role = db.t_role.Where(x => x.id == entity.id).FirstOrDefault(); if (role != null) { role.active = false; role.modified_by = userid; role.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.Message = "user not found!"; } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public ActionResult RoleInfo(int?id) { t_role model = new t_role(); if (id.GetValueOrDefault() > 0) { model = _bus.FindModel(id); } return(View(model)); }
public static ResponResultViewModel Update(RoleViewModel entity, long userid) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); entity.code = GetNewRole(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_role role = new t_role(); role.code = entity.code; role.name = entity.name; role.description = entity.description; role.created_by = userid; role.created_on = DateTime.Now; role.active = entity.active; db.t_role.Add(role); db.SaveChanges(); result.Entity = role; } else { t_role role = db.t_role.Where(x => x.id == entity.id).FirstOrDefault(); if (role != null) { role.name = entity.name; role.description = entity.description; role.modified_by = userid; role.modified_on = DateTime.Now; role.active = entity.active; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
public ActionResult RoleSave(t_role model) { if (ModelState.IsValid) { var result = _bus.SaveModel(model); if (result.Item1) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", result.Item2); return(View("Info", model)); } } else { return(View("Info", model)); } }
public static ResponseResult Update(RoleViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //CREATE if (entity.id == 0) { t_role rol = new t_role(); rol.code = entity.code; //sesuai yg kita input di web rol.name = entity.name; rol.description = entity.description; rol.is_deleted = entity.is_delete; rol.created_by = entity.UserId; rol.created_on = DateTime.Now; db.t_role.Add(rol); db.SaveChanges(); object data = new { rol.id, rol.code, rol.name, rol.description }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Insert"; log.json_insert = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); entity.id = rol.id; result.Entity = entity; } else //EDIT { t_role rol = db.t_role .Where(o => o.id == entity.id) .FirstOrDefault(); if (rol != null) { object data = new { rol.id, rol.code, rol.name, rol.description }; var json = new JavaScriptSerializer().Serialize(data); t_audit_log log = new t_audit_log(); log.type = "Modify"; log.json_before = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; rol.code = entity.code; rol.name = entity.name; rol.description = entity.description; rol.modified_by = entity.UserId; rol.modified_on = DateTime.Now; object data2 = new { rol.id, rol.code, rol.name, rol.description }; var json2 = new JavaScriptSerializer().Serialize(data2); log.json_after = json2; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Role not found!"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }