/** * GET: api/ApiData * {HTTP}/ api/ApiData * That methode return All Employees and their Attributes */ public JsonResult Get() { var employees = db.Employees; //List<Models.AllDataViewer> listForAll = new List<Models.AllDataViewer>(); if (employees != null) { DataTable dt = new DataTable(); dt.Columns.Add("EMP_ID", typeof(string)); dt.Columns.Add("EMP_Name", typeof(string)); dt.Columns.Add("EMP_DateOfHire", typeof(string)); dt.Columns.Add("EMP_Supervisor", typeof(string)); dt.Columns.Add("ATTR_ID", typeof(string)); dt.Columns.Add("ATTR_Name", typeof(string)); dt.Columns.Add("ATTR_Value", typeof(string)); foreach (Employee emp in employees) { AllDataViewer empAttr = new AllDataViewer(); foreach (Models.Attribute attr in emp.Attributes) { dt.Rows.Add(emp.EMP_ID.ToString(), emp.EMP_Name, emp.EMP_DateOfHire, emp.EMP_Supervisor, attr.ATTR_ID.ToString(), attr.ATTR_Name, attr.ATTR_Value); } } JsonResult retData = new JsonResult(); retData.JsonRequestBehavior = JsonRequestBehavior.AllowGet; retData.MaxJsonLength = dt.Rows.Count; retData.Data = dt; return(retData); } return(null); }
/* * GET: MainDataViewer * {HTTP}/MainDataViewer/Index * That methode use the Index.cshtml View * To display Employees and Attributes */ public ActionResult Index() { var employees = db.Employees; var attributes = db.Attributes; AllDataViewer modelView = new AllDataViewer(); modelView.listOfEmployee = employees.ToList(); modelView.listOfAttribute = attributes.ToList(); return(View(modelView)); }