private ReturnResultDTO CheckExistingData(int scanId) { ReturnResultDTO dto = new ReturnResultDTO(); using (var context = new WebParserEntities()) { List <int> plugins = context.MasterPlugins.Select(x => x.PluginID).Distinct().ToList(); var plgData = context.CurrScans.Where(c => plugins.Contains(c.PluginID) == false && c.Compliance == false && c.ScanID == scanId).ToList(); var cntOfPlgData = plgData.Select(c => c.PluginID).Distinct().Count(); if (cntOfPlgData > 0) { dto.NewPluginMessage = "New Plugins found. Please update"; dto.NewPluginCount = cntOfPlgData; } else { dto.NewPluginMessage = "Ok"; dto.NewPluginCount = cntOfPlgData; } List <string> complianceCheckIDList = context.ComplianceMasters.Select(c => c.ComplianceCheckID).Distinct().ToList(); var compData = context.CurrScans.Where(c => complianceCheckIDList.Contains(c.ComplianceCheckID) == false && c.Compliance == true && c.ScanID == scanId).ToList(); var compDataCount = compData.Select(c => c.ComplianceCheckID).Distinct().Count(); if (compDataCount > 0) { dto.NewComplianceMessage = "New Compliance Checks found. Please update"; dto.NewComplianceCount = compDataCount; } else { dto.NewComplianceMessage = "Ok"; dto.NewComplianceCount = compDataCount; } List <MasterPlugin> masterPlugindata = context.MasterPlugins.Where(v => v.PluginOutputReportable == true && v.PluginOutPut != null).ToList(); var count = (from item in context.CurrScans join plg in masterPlugindata on item.PluginID equals plg.PluginID where item.PluginOutput != plg.PluginOutPut && item.ScanID == scanId && item.Compliance == false select item).Count(); if (count > 0) { dto.NewVarianceMessage = "Plugin output variance found.Please review."; dto.NewVarianceCount = count; } else { dto.NewVarianceMessage = "Ok"; dto.NewVarianceCount = count; } dto.IsSuccess = true; return(dto); } }
public ReturnResultDTO UpdateMasterPluginData(List <MasterPluginDTO> input) { //List<int> pluginIds=input.Select(c=>c. ReturnResultDTO dt = new ReturnResultDTO(); try { bool isUpdated = false; int plgId = 0; using (var context = new WebParserEntities()) { input.ForEach(c => { plgId = int.Parse(c.PluginId.ToString()); var data = context.MasterPlugins.FirstOrDefault(v => v.PluginID == plgId); if (data != null) { isUpdated = true; data.Description = c.Description; data.Synopsis = c.Synopsis; data.PluginOutPut = c.PluginOutPut; data.RiskFactor = c.Riskfactor; data.PluginOutputReportable = c.PluginOutPutReportable; data.Reportable = c.Reportable; data.Solution = c.Solution; } }); if (isUpdated) { context.SaveChanges(); dt.Message = "Update successfull."; dt.IsSuccess = true; } else { dt.Message = "No matchin plugin found."; dt.IsSuccess = true; } return(dt); } } catch (Exception ex) { throw ex; } }
public ReturnResultDTO UpdateMasterCompliance(List <MasterComplianceDTO> input) { //List<int> pluginIds=input.Select(c=>c. ReturnResultDTO dt = new ReturnResultDTO(); bool isUpdated = false; try { int plgId = 0; using (var context = new WebParserEntities()) { input.ForEach(c => { plgId = int.Parse(c.PluginId.ToString()); var data = context.ComplianceMasters.FirstOrDefault(v => v.PluginId == plgId); if (data != null) { isUpdated = true; data.Description = c.Description; data.Reportable = c.Reportable; data.RiskFactor = c.Riskfactor; data.Category1 = c.Category1; data.Category2 = c.Category2; } }); if (isUpdated) { context.SaveChanges(); dt.Message = "Update successfull."; dt.IsSuccess = true; } else { dt.Message = "No matchin plugin found."; dt.IsSuccess = true; } return(dt); } } catch (Exception ex) { throw ex; } //} }
public ReturnResultDTO UpdatePluginVariance2(List <MasterPluginDTO> input) { //List<int> pluginIds=input.Select(c=>c. ReturnResultDTO dt = new ReturnResultDTO(); bool isUpdated = false; int plgId = 0; try { using (var context = new WebParserEntities()) { input.ForEach(c => { plgId = int.Parse(c.PluginId.ToString()); var data = context.CurrScans.FirstOrDefault(v => v.PluginID == plgId && v.ComplianceCheckID == c.ComplianceCheckID); if (data != null) { isUpdated = true; data.PluginOutputReportable = c.PluginOutPutReportable; } }); if (isUpdated) { context.SaveChanges(); dt.Message = "Update successfull."; dt.IsSuccess = true; } else { dt.Message = "No matchin plugin found."; dt.IsSuccess = true; } return(dt); } } catch (Exception ex) { throw ex; } }
public ReturnResultDTO ImportXmlData(List <ImportXMLDataDTO> inputDTOList) { int scanId = 0; int subScnaID = 0; ReturnResultDTO dtoItem; if (inputDTOList.Any(c => c.IsAdditionalScan)) { //Generate New ScanID; scanId = inputDTOList.First().ScanId; subScnaID = inputDTOList.First().SubScanId + 1; } //Create MasterScan ScanMaster master = CreateScanMaster(scanId, subScnaID, inputDTOList.First().UserId, inputDTOList.First().ClientName, inputDTOList.First().ScanDate, inputDTOList.First().ScanName); using (var context = new WebParser.DAL.DataModel.WebParserEntities()) { if (!inputDTOList.Any(c => c.IsAdditionalScan)) { ScanNumber newNumber = new ScanNumber() { UserId = inputDTOList.First().UserId }; context.ScanNumbers.Add(newNumber); context.SaveChanges(); var userID = inputDTOList.First().UserId; var listOfScan = context.ScanNumbers.Where(c => c.UserId == userID).ToList(); scanId = listOfScan.Last().ScanId; master.ScanId = scanId; } foreach (var item in inputDTOList) { CurrScan newItem = CreateCurrentScan(item, scanId, subScnaID); master.CurrScans.Add(newItem); //context.CurrScans.Add(newItem); } context.ScanMasters.Add(master); int value = 0; try { using (TransactionScope trans = new TransactionScope()) { value = context.SaveChanges(); if (value > 0) { dtoItem = CheckExistingData(scanId); dtoItem.IsSuccess = true; trans.Complete(); } else { dtoItem = new ReturnResultDTO(); dtoItem.IsSuccess = false; trans.Dispose(); } } } catch (Exception ex) { throw ex; } } return(dtoItem); }
protected void btnsave_Click(object sender, EventArgs e) { XDocument myDoc = XDocument.Load(fileUpload1.FileContent); XNamespace cm = myDoc.Descendants("Report").First().Attributes().ElementAt(1).Value; var dtl = (from r in myDoc.Descendants("ReportItem") select new ImportXMLDataDTO() { ReportHost = r.Parent.Attribute("name").Value, ClientName = txtClientName.Text, ScanDate = DateTime.Parse(txtDate.Text), ScanName = txtNewScanName.Text, IsAdditionalScan = rdbtnAddtional.Checked, ScanId = Session["ScanId"] != null ? Convert.ToInt32(Session["ScanId"]) : 0, SubScanId = Session["SubscanId"] != null ? Convert.ToInt32(Session["SubscanId"]) : 0, UserId = Session["UserName"] as string, PlugId = r.Attribute("pluginID").Value, Port = r.Attribute("port") == null ? null : r.Attribute("port").Value, Compliance = r.Element("compliance") == null ? null : r.Element("compliance").Value, ComplianceResult = r.Element(cm + "compliance-result") == null ? null : r.Element(cm + "compliance-result").Value, ComplianceActualValue = r.Element(cm + "compliance-actual-value") == null ? null : r.Element(cm + "compliance-actual-value").Value, ComplianceCheckID = r.Element(cm + "compliance-check-id") == null ? null : r.Element(cm + "compliance-check-id").Value, ComplianceOutPut = r.Element(cm + "compliance-output") == null ? null : r.Element(cm + "compliance-output").Value, CompliancePolicyValue = r.Element(cm + "compliance-policy-value") == null ? null : r.Element(cm + "compliance-policy-value").Value, Description = r.Element("description") == null ? null : r.Element("description").Value, ExploitAvailable = r.Element("exploit_available") == null ? null : r.Element("exploit_available").Value, ExploitabilityEase = r.Element("exploitability_ease") == null ? null : r.Element("exploitability_ease").Value, ExploitedByMalware = r.Element("exploited_by_malware") == null ? null : r.Element("exploited_by_malware").Value, RiskFactor = r.Element("risk_factor") == null ? null : r.Element("risk_factor").Value, SeeLAlso = r.Element("see_also") == null ? null : r.Element("see_also").Value, Solution = r.Element("solution") == null ? null : r.Element("solution").Value, Synopsis = r.Element("synopsis") == null ? null : r.Element("synopsis").Value, PluginOutput = r.Element("plugin_output") == null ? null : r.Element("plugin_output").Value, ComplianceCheckName = r.Element(cm + "compliance-check-name") == null ? null : r.Element(cm + "compliance-check-name").Value, Complianceinfo = r.Element(cm + "compliance-info") == null ? null : r.Element(cm + "compliance-info").Value, ComplianceSeeAlso = r.Element(cm + "compliance-see-also") == null ? null : r.Element(cm + "compliance-see-also").Value, ComplianceSolution = r.Element(cm + "compliance-solution") == null ? null : r.Element(cm + "compliance-solution").Value, }).ToList(); var obj = new OperationFunctions(); try { ReturnResultDTO retValue = obj.ImportXmlData(dtl); if (retValue.IsSuccess) { txtNewScanName.Text = string.Empty; txtDate.Text = string.Empty; txtClientName.Text = string.Empty; lblmessage.Visible = true; lblmessage.Text = "Upload successfull."; lblComplianceMessage.Text = retValue.NewComplianceMessage; lblNewCompaliance.Text = retValue.NewComplianceCount.ToString(); lblNewPlugins.Text = retValue.NewPluginCount.ToString(); lblPluginMessage.Text = retValue.NewPluginMessage; lblNewVariance.Text = retValue.NewVarianceCount.ToString(); lblVarianceMessage.Text = retValue.NewVarianceMessage; pnlMessage.Visible = true; RadioButton1.Checked = true; } else { lblmessage.Visible = true; lblmessage.Text = "Import failed."; RadioButton1.Checked = true; } } catch (Exception ex) { lblmessage.Visible = true; lblmessage.Text = "Import failed."; //throw; } }