123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections.Generic;
- using Luticate2.Utils.Dbo;
- using Luticate2.Utils.Dbo.Result;
- using Luticate2.Utils.Middlewares;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
-
- namespace Luticate2.Utils.Controllers
- {
- public static class LuUtilsExtensions
- {
- public static IServiceCollection AddLuticatUtils(this IServiceCollection services)
- {
-
- return services;
- }
-
- public static IMvcBuilder AddLuticatUtils(this IMvcBuilder builder)
- {
- return builder;
- }
-
- public static IApplicationBuilder UseLuticateUtils(this IApplicationBuilder app)
- {
- // app.UseMiddleware<LuAuthMiddleware>();
- app.UseMiddleware<LuExceptionMiddleware>();
- return app;
- }
-
- public static int GetHttpCode<T>(this LuResult<T> result)
- {
- if (result.Status == LuStatus.Success)
- {
- return 200;
- }
- if (result.Status == LuStatus.InputError)
- {
- return 400;
- }
- if (result.Status == LuStatus.LoginError)
- {
- return 401;
- }
- if (result.Status == LuStatus.PermissionError)
- {
- return 403;
- }
- if (result.Status == LuStatus.NotFound)
- {
- return 404;
- }
- if (result.Status == LuStatus.DbError)
- {
- return 500;
- }
- if (result.Status == LuStatus.InternalError)
- {
- return 500;
- }
- return 418;
- }
-
- public static IDictionary<object, object> GetLuItems(this HttpContext context)
- {
- return (IDictionary<object, object>) context.Items["luticateItems"];
- }
- }
- }
|