示例#1
0
        public void DeleteFinding(Finding finding)
        {
            FindingViewModel fm = new FindingViewModel(finding, assessmentContext);

            fm.Delete();
            fm.Save();
        }
示例#2
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);
                        }
                    }
                }
            }
        }
示例#3
0
        public List <Finding> AllFindings()
        {
            List <Finding> findings = new List <Finding>();

            var xxx = assessmentContext.FINDING
                      .Where(x => x.Answer_Id == this.answer_id)
                      .Include(i => i.Importance_)
                      .Include(k => k.FINDING_CONTACT)
                      .ToList();

            foreach (FINDING f in xxx)
            {
                Finding webF = new Finding();
                webF.Finding_Contacts = new List <FindingContact>();
                webF.Summary          = f.Summary;
                webF.Finding_Id       = f.Finding_Id;
                webF.Answer_Id        = this.answer_id;
                TinyMapper.Map(f, webF);
                if (f.Importance_ == null)
                {
                    webF.Importance = new Importance()
                    {
                        Importance_Id = 1,
                        Value         = Constants.SAL_LOW
                    }
                }
                ;
                else
                {
                    webF.Importance = TinyMapper.Map <IMPORTANCE, Importance>(f.Importance_);
                }

                foreach (FINDING_CONTACT fc in f.FINDING_CONTACT)
                {
                    FindingContact webFc = TinyMapper.Map <FINDING_CONTACT, FindingContact>(fc);

                    webFc.Selected = (fc != null);
                    webF.Finding_Contacts.Add(webFc);
                }
                findings.Add(webF);
            }
            return(findings);
        }
示例#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);
                        }
                    }
                }
            }
        }