public int InsertJournalContent(JournalContent content) { return(TryFunc <int>(() => { int id = 0; using (EGESupportEntities context = new EGESupportEntities()) { ppe_exams ppe_exam = (from p in context.ppe_exams where (p.exam_date_id == content.exam_date_id) && (p.ppe_id == content.ppe_id) select p).FirstOrDefault(); int ppe_exam_id; if (ppe_exam == null) { ppe_exams p = new ppe_exams() { exam_date_id = content.exam_date_id, ppe_id = content.ppe_id }; context.ppe_exams.Add(p); context.SaveChanges(); ppe_exam_id = p.id; } else { ppe_exam_id = ppe_exam.id; int double_rec = (from jour in context.journals where jour.ppe_exam_id == ppe_exam_id && jour.blank_type_id == content.blank_type_id && jour.auditorium == content.aud && jour.id != content.id select jour.id).Count(); if (double_rec > 0) { throw new FaultException <Fault>(new Fault() { Token = "error", Message = "В базу данных уже внесена запись с аналогичным ППЭ, ауд и типом бланка" }, "soap error"); } } journals j = new journals(); j.ppe_exam_id = ppe_exam_id; j.blank_type_id = content.blank_type_id; j.auditorium = content.aud; j.count_blanks = content.count_blanks; j.count_add_blanks = content.blank_type_id == 3 ? content.count_add_blanks : 0; context.journals.Add(j); context.SaveChanges(); id = j.id; } return id; })); }
public bool DeletePPEExamBlank(PPEExamBlank exam_blanks) { return(TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { IEnumerable <journals> jours = context.journals.Where(x => x.ppe_exam_id == exam_blanks.ppe_exam_id && x.auditorium == exam_blanks.aud); context.journals.RemoveRange(jours); context.SaveChanges(); res = true; } return res; })); }
public int InsertPPEExamBlank(PPEExamBlank exam_blanks) { return(TryFunc <int>(() => { int aud = exam_blanks.aud; using (EGESupportEntities context = new EGESupportEntities()) { if (exam_blanks.count_r > 0) { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 1, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_r, count_add_blanks = 0 }); } if (exam_blanks.count_1 > 0) { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 2, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_1, count_add_blanks = 0 }); } if (exam_blanks.count_2 > 0) { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 3, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_2, count_add_blanks = exam_blanks.count_add_2 }); } context.SaveChanges(); } return aud; })); }
public void ChangeStatusPPEExam(int ppe_exam_id, int status_id) { TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { ppe_exams p = new ppe_exams() { id = ppe_exam_id }; context.ppe_exams.Attach(p); p.status_id = status_id; context.SaveChanges(); res = true; } return(res); }); }
public void SetIsUploadPPEExam(int ppe_exam_id) { TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { ppe_exams p = new ppe_exams() { id = ppe_exam_id }; context.ppe_exams.Attach(p); p.is_upload_data = true; context.SaveChanges(); res = true; } return(res); }); }
public bool DeleteJournalContent(int id) { return(TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { journals j = new journals() { id = id }; context.journals.Attach(j); context.journals.Remove(j); context.SaveChanges(); res = true; } return res; })); }
public void SendPPEMessage(PPEExamMessage mes) { TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { ppe_messages m = new ppe_messages() { user_id = mes.user_id, ppe_exam_id = mes.ppe_exam_id, mes_date = DateTime.Now, message = mes.message }; context.ppe_messages.Add(m); context.SaveChanges(); res = true; } return(res); }); }
public void UpdatePPEExamBlank(PPEExamBlank exam_blanks, int old_aud) { TryFunc <bool>(() => { bool res = false; using (EGESupportEntities context = new EGESupportEntities()) { IEnumerable <journals> jours = (from j in context.journals where j.ppe_exam_id == exam_blanks.ppe_exam_id && j.auditorium == old_aud select j); journals jour = jours.Where(x => x.blank_type_id == 1).SingleOrDefault(); if (exam_blanks.count_r > 0) { if (jour != null) { jour.auditorium = exam_blanks.aud; jour.count_blanks = exam_blanks.count_r; } else { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 1, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_r, count_add_blanks = 0 }); } } else { if (jour != null) { context.journals.Remove(jour); } } jour = jours.Where(x => x.blank_type_id == 2).SingleOrDefault(); if (exam_blanks.count_1 > 0) { if (jour != null) { jour.auditorium = exam_blanks.aud; jour.count_blanks = exam_blanks.count_1; } else { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 2, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_1, count_add_blanks = 0 }); } } else { if (jour != null) { context.journals.Remove(jour); } } jour = jours.Where(x => x.blank_type_id == 3).SingleOrDefault(); if (exam_blanks.count_2 > 0) { if (jour != null) { jour.auditorium = exam_blanks.aud; jour.count_blanks = exam_blanks.count_2; jour.count_add_blanks = exam_blanks.count_add_2; } else { context.journals.Add(new journals() { ppe_exam_id = exam_blanks.ppe_exam_id, blank_type_id = 3, auditorium = exam_blanks.aud, count_blanks = exam_blanks.count_2, count_add_blanks = exam_blanks.count_add_2 }); } } else { if (jour != null) { context.journals.Remove(jour); } } context.SaveChanges(); res = true; } return(res); }); }
public PPEExamContent GetPPEExamContent(int exam_date_id, int ppe_id) { return(TryFunc <PPEExamContent>(() => { PPEExamContent res = new PPEExamContent(); res.exam_date_id = exam_date_id; res.ppe_id = ppe_id; using (EGESupportEntities context = new EGESupportEntities()) { var exam = (from e in context.exam_dates join s in context.subjects on e.subject_id equals s.id where e.id == exam_date_id select e).SingleOrDefault(); res.exam_date = "Выгрузка за " + exam.exam_date.ToString("dd.MM.yyyy") + " ЕГЭ " + [email protected]() + " класс (" + exam.subjects.name + ")"; ppe cur_ppe = (from p in context.ppe join a in context.areas on p.area_id equals a.id where p.id == ppe_id select p).SingleOrDefault(); res.ppe_name = "Код ППЭ: " + cur_ppe.ppe_code + " - " + cur_ppe.name + " (" + cur_ppe.areas.name + ")"; res.ppe_code = cur_ppe.ppe_code; ppe_exams ppe_exam = (from p in context.ppe_exams where p.exam_date_id == exam_date_id && p.ppe_id == ppe_id select p).SingleOrDefault(); if (ppe_exam == null) { ppe_exam = new ppe_exams() { exam_date_id = exam_date_id, ppe_id = ppe_id, status_id = 1, is_upload_data = false }; context.ppe_exams.Add(ppe_exam); } if (string.IsNullOrEmpty(ppe_exam.files_path)) { ppe_exam.files_path = context.get_ppe_files_path(exam_date_id, ppe_id).SingleOrDefault(); } context.SaveChanges(); res.is_uploaded = ppe_exam.is_upload_data; res.ppe_exam_id = ppe_exam.id; res.ppe_files_path = ppe_exam.files_path; res.status_id = (int)ppe_exam.status_id; res.status_name = context.ppe_exam_statuses.Where(x => x.id == res.status_id).Select(x => x.name).SingleOrDefault(); List <journals> blanks = (from j in context.journals where j.ppe_exam_id == ppe_exam.id select j).ToList(); List <PPEExamBlank> exam_blanks = new List <PPEExamBlank>(); foreach (int auditorium in blanks.Select(x => x.auditorium).Distinct()) { int?count_r = blanks.Where(x => x.auditorium == auditorium && x.blank_type_id == 1).Select(x => x.count_blanks).SingleOrDefault(); int?count_1 = blanks.Where(x => x.auditorium == auditorium && x.blank_type_id == 2).Select(x => x.count_blanks).SingleOrDefault(); int?count_2 = blanks.Where(x => x.auditorium == auditorium && x.blank_type_id == 3).Select(x => x.count_blanks).SingleOrDefault(); int?count_add_2 = blanks.Where(x => x.auditorium == auditorium && x.blank_type_id == 3).Select(x => x.count_add_blanks).SingleOrDefault(); exam_blanks.Add(new PPEExamBlank() { ppe_exam_id = ppe_exam.id, aud = auditorium, count_r = count_r != null ? (int)count_r : 0, count_1 = count_1 != null ? (int)count_1 : 0, count_2 = count_2 != null ? (int)count_2 : 0, count_add_2 = count_add_2 != null ? (int)count_add_2 : 0 }); } res.ListPPEExamBlanks = exam_blanks; res.messages = (from m in context.ppe_messages join u in context.au_users on m.user_id equals u.id join r in context.au_roles on u.role_id equals r.id where m.ppe_exam_id == ppe_exam.id select new PPEExamMessage() { id = m.id, ppe_exam_id = m.ppe_exam_id, fio = u.fio, user_id = u.id, user_role = r.description, message = m.message, mes_date = m.mes_date }).ToList(); List <PPEExamFile> exam_files = (from e in context.exam_dates join s in context.subjects on e.subject_id equals s.id join sb in context.subject_blanks on s.id equals sb.subject_id join bt in context.blank_types on sb.blank_type_id equals bt.id where e.id == exam_date_id select new PPEExamFile() { ppe_exam_id = ppe_exam.id, blank_type_id = bt.id, blank_type_name = bt.name, blank_folder_name = bt.folder_name, server_file_folder = ppe_exam.files_path + "/" + bt.folder_name }).ToList(); foreach (PPEExamFile file in exam_files) { string work_dir = ppe_exam.files_path + "/" + file.blank_folder_name; WorkWithFTP.FTPMakeDir(work_dir); file.ftp_files = WorkWithFTP.GetListFilesFromDir(work_dir); } res.exam_files = exam_files; } return res; })); }