private bool checkModelStateCreateEdit(ActionEnumForm action, sys_customer_model item) { if (string.IsNullOrEmpty(item.db.name)) { ModelState.AddModelError("db.name", "required"); } if (string.IsNullOrEmpty(item.db.tax_number)) { ModelState.AddModelError("db.tax_number", "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"); } var searchTax = repo.FindAll().Where(d => d.db.tax_number == item.db.tax_number && d.db.id != item.db.id).Count(); if (search > 0) { ModelState.AddModelError("db.tax_number", "existed"); } return(ModelState.IsValid); }
public async Task <int> insert(sys_customer_model model) { await _context.sys_customers.AddAsync(model.db); _context.SaveChanges(); return(1); }
public int update(sys_customer_model model) { var db = _context.sys_customers.Where(d => d.id == model.db.id).FirstOrDefault(); db.name = model.db.name; db.note = model.db.note; db.address = model.db.address; db.email = model.db.email; db.phone = model.db.phone; db.fax = model.db.fax; db.logo_path = model.db.logo_path; db.tax_number = model.db.tax_number; db.update_by = model.db.update_by; db.update_date = model.db.update_date; db.is_supplier = model.db.is_supplier ?? false; db.is_customer = model.db.is_customer ?? false; _context.SaveChanges(); return(1); }
private bool checkModelStateEdit(sys_customer_model item) { return(checkModelStateCreateEdit(ActionEnumForm.edit, item)); }