You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuController.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. using Luticate2.Utils.Dbo.Basic;
  3. using Luticate2.Utils.Dbo.Result;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Options;
  6. namespace Luticate2.Utils.Controllers
  7. {
  8. public abstract class LuController : Controller
  9. {
  10. protected readonly LuUtilsOptionsDbo LuUtilsOptionsDbo;
  11. protected IDictionary<object, object> LuItems => HttpContext.GetLuItems();
  12. protected LuController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo)
  13. {
  14. LuUtilsOptionsDbo = luUtilsOptionsDbo.Value;
  15. }
  16. protected virtual LuApiWrapperDbo<T> Handle<T>(LuResult<T> result)
  17. {
  18. if (result)
  19. {
  20. return new LuApiWrapperDbo<T>
  21. {
  22. code = 200,
  23. data = result.Data,
  24. message = null,
  25. version = LuUtilsOptionsDbo.Version
  26. };
  27. }
  28. throw new LuResultException(result.To<object>());
  29. }
  30. protected virtual LuApiWrapperDbo<LuBoxedValueDbo<T>> HandleBoxed<T>(LuResult<T> result)
  31. {
  32. return Handle(result.To(arg => new LuBoxedValueDbo<T>
  33. {
  34. Value = arg
  35. }));
  36. }
  37. }
  38. }