public view_expertise_pospelov GetListExpertisePospelov(int id_expertise, int id_expert) { try { view_expertise_pospelov result = new view_expertise_pospelov(); expertises _expertises = db_Expertises.expertises.Where(p => p.id_expertise == id_expertise).FirstOrDefault(); if (_expertises != null) { List <factors> list_pr_ex = db_Expertises.factors.Where(p => p.id_expertise == id_expertise).ToList(); List <marks_ribs> list_marks_ribs = db_Expertises.marks_ribs.Where(p => p.id_expertise == id_expertise && p.id_expert == id_expert).ToList(); List <marks_factors> list_marks_factors = db_Expertises.marks_factors.Where(p => p.id_expertise == id_expertise && p.id_expert == id_expert).ToList(); List <factors> temp = new List <factors>(); List <ribs> temp2 = new List <ribs>(); foreach (var pr in list_pr_ex) { factors t = new factors(); t.id_expertise = pr.id_expertise; t.id_factor = pr.id_factor; t.priority = pr.priority; t.name = pr.name; List <ribs> list_ex_cr = db_Expertises.ribs.Where(p => p.id_factor_from == pr.id_factor).ToList(); if (list_ex_cr != null) { foreach (var pr2 in list_ex_cr) { ribs t2 = new ribs(); t2.id_rib = pr2.id_rib; t2.id_factor_from = pr2.id_factor_from; t2.id_factor_in = pr2.id_factor_in; temp2.Add(t2); } } temp.Add(t); } List <marks_factors> temp3 = new List <marks_factors>(); foreach (var pr in list_marks_factors) { marks_factors t = new marks_factors(); t.id_mark = pr.id_mark; t.id_expertise = pr.id_expertise; t.id_factor = pr.id_factor; t.id_expert = pr.id_expert; t.value = pr.value; temp3.Add(t); } List <marks_ribs> temp4 = new List <marks_ribs>(); foreach (var pr in list_marks_ribs) { marks_ribs t = new marks_ribs(); t.id_mark_rib = pr.id_mark_rib; t.id_expertise = pr.id_expertise; t.id_rib = pr.id_rib; t.id_expert = pr.id_expert; t.value = pr.value; temp4.Add(t); } result.id_expertise = id_expertise; result.list_factors = temp; result.list_ribs = temp2; result.list_marks_factors = temp3; result.list_marks_ribs = temp4; //return _expertises.id_expertise; } return(result); } catch (Exception Ex) { // тут логируется ошибка view_expertise_pospelov tmpC = new view_expertise_pospelov(); tmpC.id_expertise = -1; return(tmpC); } }
//Метод добавления экспертизы pospelov public int AddExperisePospelov(string name, List <int> ls_id_experts, List <List <string> > ls_fac /*List<int> ls_prior, List<string> ls_name_fact*/) { try { expertises _expertises = new expertises(); _expertises.name = name; _expertises.id_status = 1; _expertises.type = 2; db_Expertises.expertises.Add(_expertises); db_Expertises.SaveChanges(); foreach (int temp in ls_id_experts) { experts_expertises ex_ex = new experts_expertises(); ex_ex.id_expertise = _expertises.id_expertise; ex_ex.id_expert = temp; ex_ex.id_status = 1; db_Expertises.experts_expertises.Add(ex_ex); db_Expertises.SaveChanges(); } int level = 0; foreach (var temp in ls_fac) { for (int i = 0; i < temp.Count(); i++) { factors fc = new factors(); fc.id_expertise = _expertises.id_expertise; fc.name = temp[i]; fc.priority = level; db_Expertises.factors.Add(fc); db_Expertises.SaveChanges(); } level++; } int max_priority = ls_fac.Count(); level = 0; foreach (var temp in ls_fac) { if (level != max_priority) { for (int i = 0; i < temp.Count(); i++) { string name_fact = temp[i]; var id_factor = db_Expertises.factors.Where(o => o.id_expertise == _expertises.id_expertise && o.name == name_fact).FirstOrDefault().id_factor; List <factors> tmpFactors = db_Expertises.factors.Where(o => o.priority == level + 1 && o.id_expertise == _expertises.id_expertise).ToList(); foreach (var fact in tmpFactors) { ribs r = new ribs(); r.id_factor_from = id_factor; r.id_factor_in = fact.id_factor; db_Expertises.ribs.Add(r); db_Expertises.SaveChanges(); } } level++; } } return(_expertises.id_expertise); } catch (Exception ex) { return(-1); } }