コード例 #1
0
        //
        // -------------------------------------------------------------------
        //
        /// <summary>
        ///
        /// </summary>
        /// <param name="incidentId"></param>
        /// <param name="serverId"></param>
        /// <returns></returns>
        public NetworkIncidentData GetByPrimaryKey(long incidentId, int serverId)
        {
            string _user   = Helpers.Helpers.GetUserAccount( );
            string _params = string.Format("Entering with: incidentId: {0}, serverId: {1}", incidentId, serverId);

            Log.Logger.Log(LoggingLevel.Debug, _user, MethodBase.GetCurrentMethod(), _params);
            System.Diagnostics.Debug.WriteLine(_params);
            //
            NetworkIncidentData _data = new NetworkIncidentData();

            _data.message      = "";
            _data.deletedNotes = new List <IncidentNoteData>();
            _data.deletedLogs  = new List <NetworkLogData>();
            SelectItemAccess   _sis   = new SelectItemAccess(_niEntities);
            NetworkLogAccess   _nl    = new NetworkLogAccess(_niEntities);
            IncidentTypeAccess _it    = new IncidentTypeAccess(_niEntities);
            Incident           _incid = null;
            int _companyId            = _niEntities.Servers.Where(s => s.ServerId == serverId)
                                        .First().CompanyId;

            // need the notes data, etc
            if (incidentId > 0)
            {
                _incid = _niEntities.Incidents
                         .Where(_i => _i.IncidentId == incidentId).FirstOrDefault();
            }
            else
            {
                _incid = EmptyIncident(serverId);
            }
            //
            if (_incid != null)
            {
                _data.incident = _incid.ToIncidentData();
                //
                _data.incidentNotes = _incid.IncidentNotes
                                      .Where(_r => _r.Incidents.Any(_i => _i.IncidentId == incidentId))
                                      .AsEnumerable <IncidentNote>()
                                      .Select(_n => _n.ToIncidentNoteData()).ToList();
                //
                _data.networkLogs = _nl.ListByIncident(_incid.ServerId, incidentId, _incid.Mailed);
                //
                _data.typeEmailTemplates = _it.ListByCompanySpecific(_companyId);
                //
                _data.NICs = _sis.NICs();
                //
                _data.incidentTypes = _sis.IncidentTypes();
                //
                _data.noteTypes = _sis.NoteTypes();
                //
            }
            else
            {
                Log.Logger.Log(LoggingLevel.Error, _user, MethodBase.GetCurrentMethod(), "Incident is null.");
            }
            //
            return(_data);
        }
コード例 #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);
        }