public ExportOperationsDto ExportOperationsForEvent(int eventID) { var ev = db.Events.Where(x => x.ID == eventID).Include(x => x.EventSnippets).Include(x => x.EventSnippets.Select(y => y.Snippet.Operations)).Select(x => new { x.Name, Snippets = x.EventSnippets.Select(y => new { y.OrderNumber, Operations = y.Snippet.Operations }) }).FirstOrDefault(); if (ev == null) { return(null); } var operations = db.Operations.ToList(); //create table for snippets and operations DataTable dtSnippets = new DataTable(); dtSnippets.Columns.Add("Задача", typeof(string)); foreach (var item in operations) { dtSnippets.Columns.Add(item.Operator); } foreach (var item in ev.Snippets) { object[] rowData = new object[operations.Count + 1]; rowData[0] = "Задача " + item.OrderNumber; int idx = 1; foreach (var optemp in operations) { var tempOperation = item.Operations.FirstOrDefault(x => x.OperationID == optemp.ID); if (tempOperation != null) { rowData[idx++] = tempOperation.Frequency; } else { rowData[idx++] = 0; } } dtSnippets.Rows.Add(rowData); } ExportOperationsDto result = new ExportOperationsDto(); result.Table = dtSnippets; result.Name = string.Format("{0} - Operacii", ev.Name); return(result); }
public ExportOperationsDto ExportOperationsForEventOld(int eventID) { var snippets = db.Answers.Where(x => x.EventID == eventID) .Select(x => x.SnippetID) .ToList(); //var op = db.Operations.ToList(); //var snippetoperators = db.SnippetOperations.Where(x => snippets.Contains(x.SnippetID)).Include(x=>x.Operation).ToList(); ////create table for snippets and operations DataTable dtSnippets = new DataTable(); dtSnippets.Columns.Add("Задача", typeof(string)); //foreach (var item in op) //{ // dtSnippets.Columns.Add(item.Operator, typeof(int)); //} //int ct = 1; //foreach (var item in snippetoperators) //{ // object[] rowData = new object[op.Count + 1]; // var ops = snippetoperators.ToList(); // rowData[0] = "Задача " + ct; // int idx = 1; // foreach (var optemp in op) // { // var tempOperation = ops.FirstOrDefault(x => x.OperationID == optemp.ID); // if (tempOperation != null) // { // rowData[idx++] = tempOperation.Frequency; // } // else // { // rowData[idx++] = 0; // } // } // ct++; // dtSnippets.Rows.Add(rowData); //} ExportOperationsDto result = new ExportOperationsDto(); ////result.Table = dtSnippets; return(result); }