public ActionResult ResearchSample(int id = 0) { var model = new ResearchSampleViewModel { SampleId = id, SampleName = _dataManager.Samples.GetSampleByNumber(id).Name }; return(View(model)); }
public ActionResult ResearchSample(ResearchSampleViewModel model) { if (!ModelState.IsValid) { return(View(model)); } //Получение внешних ключей для записи в таблицу результатов int employeeId = _dataManager.Employees.AddEmployee(model.EmployeeFirstName, model.EmployeeLastName, model.EmployeeMiddleName, model.EmployeePost, "токсикология"); int gageId = _dataManager.Gages.AddGage(model.GageName, model.GageSerialNumber); int techniqueOfTestId = _dataManager.TechnicalRegulations.AddTechnicalRegulation(model.TechniqueOfTestDesignation, model.TechniqueOfTestName); int indicatorId = _dataManager.Indicators.AddIndicator(model.Indicator, model.Units); //Получение внешнего ключа таблицы "Допустимые уровни" int normativeDocumentId = _dataManager.TechnicalRegulations.AddTechnicalRegulation(model.NormativeDocumentDesignation, model.NormativeDocumentName); int levelId = _dataManager.AdmissibleLevels.AddAdmissibleLevel(model.AdmissibleLever, indicatorId, normativeDocumentId); //Добавление данных в таблицу результатов int resultId = _dataManager.Results.AddResult(model.Result, DateTime.Now, indicatorId, levelId, techniqueOfTestId, gageId, model.SampleId, employeeId); Direction direction = _dataManager.Directions.GetDirectionBySampleIdAndDepartment(model.SampleId, "токсикология"); if (direction != null) { direction.State = "выполнено"; _dataManager.Directions.SaveDirection(direction); } //Добавление условий исследований indicatorId = _dataManager.Indicators.AddIndicator("температура", "градус Цельсия"); _dataManager.Conditions.CreateCondition(DateTime.Now, model.Temperature, indicatorId, resultId); indicatorId = _dataManager.Indicators.AddIndicator("влажность", "процент"); _dataManager.Conditions.CreateCondition(DateTime.Now, model.Humidity, indicatorId, resultId); indicatorId = _dataManager.Indicators.AddIndicator("атмосферное давление", "килопаскаль"); _dataManager.Conditions.CreateCondition(DateTime.Now, model.Pressure, indicatorId, resultId); indicatorId = _dataManager.Indicators.AddIndicator("мощность экспозиционной дозы", "микрозиверт в час"); _dataManager.Conditions.CreateCondition(DateTime.Now, model.Radiation, indicatorId, resultId); return(RedirectToAction("Results")); }