private void btnSaveToSvr_Click(object sender, EventArgs e) { if (MsgBox.ShowYesNoMessage("", "确定要保存菜单至服务器?") == System.Windows.Forms.DialogResult.No) { return; } using (var db = new Database()) { var mnu = db.FirstOrDefault <t_menu>("select * from t_menu"); if (mnu == null) { mnu = new t_menu { Guid = Guid.NewGuid(), Version = "1.0", MenuXml = BuildMenuXml(), CreateDate = TimeSync.Default.CurrentSyncTime }; } else { mnu.MenuXml = BuildMenuXml(); } db.Save(mnu); } MsgBox.ShowMessage("", "保存成功!"); }
public static ResponResultViewModel Deactive(MenuViewModel entity, long userid) { //untuk deactive ResponResultViewModel result = new ResponResultViewModel(); try { using (var db = new MinProContext()) { t_menu menu = db.t_menu.Where(x => x.id == entity.id).FirstOrDefault(); if (menu != null) { menu.active = false; menu.modified_by = userid; menu.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 static ResponseResult Delete(MenuViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { t_menu menu = db.t_menu.Where(o => o.id == entity.id).FirstOrDefault(); if (menu != null) { var Serial = new JavaScriptSerializer(); object data = new { menu.id, menu.image_url, menu.title, menu.code }; var json = Serial.Serialize(data); menu.is_delete = true; menu.deleted_by = entity.UserId; menu.deleted_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; db.SaveChanges(); t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_delete = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Category not found"; } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
public static ResponResultViewModel Update(MenuViewModel entity, long userid) { //untuk create & edit ResponResultViewModel result = new ResponResultViewModel(); entity.code = GetNewMenu(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_menu menu = new t_menu(); menu.code = entity.code; menu.title = entity.title; menu.description = entity.description; menu.image_url = entity.image_url; menu.menu_order = entity.menu_order; menu.menu_parent = entity.menu_parent; menu.menu_url = entity.menu_url; menu.created_by = userid; menu.created_on = DateTime.Now; menu.active = entity.active; db.t_menu.Add(menu); db.SaveChanges(); result.Entity = menu; } else { t_menu menu = db.t_menu.Where(x => x.id == entity.id).FirstOrDefault(); if (menu != null) { menu.title = entity.title; menu.description = entity.description; menu.image_url = entity.image_url; menu.menu_order = entity.menu_order; menu.menu_parent = entity.menu_parent; menu.menu_url = entity.menu_url; menu.created_by = userid; menu.created_on = DateTime.Now; menu.active = entity.active; db.SaveChanges(); result.Entity = entity; } } } } catch (Exception e) { result.Success = false; result.Message = e.Message; } return(result); }
// POST: api/MenuPublicar public void Post([FromBody] MenuRegistrarRequest request) { try { t_menu tMenu = BD.t_menu.FirstOrDefault(x => x.menu_id == request.Menu.menu_id); tMenu.menu_publicado = request.Menu.menu_publicado; BD.SaveChanges(); } catch (Exception err) { throw err; } }
// DELETE: api/ListaPrecio/5 public void Delete(int id) { try { t_menu tMenu = BD.t_menu.FirstOrDefault(x => x.menu_id == id); if (tMenu != null) { BD.t_menu.Remove(tMenu); } BD.SaveChanges(); } catch (Exception err) { throw err; } }
private void MenuView_Load(object sender, EventArgs e) { t_menu mnu; using (var db = new Database()) { mnu = db.FirstOrDefault <t_menu>("select * from t_menu"); if (null == mnu || string.IsNullOrEmpty(mnu.MenuXml)) { treeCtl1.ClearNodes(); mnu = new t_menu { MenuXml = BuildMenuXml(), Version = "1.0" }; } } //解析菜单XML treeCtl1.ClearNodes(); ExtractMenu(mnu.MenuXml); }
private void btnSaveToSvr_Click(object sender, EventArgs e) { if (MsgBox.ShowYesNoMessage("", "确定要保存菜单至服务器?") == System.Windows.Forms.DialogResult.No) { return; } var menus = BuildMenuList(); try { Db.Execute("delete t_menu where Version = '1.0'"); var menu = new t_menu { CreateDate = TimeSync.Default.CurrentSyncTime, MenuJson = ObjectHelper.SerializeJson(menus), Version = "1.0", }; Db.Insert(menu); MsgBox.ShowMessage("", "保存成功!"); } catch (Exception) { throw; } }
// POST: api/ListaPrecio public IHttpActionResult Post([FromBody] MenuRegistrarRequest request) { MenuRegistrarResponse objresponse = new MenuRegistrarResponse(); objresponse.status = new ProcesoResponse(); try { t_menu tMenu = new t_menu(); tMenu.menu_estado = request.Menu.menu_estado; tMenu.menu_nombre = request.Menu.menu_nombre; tMenu.menu_publicado = request.Menu.menu_publicado; tMenu.menu_ruc = request.Menu.menu_ruc; BD.t_menu.Add(tMenu); BD.SaveChanges(); objresponse.Menu = request.Menu; objresponse.Menu.menu_id = tMenu.menu_id; objresponse.status.estado = 0; objresponse.status.mensaje = "Registrado con exito"; } catch (Exception err) { objresponse.status.estado = -1; objresponse.status.mensaje = err.Message; throw err; } return(Ok(objresponse)); }
private void MenuView_Load(object sender, EventArgs e) { t_menu mnu; using (var db = new Database()) { mnu = db.FirstOrDefault<t_menu>("select * from t_menu"); if (null == mnu || string.IsNullOrEmpty(mnu.MenuXml)) { treeCtl1.ClearNodes(); mnu = new t_menu { MenuXml = BuildMenuXml(), Version = "1.0" }; } } //解析菜单XML treeCtl1.ClearNodes(); ExtractMenu(mnu.MenuXml); }
private void btnSaveToSvr_Click(object sender, EventArgs e) { if (MsgBox.ShowYesNoMessage("", "确定要保存菜单至服务器?") == System.Windows.Forms.DialogResult.No) return; using (var db = new Database()) { var mnu = db.FirstOrDefault<t_menu>("select * from t_menu"); if (mnu == null) { mnu = new t_menu { Guid = Guid.NewGuid(), Version = "1.0", MenuXml = BuildMenuXml(), CreateDate = TimeSync.Default.CurrentSyncTime }; } else { mnu.MenuXml = BuildMenuXml(); } db.Save(mnu); } MsgBox.ShowMessage("", "保存成功!"); }
public static ResponseResult Update(MenuViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { if (entity.id == 0) { t_menu menu = new t_menu(); menu.code = getCode(); menu.title = entity.title; menu.descriptoin = entity.descriptoin; menu.image_url = entity.image_url; menu.menu_parent = entity.menu_parent; menu.menu_url = entity.menu_url; menu.created_by = entity.UserId; menu.created_on = DateTime.Now; menu.is_delete = false; db.t_menu.Add(menu); db.SaveChanges(); var json = new JavaScriptSerializer().Serialize(menu); 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 = menu.id; result.Entity = entity; } else { t_menu menu = db.t_menu.Where(o => o.id == entity.id).FirstOrDefault(); if (menu != null) { var Serial = new JavaScriptSerializer(); object data = new { menu.title, menu.descriptoin, menu.image_url, menu.menu_url, menu.menu_order, menu.menu_parent }; var json = Serial.Serialize(data); menu.title = entity.title; menu.descriptoin = entity.descriptoin; menu.image_url = entity.image_url; menu.menu_url = entity.menu_url; menu.menu_order = entity.menu_order; menu.menu_parent = entity.menu_parent; menu.modified_by = entity.UserId; menu.modified_on = DateTime.Now; db.SaveChanges(); result.Entity = entity; object data2 = new { menu.title, menu.descriptoin, menu.image_url, menu.menu_url, menu.menu_order, menu.menu_parent }; t_audit_log log = new t_audit_log(); log.type = "MODIFY"; log.json_before = json; json = Serial.Serialize(data2); log.json_after = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); result.Entity = entity; } else { result.Success = false; result.ErrorMessage = "Category not found"; } } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }
private void btnSaveToSvr_Click(object sender, EventArgs e) { if (MsgBox.ShowYesNoMessage("", "确定要保存菜单至服务器?") == System.Windows.Forms.DialogResult.No) return; var menus = BuildMenuList(); try { Db.Execute("delete t_menu where Version = '1.0'"); var menu = new t_menu { CreateDate = TimeSync.Default.CurrentSyncTime, MenuJson = ObjectHelper.SerializeJson(menus), Version = "1.0", }; Db.Insert(menu); MsgBox.ShowMessage("", "保存成功!"); } catch (Exception) { throw; } }