namespace FamilyTreeAPI.Helper { public class Helpers { public static string GetFileContent(string extension) { string contentType = ""; /* https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types */ switch (extension) { case ".pdf": contentType = "application/pdf"; break; case ".txt": contentType = "text/plain"; break; case ".xlsx": contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case ".xls": contentType = "application/vnd.ms-excel"; break; case ".doc": contentType = "application/msword"; break; case ".odt": contentType = "application/vnd.oasis.opendocument.text"; break; case ".docx": contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case ".gif": contentType = "image/gif"; break; case ".ppt": contentType = "application/vnd.ms-powerpoint"; break; case ".ico": contentType = "image/vnd.microsoft.icon"; break; case ".png": contentType = "image/png"; break; case ".rar": contentType = "application/vnd.rar"; break; case ".zip": contentType = "application/zip"; break; case ".tar": contentType = "application/x-tar"; break; case ".mp4": contentType = "video/mp4"; break; case ".jpeg": case ".jpg": contentType = "image/jpeg"; break; case ".3gp": contentType = "video/3gpp"; break; case ".7z": contentType = "application/x-7z-compressed"; break; case ".tif": case ".tiff": contentType = "image/tiff"; break; // and so on // default: // throw new ArgumentOutOfRangeException($"Unable to find Content Type for file name {file.NameWithExtension}."); } return contentType; } public static string? DateToStr(DateTime? date) { string? result = null; if (date.HasValue) { result = date.Value.ToString("yyyy-MM-dd"); } return result; } public static DateTime? DateToDateTime(string? date) { DateTime? result = null; if (!string.IsNullOrEmpty(date)) { DateTime dt; if (DateTime.TryParse(date, out dt)) { result = dt; } } return result; } } }