Exemplo n.º 1
0
 /// <summary>
 /// Will not create a new assessment
 /// if you pass a non-existent finding then it will throw an exception
 /// </summary>
 /// <param name="finding_Id"></param>
 /// <param name="context"></param>
 public FindingViewModel(int finding_Id, CSET_Context context)
 {
     this.finding_Id = finding_Id;
     this.context    = context;
     this.dbFinding  = context.FINDING.Where(x => x.Finding_Id == finding_Id).FirstOrDefault();
     if (dbFinding == null)
     {
         throw new ApplicationException("Cannot find finding_id" + finding_Id);
     }
 }
Exemplo n.º 2
0
        public Finding GetFinding(int finding_id)
        {
            Finding webF;

            if (finding_id != 0)
            {
                FINDING f = assessmentContext.FINDING
                            .Where(x => x.Finding_Id == finding_id)
                            .Include(fc => fc.FINDING_CONTACT)
                            .FirstOrDefault();

                var q = assessmentContext.ANSWER.Where(x => x.Answer_Id == this.answer_id).FirstOrDefault();

                webF                  = TinyMapper.Map <Finding>(f);
                webF.Question_Id      = q != null ? q.Question_Or_Requirement_Id : 0;
                webF.Finding_Contacts = new List <FindingContact>();
                foreach (var contact in assessmentContext.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Id == assessment_id))
                {
                    FindingContact webContact = TinyMapper.Map <FindingContact>(contact);
                    webContact.Name     = contact.PrimaryEmail + " -- " + contact.FirstName + " " + contact.LastName;
                    webContact.Selected = (f.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == contact.Assessment_Contact_Id).FirstOrDefault() != null);
                    webF.Finding_Contacts.Add(webContact);
                }
            }
            else
            {
                var q = assessmentContext.ANSWER.Where(x => x.Answer_Id == this.answer_id).FirstOrDefault();

                FINDING f = new FINDING()
                {
                    Answer_Id = answer_id
                };


                assessmentContext.FINDING.Add(f);
                assessmentContext.SaveChanges();
                webF = TinyMapper.Map <Finding>(f);
                webF.Finding_Contacts = new List <FindingContact>();
                foreach (var contact in assessmentContext.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Id == assessment_id))
                {
                    FindingContact webContact = TinyMapper.Map <FindingContact>(contact);
                    webContact.Finding_Id = f.Finding_Id;
                    webContact.Name       = contact.PrimaryEmail + " -- " + contact.FirstName + " " + contact.LastName;
                    webContact.Selected   = false;
                    webF.Finding_Contacts.Add(webContact);
                }
            }

            return(webF);
        }
Exemplo n.º 3
0
        /// <summary>
        ///  The passed in finding is the source, if the ID does not exist it will create it.
        ///  this will also push the data to the database and retrieve any auto identity id's
        /// </summary>
        /// <param name="f">source finding</param>
        /// <param name="context">the data context to work on</param>
        public FindingViewModel(Finding f, CSET_Context context)
        {
            //get all the contacts in this assessment
            //get all the contexts on this finding
            this.webFinding = f;
            this.context    = context;
            this.dbFinding  = context.FINDING
                              .Include(x => x.FINDING_CONTACT)
                              .Where(x => x.Answer_Id == f.Answer_Id && x.Finding_Id == f.Finding_Id)
                              .FirstOrDefault();
            if (dbFinding == null)
            {
                var finding = new FINDING();
                finding.Answer_Id = f.Answer_Id;
                this.dbFinding    = finding;
                context.FINDING.Add(finding);
            }
            TinyMapper.Map(f, this.dbFinding);
            int importid = (f.Importance_Id == null) ? 1 : (int)f.Importance_Id;

            this.dbFinding.Importance_ = context.IMPORTANCE.Where(x => x.Importance_Id == importid).FirstOrDefault();//note that 1 is the id of a low importance

            if (f.Finding_Contacts != null)
            {
                foreach (FindingContact fc in f.Finding_Contacts)
                {
                    if (fc.Selected)
                    {
                        FINDING_CONTACT tmpC = dbFinding.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == fc.Assessment_Contact_Id).FirstOrDefault();
                        if (tmpC == null)
                        {
                            dbFinding.FINDING_CONTACT.Add(new FINDING_CONTACT()
                            {
                                Assessment_Contact_Id = fc.Assessment_Contact_Id, Finding_Id = f.Finding_Id
                            });
                        }
                    }
                    else
                    {
                        FINDING_CONTACT tmpC = dbFinding.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == fc.Assessment_Contact_Id).FirstOrDefault();
                        if (tmpC != null)
                        {
                            dbFinding.FINDING_CONTACT.Remove(tmpC);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///  The passed in finding is the source, if the ID does not exist it will create it.
        ///  this will also push the data to the database and retrieve any auto identity id's
        /// </summary>
        /// <param name="f">source finding</param>
        /// <param name="context">the data context to work on</param>
        public FindingViewModel(Finding f, CSET_Context context)
        {
            //get all the contacts in this assessment
            //get all the contexts on this finding
            this.webFinding = f;

            if (f.IsFindingEmpty())
            {
                return;
            }

            this.context = context;

            this.dbFinding = context.FINDING
                             .Include(x => x.FINDING_CONTACT)
                             .Where(x => x.Answer_Id == f.Answer_Id && x.Finding_Id == f.Finding_Id)
                             .FirstOrDefault();
            if (dbFinding == null)
            {
                var finding = new FINDING
                {
                    Answer_Id       = f.Answer_Id,
                    Summary         = f.Summary,
                    Impact          = f.Impact,
                    Issue           = f.Issue,
                    Recommendations = f.Recommendations,
                    Vulnerabilities = f.Vulnerabilities,
                    Resolution_Date = f.Resolution_Date
                };

                this.dbFinding = finding;
                context.FINDING.Add(finding);
            }

            TinyMapper.Map(f, this.dbFinding);

            int importid = (f.Importance_Id == null) ? 1 : (int)f.Importance_Id;

            this.dbFinding.Importance_ = context.IMPORTANCE.Where(x => x.Importance_Id == importid).FirstOrDefault();//note that 1 is the id of a low importance

            if (f.Finding_Contacts != null)
            {
                foreach (FindingContact fc in f.Finding_Contacts)
                {
                    if (fc.Selected)
                    {
                        FINDING_CONTACT tmpC = dbFinding.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == fc.Assessment_Contact_Id).FirstOrDefault();
                        if (tmpC == null)
                        {
                            dbFinding.FINDING_CONTACT.Add(new FINDING_CONTACT()
                            {
                                Assessment_Contact_Id = fc.Assessment_Contact_Id, Finding_Id = f.Finding_Id
                            });
                        }
                    }
                    else
                    {
                        FINDING_CONTACT tmpC = dbFinding.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == fc.Assessment_Contact_Id).FirstOrDefault();
                        if (tmpC != null)
                        {
                            dbFinding.FINDING_CONTACT.Remove(tmpC);
                        }
                    }
                }
            }
        }