// POST: api/UniqueMachineStatusses public string Post(HttpRequestMessage value) { try { Model.Unique_Machine mach = new Model.Unique_Machine(); string message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5); JArray machineDetails = JArray.Parse(message); foreach (JObject mac in machineDetails) { int um_ID = (int)mac["Unique_Machine_ID"]; mach = (from p in db.Unique_Machine where p.Unique_Machine_ID == um_ID select p).First(); mach.Machine_Status_ID = (int)mac["Machine_Status_ID"]; } db.SaveChanges(); return("true|Unique Machine Statuses successfully updated."); } catch (Exception e) { ExceptionLog.LogException(e, "UniqueMachineStatusController POST"); return("false|An error has occured updating the Unique Machine Statuses on the system."); } }
// POST: api/UniqueMachine public string Post(HttpRequestMessage value) { try { Model.Unique_Machine mach = new Model.Unique_Machine(); string message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5); JObject machineDetails = JObject.Parse(message); int key = db.Unique_Machine.Count() == 0 ? 1 : (from t in db.Unique_Machine orderby t.Unique_Machine_ID descending select t.Unique_Machine_ID).First() + 1; mach.Unique_Machine_ID = key; mach.Machine_ID = (int)machineDetails["Machine_ID"]; mach.Unique_Machine_Serial = (string)machineDetails["Unique_Machine_ID"]; mach.Machine_Status_ID = (int)machineDetails["Machine_Status_ID"]; string errorString = "false|"; bool error = false; if ((from t in db.Unique_Machine where t.Unique_Machine_Serial == mach.Unique_Machine_Serial select t).Count() != 0) { error = true; errorString += "The Unique Machine serial number entered already exists on the system. "; } if (error) { return(errorString); } db.Unique_Machine.Add(mach); db.SaveChanges(); return("true|Unique Machine " + (string)machineDetails["Unique_Machine_ID"] + " successfully added."); } catch (Exception e) { ExceptionLog.LogException(e, "UniqueMachineController POST"); return("false|An error has occured adding the Unique Machine to the system."); } }