public ActionResult CreateForGrid([DataSourceRequest] DataSourceRequest request, TestDatesViewModel testsdates, long _testid) { if (!db.TESTS.Get().Any(t => t.ID == _testid)) { ModelState.AddModelError("TESTDATES", "Невозможно добавить данный период!<br> Ошибка: Тест не обнаружен в базе данных!"); } CheckingErrors(testsdates); if (ModelState.IsValid) { testsdates.testid = _testid; TESTDATES entity = testsdates.ToEntity(new TESTDATES()); try { db.TESTSDATES.Create(entity); testsdates.id = entity.ID; } catch (Exception ex) { ModelState.AddModelError("TESTDATES", ex.Message); } } return(Json(new[] { testsdates }.ToDataSourceResult(request, ModelState))); }
public ActionResult UpdateForGrid([DataSourceRequest] DataSourceRequest request, TestDatesViewModel testsdates) { TESTDATES entity = db.TESTSDATES.Get().FirstOrDefault(t => t.ID == testsdates.id); if (entity == null) { ModelState.AddModelError("TESTDATES", String.Format("Период не обнаружен в базе данных!")); } CheckingErrors(testsdates); if (ModelState.IsValid) { entity = testsdates.ToEntity(entity); try { db.TESTSDATES.Update(entity); } catch (Exception ex) { ModelState.AddModelError("TESTDATES", ex.Message); } } return(Json(new[] { testsdates }.ToDataSourceResult(request, ModelState))); }
public TESTDATES ToEntity(TESTDATES testdates) { testdates.ID = this.id; testdates.BEGIN = this.begin; testdates.END = this.end; testdates.TESTID = this.testid; return(testdates); }