public int InsertSave(IncidentData data) { int _return = 0; Incident _incident = Insert(data); _niEntities.SaveChanges( ); _return = 1; return(_return); }
public int UpdateSave(IncidentData data) { int _return = 0; Incident _incident = Update(data); if (_incident != null) { _niEntities.SaveChanges(); _return++; } return(_return); }
// /// <summary> /// Return one row of Incident /// </summary> /// <param name="incidentId"></param> /// <returns></returns> public IncidentData GetByPrimaryKey(long incidentId) { IncidentData _incident = null; var _incidents = ListIncidentQueryable() .Where(_r => _r.IncidentId == incidentId); if (_incidents.Count( ) > 0) { _incident = _incidents.First(); } return(_incident); }
// /// <summary> /// Update one row of Incident without SaveChanges /// </summary> /// <param name="data"></param> /// <returns></returns> public Incident Update(IncidentData data) { Incident _incident = null; var _incidents = from _r in _niEntities.Incidents where _r.IncidentId == data.IncidentId select _r; if (_incidents.Count( ) > 0) { _incident = _incidents.First( ); if (_incident.IPAddress != data.IPAddress) { _incident.IPAddress = data.IPAddress; } if (_incident.NIC_Id != data.NIC) { _incident.NIC_Id = data.NIC; } if (_incident.NetworkName != data.NetworkName) { _incident.NetworkName = data.NetworkName; } if (_incident.AbuseEmailAddress != data.AbuseEmailAddress) { _incident.AbuseEmailAddress = data.AbuseEmailAddress; } if (_incident.ISPTicketNumber != data.ISPTicketNumber) { _incident.ISPTicketNumber = data.ISPTicketNumber; } if (_incident.Mailed != data.Mailed) { _incident.Mailed = data.Mailed; } if (_incident.Closed != data.Closed) { _incident.Closed = data.Closed; } if (_incident.Special != data.Special) { _incident.Special = data.Special; } if (_incident.Notes != data.Notes) { _incident.Notes = data.Notes; } } return(_incident); }
// /// <summary> /// Insert one row into Incident without SaveChanges /// </summary> /// <param name="data"></param> /// <returns></returns> public Incident Insert(IncidentData data) { Incident _incident = new Incident( ); _incident.ServerId = data.ServerId; _incident.NIC_Id = data.NIC; _incident.IPAddress = data.IPAddress; _incident.NetworkName = data.NetworkName; _incident.AbuseEmailAddress = data.AbuseEmailAddress; _incident.ISPTicketNumber = data.ISPTicketNumber; _incident.Mailed = data.Mailed; _incident.Closed = data.Closed; _incident.Special = data.Special; _incident.Notes = data.Notes; _incident.CreatedDate = DateTime.Now; _niEntities.Incidents.Add(_incident); return(_incident); }
// #endregion // public IncidentData EmptyIncidentData(int serverId) { IncidentData _incid = new IncidentData(); _incid.IncidentId = 0; _incid.ServerId = serverId; _incid.IPAddress = ""; _incid.NIC = ""; _incid.NetworkName = ""; _incid.AbuseEmailAddress = ""; _incid.ISPTicketNumber = ""; _incid.Mailed = false; _incid.Closed = false; _incid.Special = false; _incid.Notes = ""; _incid.CreatedDate = DateTime.Now; return(_incid); }
// public NetworkIncidentData Update(NetworkIncidentSave data) { string _params = string.Format("Entering with: incidentId: {0}, UserName: {1}", data.incident.IncidentId, data.user.UserName); System.Diagnostics.Debug.WriteLine(_params); // long _id = data.incident.IncidentId; Incident _incident = null; try { Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), "Entering ... " + data.incident.ToString()); IncidentAccess _ia = new IncidentAccess(_niEntities); NetworkLogAccess _nla = new NetworkLogAccess(_niEntities); IncidentNoteAccess _ina = new IncidentNoteAccess(_niEntities); IncidentData _incidentBefore = _ia.GetByPrimaryKey(data.incident.IncidentId); _incident = _ia.Update(data.incident); // Update notes foreach (IncidentNoteData _in in data.incidentNotes.Where(_r => _r.IsChanged == true && _r.IncidentNoteId > 0)) { _ina.Update(_in); } // Add notes foreach (IncidentNoteData _in in data.incidentNotes.Where(_r => _r.IncidentNoteId < 0)) { _incident.IncidentNotes.Add(_in.ToIncidentNote()); } // Delete notes foreach (IncidentNoteData _in in data.deletedNotes) { _ina.Delete(_in.IncidentNoteId); } // Update logs foreach (NetworkLogData _nl in data.networkLogs.Where(_l => _l.IsChanged == true)) { _nla.UpdateIncidentId(_nl); } // Delete Logs; foreach (NetworkLogData _nl in data.deletedLogs) { if (_nl.Selected == false) { _nla.Delete(_nl.NetworkLogId); } } // _niEntities.SaveChanges(); Log.Logger.Log(LoggingLevel.Info, data.user.UserName, MethodBase.GetCurrentMethod(), "Inside, after save ... id: " + data.incident.IncidentId.ToString()); // if (_incidentBefore.Mailed == false && data.incident.Mailed == true) { Task.Run(() => { EMailIspReport(data); }); } } catch (DbEntityValidationException _entityEx) { // extension method string _errors = _entityEx.EntityValidationErrors.GetDbValidationErrors(); Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + ' ' + _errors, _entityEx); System.Diagnostics.Debug.WriteLine(_errors); } catch (Exception _ex) { Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + _ex.Message, _ex); System.Diagnostics.Debug.WriteLine(_ex.ToString()); } NetworkIncidentData _networkIncident = GetByPrimaryKey(data.incident.IncidentId, data.incident.ServerId); Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), "Exiting ... " + _networkIncident.incident.ToString()); return(_networkIncident); }