//gets/reads all employees, including active and inactive used for dropdown list and/or tables public ActionResult GetEmployeesAll() { //stores the first table Employee = itsApp.GetEmployees().Tables[0].DefaultView; //serializes/converts the DataView to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in Employee.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in Employee.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //serialized the data into javascript string JsSerializer = JsonConvert.SerializeObject(parentRow); //this sets the Json data allowance to it's max value. Otherwise, Json will limit the Equipment data from displaying JsonResult json = Json(JsSerializer, JsonRequestBehavior.AllowGet); json.MaxJsonLength = int.MaxValue; return(json); }
//gets/reads all active employees, used for dropdown list public ActionResult GetActiveEmployees() { //stores the first table of all active employees ActiveEmployees = itsApp.GetEmployees().Tables[0].DefaultView; //serializes/converts the DataView to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in ActiveEmployees.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in ActiveEmployees.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //serialized the data into javascript string JsSerializer = JsonConvert.SerializeObject(parentRow).Replace(@"\", ""); //returns the data as JSON, which can now be used with AngularJS return(Json(JsSerializer, JsonRequestBehavior.AllowGet)); }