Compare commits
4 Commits
2521d3d887
...
f72b6f26f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f72b6f26f3 | ||
|
|
eca0e34740 | ||
|
|
f385619bcf | ||
|
|
94da0733ce |
@@ -1,5 +1,6 @@
|
|||||||
using DigitalData.Core.Contracts.Application;
|
using DigitalData.Core.Contracts.Application;
|
||||||
using DigitalData.Core.Contracts.Infrastructure;
|
using DigitalData.Core.Contracts.Infrastructure;
|
||||||
|
using DigitalData.Core.DTO;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace DigitalData.Core.API
|
namespace DigitalData.Core.API
|
||||||
@@ -57,6 +58,7 @@ namespace DigitalData.Core.API
|
|||||||
var routeValues = new { id = createdResource.Id };
|
var routeValues = new { id = createdResource.Id };
|
||||||
return CreatedAtAction(actionName, routeValues, createdResource);
|
return CreatedAtAction(actionName, routeValues, createdResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BadRequest(result);
|
return BadRequest(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace DigitalData.Core.API
|
|||||||
/// <param name="services">The IServiceCollection to add services to.</param>
|
/// <param name="services">The IServiceCollection to add services to.</param>
|
||||||
/// <param name="resourcesPath">The path to the resource files used for localization.</param>
|
/// <param name="resourcesPath">The path to the resource files used for localization.</param>
|
||||||
/// <returns>The IServiceCollection for chaining.</returns>
|
/// <returns>The IServiceCollection for chaining.</returns>
|
||||||
public static IServiceCollection AddCookieBasedLocalizer(this IServiceCollection services, string resourcesPath)
|
public static IServiceCollection AddCookieBasedLocalizer(this IServiceCollection services, string resourcesPath = "")
|
||||||
{
|
{
|
||||||
// Adds localization services with the specified resources path.
|
// Adds localization services with the specified resources path.
|
||||||
services.AddLocalization(options => options.ResourcesPath = resourcesPath)
|
services.AddLocalization(options => options.ResourcesPath = resourcesPath)
|
||||||
|
|||||||
@@ -72,19 +72,19 @@ namespace DigitalData.Core.DTO
|
|||||||
return result.IsSuccess ? Try(result.Data) : Catch(result.Messages, result.Notices);
|
return result.IsSuccess ? Try(result.Data) : Catch(result.Messages, result.Notices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<I> Then<I>(this Task<Result> tResult, Func<I> Try, Func<List<string>, List<Notice>, I> Catch)
|
public static async Task<I> ThenAsync<I>(this Task<Result> tResult, Func<I> Try, Func<List<string>, List<Notice>, I> Catch)
|
||||||
{
|
{
|
||||||
Result result = await tResult;
|
Result result = await tResult;
|
||||||
return result.IsSuccess ? Try() : Catch(result.Messages, result.Notices);
|
return result.IsSuccess ? Try() : Catch(result.Messages, result.Notices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<I> Then<T, I>(this Task<DataResult<T>> tResult, Func<T, I> Try, Func<List<string>, List<Notice>, I> Catch)
|
public static async Task<I> ThenAsync<T, I>(this Task<DataResult<T>> tResult, Func<T, I> Try, Func<List<string>, List<Notice>, I> Catch)
|
||||||
{
|
{
|
||||||
DataResult<T> result = await tResult;
|
DataResult<T> result = await tResult;
|
||||||
return result.IsSuccess ? Try(result.Data) : Catch(result.Messages, result.Notices);
|
return result.IsSuccess ? Try(result.Data) : Catch(result.Messages, result.Notices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogNotice<T>(this ILogger<T> logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
|
public static void LogNotice(this ILogger logger, IEnumerable<Notice> notices, string start = ": ", string seperator = ". ", string end = ".\n")
|
||||||
{
|
{
|
||||||
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
|
foreach(LogLevel level in Enum.GetValues(typeof(LogLevel)))
|
||||||
{
|
{
|
||||||
@@ -106,5 +106,8 @@ namespace DigitalData.Core.DTO
|
|||||||
logger.Log(level, sb.ToString());
|
logger.Log(level, sb.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LogNotice(this ILogger logger, Result result, string start = ": ", string seperator = ". ", string end = ".\n")
|
||||||
|
=> logger.LogNotice(notices: result.Notices, start: start, seperator: seperator, end: end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,10 @@ namespace DigitalData.Core.DTO
|
|||||||
Data = data
|
Data = data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public bool HasFlag(Enum flag) => Notices.Any(n => n.Flag?.ToString() == flag.ToString());
|
||||||
|
|
||||||
|
public bool HasAnyFlag(params Enum[] flags) => flags.Any(f => HasFlag(f));
|
||||||
|
|
||||||
public static Result Success() => new() { IsSuccess = true };
|
public static Result Success() => new() { IsSuccess = true };
|
||||||
|
|
||||||
public static Result Fail() => new() { IsSuccess = false };
|
public static Result Fail() => new() { IsSuccess = false };
|
||||||
|
|||||||
Reference in New Issue
Block a user