//CRUD DELETE //POST a deletion/deactivation to the db //error checking //POST: /TSMaintenanceOrderActivity/DeleteMaintOrdActivity public string DeleteMaintOrdActivity(TSMaintenanceOrderActivityModel tsMaintenanceOrderActivity) { //error checking try { //create a new MaintOrdActivity-type object called oMainOrdActivity MaintOrdActivity oMainOrdActivity = new MaintOrdActivity(); //populate the DAL-object with the MVC object data oMainOrdActivity.TA_RecID = tsMaintenanceOrderActivity.TA_RecID; oMainOrdActivity.Task = tsMaintenanceOrderActivity.Task; oMainOrdActivity.CombinedActivites = tsMaintenanceOrderActivity.CombinedActivities; oMainOrdActivity.TA_Code = tsMaintenanceOrderActivity.TA_Code; //set the object property to false. When you load the table in, with the //GetMaintOrdGroup() method called and filering in only active=true objects, //you'll only get the objects labelled as true (i.e. not "deleted") oMainOrdActivity.Active = false; //connect via interface to DAL App, and delete the object. The DAL parses out just the equipment number, deleting the object with that number itsApp.DeleteMaintOrdActivity(oMainOrdActivity); return("Deleted"); } catch { return("Not Deleted"); } }
//CRUD UPDATE //POST an update to the db //error checking //POST: /TSMaintenanceOrderActivity/UpdateMaintOrdActivity public string UpdateMaintOrdActivity(TSMaintenanceOrderActivityModel tsMaintenanceOrderActivity) { //error checking try { //create a new DAL-based MaintOrdActivity-type object called oMainOrdActivity MaintOrdActivity oMainOrdActivity = new MaintOrdActivity(); //populate the DAL-object with the MVC object data //for update, make sure to send back the ta_recid. //That id is how the db knows which data row to update oMainOrdActivity.TA_RecID = tsMaintenanceOrderActivity.TA_RecID; oMainOrdActivity.Task = tsMaintenanceOrderActivity.Task; oMainOrdActivity.CombinedActivites = tsMaintenanceOrderActivity.CombinedActivities; oMainOrdActivity.TA_Code = tsMaintenanceOrderActivity.TA_Code; oMainOrdActivity.Active = tsMaintenanceOrderActivity.Active; //connect via interface to DAL App, and insert the object itsApp.UpdateMaintOrdActivity(oMainOrdActivity); return("Updated"); } catch { return("Not Updated"); } }
//inserts/creates a Maintenance Order Activity object in the DAL->db //POST: /TSMaintenanceOrderActivity/InsertMaintOrdActivity public string InsertMaintOrdActivity(TSMaintenanceOrderActivityModel tsMaintenanceOrderActivity) { //error checking try { //create a new DAL-based MaintOrdActivity-type object called oMainOrdActivity MaintOrdActivity oMainOrdActivity = new MaintOrdActivity(); //populate the DAL-object with the MVC object data //do not send back the ta_recid. The id is auto-incremented and assigned an id when on object is passed to the db/ //oMainOrdActivity.TA_RecID = tsMaintenanceOrderActivity.TA_RecID; oMainOrdActivity.Task = tsMaintenanceOrderActivity.Task; oMainOrdActivity.CombinedActivites = tsMaintenanceOrderActivity.CombinedActivities; oMainOrdActivity.TA_Code = tsMaintenanceOrderActivity.TA_Code; oMainOrdActivity.Active = tsMaintenanceOrderActivity.Active; //connect via interface to DAL App, and insert the object itsApp.InsertMaintOrdActivity(oMainOrdActivity); return("Added"); } catch { return("Not Added"); } }
//dropdown to get the TA_Code and task grouped together //POST and GET: /TSMaintenanceOrderActivity/GetMaintOrdActivityByTA_Code public ActionResult GetMaintOrdActivityByTA_Code(TSMaintenanceOrderActivityModel tsMaintenanceOrderActivity) { try { //stores the first table MaintOrdActivityByTask = itsApp.GetMaintOrdActivity().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 MaintOrdActivityByTask.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in MaintOrdActivityByTask.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //takes the List, and filters through to data using LINQ to SQL format, //gets only the rows of data that have Task labeled as the user's choice (i.e. tsMaintenanceOrderActivity.Task var maintOrdActivityFilteredByTA_Code = from x in parentRow where x.Keys.Contains("TA_Code") && x.Values.Contains(tsMaintenanceOrderActivity.TA_Code) select x; //serialized the data into javascript string JsSerializer = JsonConvert.SerializeObject(maintOrdActivityFilteredByTA_Code); //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); } catch { return(null); } }
//gets/reads Maintenance Order Activities by their id, used for tables //POST and GET: /TSMaintenanceOrderActivity/GetMaintOrdActivityByTA_RecID public ActionResult GetMaintOrdActivityByTA_RecID(TSMaintenanceOrderActivityModel tsMaintenanceOrderActivity) { //error handling //and it returns a value to the AngularJS method (after being processed by the DAL method) try { //gets entries as Dataview //stores the first table MaintOrdActivityByTA_RecID = itsApp.GetMaintOrdActivityByTA_RecID(tsMaintenanceOrderActivity.TA_RecID).Tables[0].DefaultView; //converts/serializes the DataView/Dataset data into List data List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in MaintOrdActivityByTA_RecID.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in MaintOrdActivityByTA_RecID.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //converts/serializes the DataView to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); string JsSerializer = JsonConvert.SerializeObject(parentRow); return(Json(JsSerializer, JsonRequestBehavior.AllowGet)); } //error handling, else it returns no value/null to the AngularJS method, //The AngularJS method then finishes off the error handling, //and gives the user either the data or an error message. catch { return(null); } }