public void Linking(DrugCourseLinkingBindingModel model) { var drugCourse = _drugCourseStorage.GetElement(new DrugCourseBindingModel { Id = model.DrugCourseId }); var medicine = _medicineStorage.GetElement(new MedicineBindingModel { Id = model.MedicineId }); if (drugCourse == null) { throw new Exception("Не найдена выдача"); } if (medicine == null) { throw new Exception("Не найдено выписка"); } if (drugCourse.MedicineId.HasValue) { throw new Exception("Данное лекарство уже привязано к симптоматике"); } _drugCourseStorage.Update(new DrugCourseBindingModel { Id = drugCourse.Id, Length = drugCourse.Length, FormedDate = drugCourse.FormedDate, DrugCourseDiseases = drugCourse.DrugCourseDiseases, DoctorId = drugCourse.DoctorId, MedicineId = model.MedicineId }); _medicineStorage.Update(new MedicineBindingModel { Id = medicine.Id, Class = medicine.Class, Name = medicine.Name, DrugCourseId = model.DrugCourseId }); }
public void CreateOrUpdate(MedicineBindingModel model) { var element = _medicineStorage.GetElement(new MedicineBindingModel { Name = model.Name }); if (element != null && element.Id != model.Id) { throw new Exception("Уже есть лекарство с таким названием"); } if (model.Id.HasValue) { _medicineStorage.Update(model); } else { _medicineStorage.Insert(model); } }