Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus-Goectau committed Oct 16, 2023
2 parents 7872e3f + 1b48e9e commit c6c0c15
Show file tree
Hide file tree
Showing 505 changed files with 30,094 additions and 27,244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1001" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.3" />
<PackageReference Include="Npoi.Mapper" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions CSETWebApi/CSETWebCore.AutoResponder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,17 @@ public void ProcessEmails()
{

ExcelProcess excel = new ExcelProcess();
#pragma warning disable CS8604 // Possible null reference argument.
string path = excel.BuildSheet(_context, configuration.GetValue<string>("ExcelWorkBookPassword"));

foreach(var email in configuration.GetSection("Notifications:Weekly").GetChildren())
{

_emailHelper.SendWeekly(path,
email.GetValue<string>("email"),
email.GetValue<string>("FirstName"),
email.GetValue<string>("LastName"));
#pragma warning restore CS8604 // Possible null reference argument.
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npoi.Mapper" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npoi.Mapper" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using CSETWebCore.Interfaces.Maturity;
using CSETWebCore.Model.Acet;
using CSETWebCore.Model.Maturity;
using CSETWebCore.Business.Acet;
using NPOI.SS.Formula.Functions;

namespace CSETWebCore.Business.ACETDashboard
{
Expand All @@ -37,20 +39,46 @@ public ACETDashboardBusiness(CSETContext context, IAssessmentUtil assessmentUtil
/// </summary>
/// <param name="assessmentId"></param>
/// <returns></returns>
public Model.Acet.ACETDashboard LoadDashboard(int assessmentId)
public Model.Acet.ACETDashboard LoadDashboard(int assessmentId, bool spanishFlag = false)
{
var result = GetIrpCalculation(assessmentId);

result.Domains = new List<DashboardDomain>();
Dictionary<string, IRPSpanishRow> dictionaryIrp = new Dictionary<string, IRPSpanishRow>();
Dictionary<string, GroupingSpanishRow> dictionaryDomain = new Dictionary<string, GroupingSpanishRow>();

List<MaturityDomain> domains = _maturity.GetMaturityAnswers(assessmentId, spanishFlag);

List<MaturityDomain> domains = _maturity.GetMaturityAnswers(assessmentId);
foreach (var d in domains)
{
result.Domains.Add(new DashboardDomain
{
Maturity = d.DomainMaturity,
Name = d.DomainName
});
}
if (spanishFlag)
{
dictionaryIrp = AcetBusiness.buildIRPDashboardDictionary();
dictionaryDomain = AcetBusiness.buildResultsGroupingDictionary();

var outputIrp = new IRPSpanishRow();
var outputGrouping = new GroupingSpanishRow();

foreach (var irp in result.Irps)
{
if (dictionaryIrp.TryGetValue(irp.HeaderText, out outputIrp))
{
irp.HeaderText = dictionaryIrp[irp.HeaderText].SpanishHeader;
}
}
foreach (var domain in result.Domains)
{
if (dictionaryDomain.TryGetValue(domain.Name, out outputGrouping))
{
domain.Name = dictionaryDomain[domain.Name].Spanish_Title;
}
}

}

Expand Down
250 changes: 249 additions & 1 deletion CSETWebApi/CSETWeb_Api/CSETWebCore.Business/Acet/AcetBusiness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Interfaces.Helpers;
using CSETWebCore.Interfaces.AdminTab;

using System.IO;
using NPOI.SS.UserModel;
using Npoi.Mapper;
using CSETWebCore.DataLayer.Manual;
using CSETWebCore.Model.Maturity;
using NPOI.SS.Formula.Functions;

namespace CSETWebCore.Business.Acet
{
Expand Down Expand Up @@ -206,5 +211,248 @@ public void UpdateACETDashboardSummary(int assessmentId, Model.Acet.ACETDashboar
_context.SaveChanges();

}

private static Dictionary<int, SpanishQuestionRow> dict = null;

public static Dictionary<int, SpanishQuestionRow> buildQuestionDictionary()
{
if (AcetBusiness.dict != null)
{
return AcetBusiness.dict;
}

String defaultPath = "App_Data\\ACET Spanish Question Mapping.xlsx";
MemoryStream memStream = new MemoryStream();
if(Path.Exists("..\\CSETWebCore.Business\\App_Data\\ACET Spanish Question Mapping.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\ACET Spanish Question Mapping.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<int, SpanishQuestionRow>();
}

FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<SpanishQuestionRow>> myExcelObjects = mapper.Take<SpanishQuestionRow>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;

AcetBusiness.dict = new Dictionary<int, SpanishQuestionRow>();

foreach (RowInfo<SpanishQuestionRow> item in myExcelObjects)
{
try
{
dict.Add(item.Value.Mat_Question_Id, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}
return dict;
}

public static Dictionary<int, GroupingSpanishRow> buildGroupingDictionary()
{
String defaultPath = "App_Data\\Spanish ACET Groupings.xlsx";
MemoryStream memStream = new MemoryStream();
if (Path.Exists("..\\CSETWebCore.Business\\App_Data\\Spanish ACET Groupings.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\Spanish ACET Groupings.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<int, GroupingSpanishRow>();
}
FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<GroupingSpanishRow>> myExcelObjects = mapper.Take<GroupingSpanishRow>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;

var dict = new Dictionary<int, GroupingSpanishRow>();
foreach (RowInfo<GroupingSpanishRow> item in myExcelObjects)
{
try
{
dict.Add(item.Value.Grouping_Id, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}

return dict;
}

public static Dictionary<string, GroupingSpanishRow> buildResultsGroupingDictionary()
{

String defaultPath = "App_Data\\Spanish ACET Groupings.xlsx";
MemoryStream memStream = new MemoryStream();
if (Path.Exists("..\\CSETWebCore.Business\\App_Data\\Spanish ACET Groupings.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\Spanish ACET Groupings.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<string, GroupingSpanishRow>();
}

FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<GroupingSpanishRow>> myExcelObjects = mapper.Take<GroupingSpanishRow>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;

var dict = new Dictionary<string, GroupingSpanishRow>();

foreach (RowInfo<GroupingSpanishRow> item in myExcelObjects)
{
try
{
dict.Add(item.Value.English_Title, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}
return dict;
}

public static Dictionary<int, IRPModel> buildIRPDictionary()
{
String defaultPath = "App_Data\\Spanish_Mapped_IRPS.xlsx";
MemoryStream memStream = new MemoryStream();
if (Path.Exists("..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRPS.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRPS.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<int, IRPModel>();
}

FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<IRPModel>> myExcelObjects = mapper.Take<IRPModel>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;

var dict = new Dictionary<int, IRPModel>();

foreach (RowInfo<IRPModel> item in myExcelObjects)
{
try
{
dict.Add(item.Value.IRP_Id, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}
return dict;
}

public static Dictionary<int, IRPSpanishRow> buildIRPHeaderDictionary()
{
String defaultPath = "App_Data\\Spanish_Mapped_IRP_Headers.xlsx";
MemoryStream memStream = new MemoryStream();
if (Path.Exists("..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRP_Headers.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRP_Headers.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<int, IRPSpanishRow>();
}

FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<IRPSpanishRow>> myExcelObjects = mapper.Take<IRPSpanishRow>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;
var dict = new Dictionary<int, IRPSpanishRow>();

foreach (RowInfo<IRPSpanishRow> item in myExcelObjects)
{
try
{
dict.Add(item.Value.IRP_Header_Id, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}

return dict;
}

public static Dictionary<string, IRPSpanishRow> buildIRPDashboardDictionary()
{
String defaultPath = "App_Data\\Spanish_Mapped_IRP_Headers.xlsx";
MemoryStream memStream = new MemoryStream();
if (Path.Exists("..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRP_Headers.xlsx"))
{
defaultPath = "..\\CSETWebCore.Business\\App_Data\\Spanish_Mapped_IRP_Headers.xlsx";
}
else if (!Path.Exists(defaultPath))
{
return new Dictionary<string, IRPSpanishRow>();
}

FileStream file = File.OpenRead(defaultPath);
file.CopyTo(memStream);

IWorkbook workbook = WorkbookFactory.Create(memStream);

var mapper = new Mapper(workbook);
List<RowInfo<IRPSpanishRow>> myExcelObjects = mapper.Take<IRPSpanishRow>(workbook.ActiveSheetIndex).ToList();

var rowCount = myExcelObjects.Count;
var dict = new Dictionary<string, IRPSpanishRow>();

// ACETDashboard
foreach (RowInfo<IRPSpanishRow> item in myExcelObjects)
{
try
{
dict.Add(item.Value.EnglishHeader, item.Value);
}
catch (Exception e)
{
NLog.LogManager.GetCurrentClassLogger().Error($"... {e}");
}
}

return dict;
}

}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit c6c0c15

Please sign in to comment.