Esempio n. 1
0
        //
        /// <summary>
        /// insert Incident and the attached Notes, then update the logs with
        /// the new incident id.  Delete any logs in the deleted.  Ignore any
        /// deleted notes, then shouldn't exist yet.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public NetworkIncidentData Insert(NetworkIncidentSave data)
        {
            System.Diagnostics.Debug.WriteLine(data.user.UserName + ' ' + data.incident.IPAddress);
            long _id     = 0;
            int  _server = data.incident.ServerId;

            //
            try
            {
                Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString());
                IncidentAccess   _ia       = new IncidentAccess(_niEntities);
                NetworkLogAccess _nla      = new NetworkLogAccess(_niEntities);
                Incident         _incident = _ia.Insert(data.incident);
                _incident.IncidentNotes = data.incidentNotes
                                          .AsEnumerable().Select(itd => itd.ToIncidentNote()).ToList();
                _niEntities.SaveChanges();
                _id = _incident.IncidentId;
                // List<NetworkLogData> networkLogs;
                foreach (NetworkLogData _nl in data.networkLogs.Where(_l => _l.Selected == true))
                {
                    _nl.IncidentId = _id;
                    _nla.UpdateIncidentId(_nl);
                }
                // List<NetworkLogData> deletedLogs;
                foreach (NetworkLogData _nl in data.deletedLogs)
                {
                    _nla.Delete(_nl.NetworkLogId);
                }
                _niEntities.SaveChanges();
            }
            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)
            {
                //Logger _logger = new Logger(_niEntities, "NetworkIncident");
                Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), data.incident.ToString() + _ex.Message, _ex);
                System.Diagnostics.Debug.WriteLine(_ex.ToString());
            }
            return(GetByPrimaryKey(_id, _server));
        }
Esempio n. 2
0
        //
        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);
        }