Exemplo n.º 1
0
        //
        //
        /// <summary>
        /// Delete one row from IncidentNotes
        /// </summary>
        /// <param name="incidentNoteId">long incident note id</param>
        /// <returns>Row count</returns>
        public int Delete(long incidentNoteId)
        {
            int _return        = 0;
            var _incidentNotes =
                (from _r in _niEntities.IncidentNotes
                 where _r.IncidentNoteId == incidentNoteId
                 select _r).ToList();

            if (_incidentNotes.Count() > 0)
            {
                IncidentNote _incidentNote = _incidentNotes.First();
                // Foreign key violation [dbo_Incident2IncidentNote :: IncidentNoteId]. The key value [1] does not exists in the referenced table [dbo_IncidentNote :: IncidentNoteId].. Error code: RelationError"}
                // var _incids = _incidentNote.Incidents.ToList();
                foreach (var _incid in _incidentNote.Incidents.ToList())
                {
                    List <IncidentNote> _notes = _incid.IncidentNotes
                                                 .Where(_n => _n.IncidentNoteId == incidentNoteId).ToList();
                    foreach (IncidentNote _note in _notes)
                    {
                        _niEntities.IncidentNotes.Remove(_note);
                        _return++;
                    }
                }
            }
            return(_return);
        }
Exemplo n.º 2
0
        public int InsertSave(IncidentNoteData data)
        {
            int          _return       = 0;
            IncidentNote _incidentNote = Insert(data);

            _niEntities.SaveChanges();
            _return = 1;
            return(_return);
        }
Exemplo n.º 3
0
        //
        // Insert one row into IncidentNotes
        //
        public IncidentNote Insert(IncidentNoteData data)
        {
            IncidentNote _incidentNote = new IncidentNote();

            _incidentNote.NoteTypeId = data.NoteTypeId;
            _incidentNote.Note       = data.Note;
            _niEntities.IncidentNotes.Add(_incidentNote);
            return(_incidentNote);
        }
Exemplo n.º 4
0
        //
        // [TestMethod(), TestCategory("Effort")]
        public void Effort_NoteType_Verify_CascadingDelete_Test()
        {
            IncidentNote _iNote = _niEntities.IncidentNotes.FirstOrDefault(_in => _in.IncidentNoteId == 2);
            NoteType     _newNT = _niEntities.NoteTypes.FirstOrDefault(_t => _t.NoteTypeId == _iNote.NoteTypeId);

            _niEntities.NoteTypes.Remove(_newNT);
            _niEntities.SaveChanges();
            _iNote = _niEntities.IncidentNotes.FirstOrDefault(_in => _in.IncidentNoteId == 2);
            // cascading deletes
            Assert.IsNull(_iNote);
        }
Exemplo n.º 5
0
 //
 /// <summary>
 /// Extension method...
 /// can be called fluently by the class or as a static method.
 /// </summary>
 /// <param name="incidentNote"></param>
 /// <returns>a populated IncidentNoteData class</returns>
 public static IncidentNoteData ToIncidentNoteData(this IncidentNote incidentNote)
 {
     return(new IncidentNoteData()
     {
         IncidentNoteId = incidentNote.IncidentNoteId,
         NoteTypeId = incidentNote.NoteTypeId,
         NoteTypeShortDesc = (incidentNote.NoteType == null ? "" : incidentNote.NoteType.NoteTypeShortDesc),
         Note = incidentNote.Note,
         CreatedDate = incidentNote.CreatedDate,
         IsChanged = false
     });
 }
        public void Effort_IncidentNote_Insert_Test()
        {
            DateTime _ndt  = new DateTime(2016, 4, 21, 12, 12, 12);
            var      _data = new IncidentNoteData()
            {
                IncidentNoteId    = 0,
                NoteTypeId        = 1,
                NoteTypeShortDesc = "Ping",
                Note        = "Ping",
                CreatedDate = _ndt
            };
            IncidentNote _row = _sut.Insert(_data);

            Assert.IsNotNull(_row);
            _niEntities.SaveChanges();
            System.Diagnostics.Debug.WriteLine(_row.IncidentNoteId.ToString());
            Assert.IsTrue(_row.IncidentNoteId > 2);
        }
Exemplo n.º 7
0
        public void Effort_NoteType_Verify_NonCascadingDelete_Test()
        {
            IncidentNote _iNote = _niEntities.IncidentNotes.FirstOrDefault(_in => _in.IncidentNoteId == 2);
            NoteType     _newNT = _niEntities.NoteTypes.FirstOrDefault(_t => _t.NoteTypeId == _iNote.NoteTypeId);

            _niEntities.NoteTypes.Remove(_newNT);
            try
            {
                _niEntities.SaveChanges();
                Assert.Fail("Save Changes did not fail, because deleting on...");
            }
            catch (Exception _ex)
            {
                Console.WriteLine(_ex.Message);
                if (_ex.InnerException != null)
                {
                    Console.WriteLine(_ex.InnerException.ToString());
                }
            }
        }
Exemplo n.º 8
0
        //
        /// <summary>
        /// EMail the last ISP Report
        /// </summary>
        /// <param name="data"></param>
        private void EMailIspReport(NetworkIncidentSave data)
        {
            Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), string.Format("Entering, Mailing: {0}, incident: {1}", data.incident.AbuseEmailAddress, data.incident.IncidentId));
            var _notes = _niEntities.Incidents.Where(i => i.IncidentId == data.incident.IncidentId).FirstOrDefault()
                         .IncidentNotes.Where(n => n.NoteTypeId == Constants.incidentTypeIdOfIspReport).ToList( );

            if (_notes.Count > 0)
            {
                try
                {
                    IncidentNote _note = _notes[_notes.Count - 1];   // last ISP Rpt
                    // translate the message from json string of sendgrid type
                    JavaScriptSerializer j    = new JavaScriptSerializer();
                    SendGridMessage      _sgm = (SendGridMessage)j.Deserialize(_note.Note, typeof(SendGridMessage));
                    IEMail _email             = new EMail(Log.Logger).NewMailMessage(_sgm).Send( );
                }
                catch (Exception _ex)
                {
                    Log.Logger.Log(LoggingLevel.Error, data.user.UserName, MethodBase.GetCurrentMethod(), _ex.Message + ", " + data.incident.ToString(), _ex);
                }
            }
            Log.Logger.Log(LoggingLevel.Debug, data.user.UserName, MethodBase.GetCurrentMethod(), string.Format("Exiting, Mailing: {0}, incident: {1}", data.incident.AbuseEmailAddress, data.incident.IncidentId));
        }
Exemplo n.º 9
0
        //
        // Update one row of IncidentNotes
        //
        public int Update(IncidentNoteData data)
        {
            int _return        = 0;
            var _incidentNotes =
                from _r in _niEntities.IncidentNotes
                where _r.IncidentNoteId == data.IncidentNoteId
                select _r;

            if (_incidentNotes.Count() > 0)
            {
                IncidentNote _incidentNote = _incidentNotes.First();
                if (_incidentNote.NoteTypeId != data.NoteTypeId)
                {
                    _incidentNote.NoteTypeId = data.NoteTypeId;
                }
                if (_incidentNote.Note != data.Note)
                {
                    _incidentNote.Note = data.Note;
                }
                _return = 1;    // one row updated
            }
            return(_return);
        }