//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"); } }
//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"); } }
//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"); } }
//gets/reads only distinct ta codes and their "description"(i.e. task), used for dropdowns //GET: /TSMaintenanceOrderActivity/GetMaintOrdActivityTA_CodeDistinct public ActionResult GetMaintOrdActivityTA_CodeDistinct() { //error checking try { //stores the first table MaintOrdActivity = itsApp.GetMaintOrdActivity().Tables[0].DefaultView; //uses Datatable format, filters by the TA_Code column, //only returning the rows with values that are distinct/unique in relation to each other, //Then encapsulates the distinct/unique values back into DataView format DataTable distinctTA_Codes = MaintOrdActivity.ToTable(true, "TA_Code", "Task"); DataView formatDistinctTA_Codes = distinctTA_Codes.DefaultView; //formatDistinctTA_Codes.Sort = "TA_Code"; List <Dictionary <string, object> > parentRow = new List <Dictionary <string, object> >(); Dictionary <string, object> childRow; foreach (DataRow row in formatDistinctTA_Codes.Table.Rows) { childRow = new Dictionary <string, object>(); foreach (DataColumn col in formatDistinctTA_Codes.Table.Columns) { childRow.Add(col.ColumnName, row[col]); } parentRow.Add(childRow); } //serializes/converts the DataView to JSON JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); //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); } catch { return(null); } }