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.0KB

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