private bool checkModelStateCreateEdit(ActionEnumForm action, sys_opc_model item) { if (string.IsNullOrEmpty(item.db.name)) { ModelState.AddModelError("db.name", "required"); } var search = repo.FindAll().Where(d => d.db.name == item.db.name && d.db.id != item.db.id).Count(); if (search > 0) { ModelState.AddModelError("db.name", "existed"); } if (string.IsNullOrEmpty(item.db.id_opcclient)) { ModelState.AddModelError("db.opcclient", "required"); } if (string.IsNullOrEmpty(item.db.opcnode)) { ModelState.AddModelError("db.opcnode", "required"); } var searchnode = repo.FindAll().Where(d => d.db.opcnode == item.db.opcnode && d.db.id_opcclient == item.db.id_opcclient && d.db.id != item.db.id).Count(); if (searchnode > 0) { ModelState.AddModelError("db.opcnode", "existed"); ModelState.AddModelError("db.id_opcclient", "existed"); } return(ModelState.IsValid); }
public async Task <int> insert(sys_opc_model model) { await _context.sys_opcs.AddAsync(model.db); _context.SaveChanges(); return(1); }
public int update(sys_opc_model model) { var db = _context.sys_opcs.Where(d => d.id == model.db.id).FirstOrDefault(); db.opcnode = model.db.opcnode; db.id_opcclient = model.db.id_opcclient; db.name = model.db.name; db.note = model.db.note; db.id_unit = model.db.id_unit; db.update_by = model.db.update_by; db.update_date = model.db.update_date; _context.SaveChanges(); return(1); }
private bool checkModelStateEdit(sys_opc_model item) { return(checkModelStateCreateEdit(ActionEnumForm.edit, item)); }