private bool Save() { try { if (dgvLeft.Rows.Count == 0) { MessageBox.Show("Нельзя создать пустую ведомость!", "Внимание"); return(false); } using (PriemEntities context = new PriemEntities()) { using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { if (_Id == null) { ObjectParameter vedParId = new ObjectParameter("id", typeof(Guid)); context.ExamsVed_Insert(studyLevelGroupId, facultyId, studyBasisId, passDate.Date, examId, false, false, isAddVed, (isAddVed ? addCount : null), vedParId); _Id = (Guid)vedParId.Value; } else { if (dtPassDate.Value.Date != passDate.Date) { int cnt = (from vd in context.extExamsVed where vd.ExamId == examId && vd.Date == dtPassDate.Value.Date && vd.FacultyId == facultyId && (studyBasisId == null ? vd.StudyBasisId == null : vd.StudyBasisId == studyBasisId) select vd).Count(); if (cnt > 0) { WinFormsServ.Error(string.Format("Ведомость на этот экзамен на эту дату {0} уже существует! ", studyBasisId == null ? "" : "на эту основу обучения")); return(false); } } context.ExamsVedHistory_DeleteByVedId(_Id); if (dtPassDate.Value.Date != passDate.Date) { context.ExamsVed_UpdateDate(dtPassDate.Value.Date, _Id); } } //записи в ведомостьхистори foreach (DataGridViewRow r in dgvLeft.Rows) { Guid?persId = new Guid(r.Cells["Id"].Value.ToString()); context.ExamsVedHistory_InsertToVed(_Id, persId); } transaction.Complete(); return(true); } } } catch (Exception ex) { WinFormsServ.Error("Ошибка при создании новой ведомости: " + ex.Message); return(false); } }