public string AddDolznostSave(Dolgnost dol) { if (ModelState.IsValid) { try { Dolznost dolznost = new Dolznost() { NameDolznost = dol.dolgnost }; ugtu_db.Dolznost.InsertOnSubmit(dolznost); ugtu_db.SubmitChanges(); return ugtu_db.Dolznost.Where(m => m.NameDolznost == dol.dolgnost).Select(m => m.IDDolznost).First().ToString(); } catch (Exception) { return ("Данная должность уже существует"); } } else { return ("Ошибка. Длина поля больше 100 символов"); } }
//добавление public int AddDolgnostSave(string name) { using (var ugtu_db = new UGTU_DBDataContext()) { Dolznost Dol = new Dolznost() { NameDolznost = name }; ugtu_db.Dolznost.InsertOnSubmit(Dol); ugtu_db.SubmitChanges(); return Dol.IDDolznost; } }
partial void DeleteDolznost(Dolznost instance);
partial void UpdateDolznost(Dolznost instance);
partial void InsertDolznost(Dolznost instance);
public int? AddDolgnost(string name) { using (var ugtu_db = new UGTU_DBDataContext()) { if (name == null) return null; int? idDol = ugtu_db.Dolznost.Where(m => m.NameDolznost.ToLower() == name.ToLower()).Select(m => m.IDDolznost).SingleOrDefault(); if (idDol == 0) { Dolznost D = new Dolznost() { NameDolznost = name }; ugtu_db.Dolznost.InsertOnSubmit(D); ugtu_db.SubmitChanges(); idDol = D.IDDolznost; } return idDol; } }