public ActionResult AddComment(int site_expert, int site_id) { if (db.Experts_comments.Count(p => p.site_experts.audit_object_id == site_id && p.site_experts.id == site_expert) > 0) { return(RedirectToAction("Index")); } int type_organization = Convert.ToInt32(db.audit_object.Find(site_id).education__institution.First(p => p.audit_object_id == site_id).type_education_institution_id); int not_type_organization = (type_organization == 1) ? 1 : 2; List <Criteria> criterias = db.Criteria.Where(p => p.type_organization != not_type_organization).ToList(); List <Experts_comments> comments = new List <Experts_comments>(); int id = (db.Experts_comments.Count() > 0) ? (db.Experts_comments.Max(p => p.id) + 1) : 1; for (int i = 0; i < criterias.Count(); ++i) { Experts_comments comment = new Experts_comments(); comment.id = id++; comment.site_experts_id = site_expert; comment.answer = Convert.ToInt32(Request.Form["ask_" + criterias.ElementAt(i).id]); if (Request.Form["comment_" + criterias.ElementAt(i).id] != null) { comment.comment = Request.Form["comment_" + criterias.ElementAt(i).id]; } comment.criteria_id = criterias.ElementAt(i).id; comments.Add(comment); } db.Experts_comments.AddRange(comments); db.SaveChanges(); int monitoring = Convert.ToInt32(db.site_experts.Find(site_expert).monitoring_id); int all_site_experts = db.site_experts.Count(p => p.audit_object_id == site_id && p.monitoring_id == monitoring); int all_site_experts_with_comment = db.site_experts.Count(p => p.audit_object_id == site_id && p.monitoring_id == monitoring && p.Experts_comments.Count() > 0); if (all_site_experts == all_site_experts_with_comment) { List <Experts_comments> com = db.Experts_comments.Where(p => p.site_experts.audit_object_id == site_id && p.site_experts.monitoring_id == monitoring).ToList(); decimal sum = 0; foreach (Experts_comments c in com) { sum += (c.answer * c.Criteria.Coefficients.value * 100); } experts_ratinng e_r = new experts_ratinng(); //добавление экспертного рейтинга e_r.id = (db.experts_ratinng.Count() > 0) ? (db.experts_ratinng.Max(p => p.id) + 1) : 1; e_r.monitoring_id = monitoring; e_r.audit_object_id = site_id; e_r.sum = Convert.ToInt32(Math.Round(sum)); db.experts_ratinng.Add(e_r); db.SaveChanges(); technical_rating t = db.technical_rating.FirstOrDefault(p => p.monitoring_id == monitoring && p.audit_object_id == site_id); Rating rat = new Rating(); rat.id = (db.Rating.Count() > 0) ? (db.Rating.Max(p => p.id) + 1) : 1; rat.monitoring_id = monitoring; rat.audit_object_id = site_id; rat.sum = (t != null) ? Convert.ToInt32(Math.Round(sum + Convert.ToDecimal(t.sum))) : Convert.ToInt32(Math.Round(sum)); db.Rating.Add(rat); db.SaveChanges(); } return(RedirectToAction("Index")); }
// GET: Experts/Details/5 public ActionResult _answer_end(int site_id, int group_id, int?m) { int type_organization = Convert.ToInt32(db.audit_object.Find(site_id).education__institution.First(p => p.audit_object_id == site_id).type_education_institution_id); int not_type_organization = (type_organization == 1) ? 1 : 2; if (m == null) { audit_object a = db.audit_object.Find(site_id); monitoring monitoring = db.monitoring.OrderByDescending(p => p.date_end).FirstOrDefault(p => p.date_end < DateTime.Now && p.Rating.Count(t => t.audit_object_id == site_id) > 0); if (monitoring != null) { m = monitoring.id; } } List <Experts_comments> answers = db.Experts_comments.Where(p => p.site_experts.audit_object_id == site_id && p.site_experts.monitoring_id == m && p.Criteria.group_id == group_id && p.Criteria.type_organization != not_type_organization).ToList(); List <Experts_comments> result = new List <Experts_comments>(); int id = 1; List <Criteria> cr = db.Criteria.Where(p => p.group_id == group_id && p.type_organization != not_type_organization).ToList(); foreach (Criteria c in cr) { List <Experts_comments> cr_answer = answers.Where(p => p.criteria_id == c.id).ToList(); Experts_comments one = new Experts_comments(); one.id = id++; one.criteria_id = c.id; int count_cr = cr_answer.Count(); one.Criteria = c; int sum = 0; for (int i = 0; i < cr_answer.Count(); ++i) { one.answer += cr_answer.ElementAt(i).answer; one.site_experts_id = cr_answer.ElementAt(i).site_experts_id; one.comment += " " + cr_answer.ElementAt(i).comment; } if (count_cr != 0) { one.answer = Convert.ToInt32(Math.Round(Convert.ToDouble(one.answer) / count_cr)); } else { one.answer = 0; } result.Add(one); } return(PartialView(result)); }
public ActionResult ExportResults() { monitoring m = db.monitoring.OrderByDescending(p => p.date_end).FirstOrDefault(p => p.date_end < DateTime.Now); //last monitoring List <education__institution> edu = db.education__institution.Where(p => p.audit_object.technical_rating.Where(s => s.monitoring_id == m.id).Count() > 0 && p.audit_object.experts_ratinng.Where(s => s.monitoring_id == m.id).Count() > 0).ToList(); List <technical_rating> tech = db.technical_rating.Where(p => p.monitoring_id == m.id).ToList(); List <experts_ratinng> exp = db.experts_ratinng.Where(p => p.monitoring_id == m.id).ToList(); List <Groups> groups = db.Groups.ToList(); List <Criteria> criteria = db.Criteria.ToList(); List <Experts_comments> e_comment = db.Experts_comments.ToList(); ExcelPackage excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add("Результаты"); workSheet.Cells[1, 1].Value = "Учреждение"; workSheet.Cells[1, 2].Value = "Технический рейтинг"; workSheet.Cells[2, 2].Value = "Доступность сайта"; workSheet.Cells[2, 3].Value = "Код ответа HTTP"; workSheet.Cells[2, 4].Value = "Использование HTTPS"; workSheet.Cells[2, 5].Value = "Время отклика"; workSheet.Cells[2, 6].Value = "Время полной загрузки сайта"; workSheet.Cells[2, 7].Value = "Наличие подписей картинок"; workSheet.Cells[2, 8].Value = "Наличие заголовка"; workSheet.Cells[2, 9].Value = "Файл robot.txt"; workSheet.Cells[2, 10].Value = "Максимальный уровень вложенности"; workSheet.Cells[2, 11].Value = "Количество битых ссылок"; workSheet.Cells[1, 12].Value = "Экспертный рейтинг"; int rows = 4; int cols = 12; for (int i = 0; i < groups.Count(); ++i) { workSheet.Cells[2, cols].Value = groups.ElementAt(i).name; int group_id = groups.ElementAt(i).id; List <Criteria> cr = criteria.Where(p => p.group_id == group_id).ToList(); for (int j = 0; j < cr.Count(); ++j) { workSheet.Cells[3, cols++].Value = cr.ElementAt(j).short_name; } } for (int i = 0; i < edu.Count(); ++i) { workSheet.Cells[rows, 1].Value = edu.ElementAt(i).full_name; int audit_object_id = Convert.ToInt32(edu.ElementAt(i).audit_object_id); technical_rating t = tech.First(p => p.audit_object_id == audit_object_id); workSheet.Cells[rows, 2].Value = t.site_accessibility; workSheet.Cells[rows, 3].Value = ((t.status_code != null) && t.status_code.Contains("True")) ? "Доступен" : "Не доступен"; workSheet.Cells[rows, 4].Value = ((t.using_HTTPS != null) && t.using_HTTPS.Contains("True")) ? "Да" : "Нет"; workSheet.Cells[rows, 5].Value = t.response_time; workSheet.Cells[rows, 6].Value = t.full_load; workSheet.Cells[rows, 7].Value = ((t.img_title != null) && t.img_title.Contains("True")) ? "Да" : "Нет"; workSheet.Cells[rows, 8].Value = ((t.has_title != null) && t.has_title.Contains("True")) ? "Да" : "Нет"; workSheet.Cells[rows, 9].Value = ((t.robots_txt != null) && t.robots_txt.Contains("True")) ? "Да" : "Нет"; workSheet.Cells[rows, 10].Value = t.nesting_level; workSheet.Cells[rows, 11].Value = t.broken_links_count; experts_ratinng e = exp.First(p => p.audit_object_id == audit_object_id); for (int s = 0; s < groups.Count(); ++s) { int group_id = groups.ElementAt(s).id; List <Criteria> cr = criteria.Where(p => p.group_id == group_id).ToList(); for (int j = 0; j < cr.Count(); ++j) { int cr_id = cr.ElementAt(j).id; Experts_comments e1 = e_comment.FirstOrDefault(p => p.criteria_id == cr_id && p.site_experts.audit_object_id == audit_object_id); workSheet.Cells[rows, cols++].Value = (e1 != null) ? e1.answer.ToString() : ""; } } cols = 12; rows++; } var path = Path.Combine(Server.MapPath("~/Content/"), "results_monitoring.xlsx"); using (var memoryStream = new MemoryStream()) { Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=" + path); excel.SaveAs(memoryStream); memoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } FileInfo fi = new FileInfo(path); long sz = fi.Length; Response.ClearContent(); Response.ContentType = Path.GetExtension(path); Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(path))); Response.AddHeader("Content-Length", sz.ToString("F0")); Response.TransmitFile(path); Response.End(); System.IO.File.Delete(path); return(Redirect("/Reports/AllResults")); }