Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LuOrderByParser.cs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. using Luticate2.Auth.Utils.Dbo;
  3. using Luticate2.Auth.Utils.Dbo.Pagination;
  4. using Luticate2.Auth.Utils.Dbo.Result;
  5. namespace Luticate2.Auth.Utils.Business.Pagination
  6. {
  7. public static class LuOrderByParser
  8. {
  9. public static LuResult<LuOrderByDbo> Parse(string data)
  10. {
  11. if (data == null)
  12. {
  13. data = "";
  14. }
  15. data = data.Trim();
  16. if (data != "")
  17. {
  18. var dbo = new LuOrderByDbo {OrderByFields = new List<LuOrderByFieldDbo>()};
  19. var fields = data.Split(',');
  20. foreach (var field in fields)
  21. {
  22. if (field == "")
  23. {
  24. return LuResult<LuOrderByDbo>.Error(LuStatus.InputError.ToInt(),
  25. $"LuOrderByParser: {data}", "Empty order by field");
  26. }
  27. var orderByField = new LuOrderByFieldDbo();
  28. // TODO parse
  29. // var split = field.Split(':');
  30. // if (split.Length > 2 || split.Length == 0)
  31. // {
  32. // return LuResult<LuOrderByDbo>.Error(LuStatus.InputError.ToInt(),
  33. // $"LuOrderByParser: {data}", "Invalid order by field syntax");
  34. // }
  35. // orderByField.Field = LuFieldDbo.Make(split[0]);
  36. // var order = split.Length == 2 ? split[1].ToLower() : "asc";
  37. // if (order == "asc")
  38. // {
  39. // orderByField.Asc = true;
  40. // }
  41. // else if (order == "desc")
  42. // {
  43. // orderByField.Asc = false;
  44. // }
  45. // else
  46. // {
  47. // return LuResult<LuOrderByDbo>.Error(LuStatus.InputError.ToInt(),
  48. // $"LuOrderByParser: {data}", "Empty order by field order");
  49. // }
  50. dbo.OrderByFields.Add(orderByField);
  51. }
  52. return LuResult<LuOrderByDbo>.Ok(dbo);
  53. }
  54. return LuResult<LuOrderByDbo>.Error(LuStatus.InputError.ToInt(), "Order by is empty or missing", "");
  55. }
  56. }
  57. }