Files
monorepo/LCU.API.Collections.RepoApi-old/LCU.API.Collections.RepoApi/Formatting/ReportCellFormatting.cs
T
2026-04-20 14:47:24 -05:00

72 lines
2.1 KiB
C#

using System;
using LCU.Shared.Collections.RepoApiLib.Models.Reporting.Responses;
namespace LCU.Shared.Collections.RepoApiLib.Formatting
{
public static class ReportCellFormatting
{
public static ReportCell CreateStringCell(string display)
{
return new ReportCell()
{
Display = string.IsNullOrEmpty(display) ? "-" : display
};
}
public static ReportCell CreateIntCell(int? number)
{
return new ReportCell()
{
Display = (number == null || number == 0) ? "-" : number?.ToString(),
Value = number
};
}
public static ReportCell CreateDecimalCell(decimal? number, bool displayZeroValue = false)
{
return new ReportCell()
{
Display = (number == null || (number == 0 && !displayZeroValue)) ? "-" : number?.ToString(),
Value = number
};
}
public static ReportCell CreatePercentageCell(decimal? number, bool isNormalized = false)
{
var display = "-";
if (number != null && number != 0)
{
if (!isNormalized)
{
number = number / 100;
}
display = string.Format(System.Globalization.CultureInfo.InvariantCulture,"{0:P2}", number);
}
return new ReportCell()
{
Display = display,
Value = number
};
}
public static ReportCell CreateDateCell(DateTime? dateTime)
{
return new ReportCell()
{
Display = dateTime?.ToString("MM/dd/yyyy") ?? "-",
Value = dateTime
};
}
public static ReportCell CreateCurrencyCell(decimal? amount)
{
return new ReportCell()
{
Display = (amount == null || amount == 0) ? "-" : string.Format("{0:C}", amount),
Value = amount
};
}
}
}