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 }; } } }