Updated daily report to show correct information when two work weeks split quarters.
Also current changes to project with Blazor implementation is implemented here as well.
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ReportingServices.Shared.Blazor.HelperClasses;
|
||||
|
||||
public static class APIHelperFunctions
|
||||
{
|
||||
public static string GetBeginningOfWeekAsAPIString()
|
||||
{
|
||||
DateTime date = DateTime.Now;
|
||||
|
||||
int dayOfWeek = (int)date.DayOfWeek;
|
||||
|
||||
date = dayOfWeek switch
|
||||
{
|
||||
0 => date.AddDays(-6),
|
||||
1 => date,
|
||||
_ => date.AddDays(1 - dayOfWeek)
|
||||
};
|
||||
|
||||
return GetDateTimeAsAPIString(date.ToString(), false);
|
||||
}
|
||||
|
||||
public static string GetDateWithOffsetAsAPIString(string dateString, float offset)
|
||||
{
|
||||
DateTime date = DateTime.Parse(dateString);
|
||||
|
||||
date = date.AddHours(offset);
|
||||
|
||||
return GetDateTimeAsAPIString(date.ToString(), true);
|
||||
}
|
||||
|
||||
public static string GetDateTimeAsAPIString(string dateString, bool fullDateTime)
|
||||
{
|
||||
DateTime date = DateTime.Parse(dateString);
|
||||
|
||||
if (fullDateTime)
|
||||
dateString = date.ToString("yyyy-M-d HH:mm:ss");
|
||||
else
|
||||
dateString = date.Year + "-" + date.Month + "-" + date.Day + " 0:0:0";
|
||||
|
||||
return dateString;
|
||||
}
|
||||
|
||||
public static List<T> ReverseList<T>(List<T> inputList)
|
||||
{
|
||||
List<T> temp = new();
|
||||
|
||||
for (int i = inputList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
temp.Add(inputList[i]);
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public static string SplitOnCamelCase(string input)
|
||||
{
|
||||
Regex r = new(@"
|
||||
(?<=[A-Z])(?=[A-Z][a-z]) |
|
||||
(?<=[^A-Z])(?=[A-Z]) |
|
||||
(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
return r.Replace(input, " ");
|
||||
}
|
||||
}
|
19
ReportingServices.Shared.Blazor/HelperClasses/ApiCaller.cs
Normal file
19
ReportingServices.Shared.Blazor/HelperClasses/ApiCaller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.Shared.Blazor.HelperClasses;
|
||||
|
||||
public static class ApiCaller
|
||||
{
|
||||
public static async Task<T> GetApi<T>(string url)
|
||||
{
|
||||
T deserializedJson = default;
|
||||
|
||||
using (HttpClient client = new())
|
||||
{
|
||||
string apiResponse = await client.GetStringAsync(url);
|
||||
deserializedJson = JsonSerializer.Deserialize<T>(apiResponse);
|
||||
}
|
||||
|
||||
return deserializedJson;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReportingServices.Shared.Blazor.HelperClasses;
|
||||
|
||||
public static class JsonFileHandler
|
||||
{
|
||||
public static T LoadJSONFile<T>(string file)
|
||||
{
|
||||
string json = File.ReadAllText(file);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
public static void SaveJSONFile<T>(T obj, string file)
|
||||
{
|
||||
string json = JsonSerializer.Serialize(obj);
|
||||
File.WriteAllText(file, json);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user