public ActionResult EditElectronics() { string strRet; uls_dbDataContext db = new uls_dbDataContext(); string strOperation = Request.Form["hdnEditOper"]; string strElectronicsID; if (strOperation == "Edit") { strElectronicsID = Request.Form["hdnEditID"]; } else { strElectronicsID = Request.Form["txtElectronicsID"]; } string strYear = Request.Form["txtElectronicsYear"]; string strType = Request.Form["ddlElectronicsType"]; string strMake = Request.Form["ddlElectronicsMake"]; string strModel = Request.Form["ddlElectronicsModel"]; string strLoc = Request.Form["ddlElectronicsLoc"]; string strMngBy = Request.Form["ddlElectronicsMngBy"]; string strRegBy = Request.Form["ddlElectronicsRegBy"]; string strMngByDt = Request.Form["dtElectronicsMngByDt"]; string strSerialNum = Request.Form["txtElectronicsSerialNum"]; string strAirCardNum = Request.Form["txtElectronicsAirCardNum"]; string strCost = Request.Form["txtElectronicsCost"]; string strStolen = Request.Form["hdnElectronicsStolen"]; string strInRepair = Request.Form["hdnElectronicsInRepair"]; string strTotaled = Request.Form["hdnElectronicsTotaled"]; string strUnknown = Request.Form["hdnElectronicsUnknown"]; string strComment = Request.Form["txtElectronicsComment"]; string strLogEntry = ""; bool blnObsolete = false; try { electronic eltrnc; electronic eltrncCheck; electronics_edit_log logentry = new electronics_edit_log(); logentry.user_id = User.Identity.Name; logentry.edit_dt = DateTime.Today; logentry.electronics_id = strElectronicsID; if (strOperation == "Edit") { eltrnc = db.electronics.Single(e => e.electronics_id == strElectronicsID); } else // add { if (strElectronicsID.Length <= 0) { throw new Exception("Invalid ID specified."); } if (strRegBy.Length <= 0) { throw new Exception("No Division specified in Registered By field."); } eltrnc = new electronic(); eltrnc.electronics_id = strElectronicsID; eltrnc.assigned = false; eltrncCheck = db.electronics.SingleOrDefault(e => e.electronics_id == eltrnc.electronics_id); if (eltrncCheck != null) { throw new Exception("This ID already exists."); } } if (strOperation == "Edit" || strOperation == "Add") { if (strComment != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Comment", eltrnc.comment == null ? "" : eltrnc.comment.ToString(), strComment, strLogEntry); } eltrnc.comment = strComment; } Single sngCost; if (strCost != null) { if (Single.TryParse(strCost.Replace("$", ""), out sngCost)) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Cost", eltrnc.cost == null ? "0" : eltrnc.cost.ToString(), strCost.Replace("$", ""), strLogEntry); } eltrnc.cost = sngCost; } } if (strYear != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Purchase Year", eltrnc.year_pur == null ? "0" : eltrnc.year_pur.ToString(), strYear, strLogEntry); } eltrnc.year_pur = strYear; } if (strUnknown != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Unknown", eltrnc.unknown == true ? "on" : "off", strUnknown, strLogEntry); } eltrnc.unknown = strUnknown == "on" ? true : false; } if (strInRepair != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("In Repair", eltrnc.in_repair == true ? "on" : "off", strInRepair, strLogEntry); } eltrnc.in_repair = strInRepair == "on" ? true : false; } Int16 intMake; if (Int16.TryParse(strMake, out intMake)) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Make ID", eltrnc.make_id == null ? "0" : eltrnc.make_id.ToString(), strMake, strLogEntry); } eltrnc.make_id = intMake; } if (strMngBy != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Managed By", eltrnc.managed_by == null ? "" : eltrnc.managed_by.ToString(), strMngBy, strLogEntry); } eltrnc.managed_by = strMngBy; } if (IsDate(strMngByDt)) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Managed By Date", eltrnc.managed_by_dt != null ? String.Format("{0:MM/dd/yyyy}", eltrnc.managed_by_dt) : "X", strMngByDt, strLogEntry); } eltrnc.managed_by_dt = Convert.ToDateTime(strMngByDt); } Int16 intModel; if (Int16.TryParse(strModel, out intModel)) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Model ID", eltrnc.model_id == null ? "0" : eltrnc.model_id.ToString(), strModel, strLogEntry); } eltrnc.model_id = intModel; } if (strRegBy != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Registered By", eltrnc.registered_by == null ? "" : eltrnc.registered_by.ToString(), strRegBy, strLogEntry); } eltrnc.registered_by = strRegBy; } if (eltrnc.registered_by == null || eltrnc.registered_by.Length <= 0) { throw new Exception("Registered By must be specified."); } if (strStolen != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Stolen", eltrnc.stolen == true ? "on" : "off", strStolen, strLogEntry); if (eltrnc.stolen == false && strStolen == "on") { blnObsolete = true; } } eltrnc.stolen = strStolen == "on" ? true : false; } if (strTotaled != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Totaled", eltrnc.totaled == true ? "on" : "off", strTotaled, strLogEntry); if (eltrnc.totaled == false && strTotaled == "on") { blnObsolete = true; } } eltrnc.totaled = strTotaled == "on" ? true : false; } Int16 intType; if (Int16.TryParse(strType, out intType)) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Type ID", eltrnc.type_id == null ? "" : eltrnc.type_id.ToString(), strType, strLogEntry); } eltrnc.type_id = intType; } if (strSerialNum != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Serial Num", eltrnc.serial_num == null ? "" : eltrnc.serial_num.ToString(), strSerialNum, strLogEntry); } eltrnc.serial_num = strSerialNum; } if (strAirCardNum != null) { if (strOperation == "Edit") { string strNumStripped = System.Text.RegularExpressions.Regex.Replace(strAirCardNum, "\\D", ""); strLogEntry = CheckEditField("Air Card Num", eltrnc.air_card_num == null ? "" : eltrnc.air_card_num.ToString(), strAirCardNum, strLogEntry); } eltrnc.air_card_num = strAirCardNum; } if (eltrnc.serial_num != null && eltrnc.serial_num.Length > 0) { eltrncCheck = db.electronics.SingleOrDefault(e => e.serial_num == eltrnc.serial_num); if (eltrncCheck != null) { if (eltrnc.electronics_id != eltrncCheck.electronics_id) { throw new Exception("Serial Number already exists for: " + eltrncCheck.electronics_id); } } } if (strLoc != null) { if (strOperation == "Edit") { strLogEntry = CheckEditField("Location", eltrnc.location == null ? "" : eltrnc.location.ToString(), strLoc, strLogEntry); } eltrnc.location = strLoc; } if (strOperation == "Add") { strLogEntry = "Record Added."; db.electronics.InsertOnSubmit(eltrnc); } } if (strLogEntry != "") { if (strOperation == "Edit") { logentry.edit_change = "Modified: " + strLogEntry; } else { logentry.edit_change = strLogEntry; } db.electronics_edit_logs.InsertOnSubmit(logentry); } db.SubmitChanges(); if (blnObsolete == true && Convert.ToString(Session["division"]) == "ULS-PA") { db.UpdateObsoleteId(strElectronicsID); } return(Content("Success" + "," + Session["division"])); } catch (Exception ex) { string msg = ex.Message; strRet = msg; return(Content(strRet + "," + "")); } finally { db.Dispose(); } }