public ActionResult UpdateTmcListChildrens([DataSourceRequest] DataSourceRequest request, TmcOffViewModel dictionary) { EXP_DrugDeclaration drugDeclaration = null; if (dictionary.RefExtertiseStatement != null) { drugDeclaration = db.EXP_DrugDeclaration .FirstOrDefault(d => d.Id == dictionary.RefExtertiseStatement.Value); } TmcOff tmcOff = db.TmcOffs.First(o => o.Id == dictionary.Id); tmcOff.StateType = dictionary.StateType; tmcOff.CreatedDate = dictionary.CreatedDate; tmcOff.Count = dictionary.Count; tmcOff.Note = dictionary.Note; tmcOff.StateType = dictionary.StateType; if (drugDeclaration != null) { tmcOff.ExpertiseStatementId = dictionary.RefExtertiseStatement; tmcOff.ExpertiseStatementNumber = drugDeclaration.Number; tmcOff.ExpertiseStatementTypeStr = drugDeclaration.EXP_DIC_Type.NameRu; } db.SaveChanges(); var item = db.TmcOffViews.First(o => o.Id == tmcOff.Id); dictionary.CreatedEmployeeValue = item.CreatedEmployeeValue; return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState))); }
public ActionResult CreateTmcListChildrens([DataSourceRequest] DataSourceRequest request, TmcOffViewModel dictionary) { string expertiseNumber = null; if (dictionary.RefExtertiseStatement != null) { expertiseNumber = db.Documents.Where(d => d.Id == dictionary.RefExtertiseStatement.Value) .Select(d => d.Number) .FirstOrDefault(); } TmcOff tmc = new TmcOff() { Id = Guid.NewGuid(), StateType = dictionary.StateType, CreatedDate = DateTime.Now, CreatedEmployeeId = UserHelper.GetCurrentEmployee().Id, Count = dictionary.Count, Note = dictionary.Note, TmcOutId = Guid.Parse(dictionary.TmcOutIdString), ExpertiseStatementId = dictionary.RefExtertiseStatement, ExpertiseStatementNumber = expertiseNumber }; db.TmcOffs.Add(tmc); db.SaveChanges(); dictionary.Id = tmc.Id; var item = db.TmcOffViews.First(o => o.Id == tmc.Id); dictionary.CreatedEmployeeValue = item.CreatedEmployeeValue; dictionary.StateTypeValue = "На списании"; return(Json(new[] { dictionary }.ToDataSourceResult(request, ModelState))); }