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.

ModelsDbo.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Linq;
  2. using Luticate2.Utils.Dbo.OrderBy;
  3. using Luticate2.Utils.Utils;
  4. using WebApiWebSem.DataAccess.Models;
  5. using WebApiWebSem.Dbo.Articles;
  6. using WebApiWebSem.Dbo.ArticlesFields;
  7. namespace WebApiWebSem.DataAccess
  8. {
  9. public static class ModelsDbo
  10. {
  11. public static ArticlesFieldsDbo ToDbo(this articles_fields model)
  12. {
  13. if (model == null)
  14. {
  15. return null;
  16. }
  17. return new ArticlesFieldsDbo
  18. {
  19. Property = model.property,
  20. Type = model.type,
  21. Value = model.value
  22. };
  23. }
  24. public static ArticlesDbo ToDbo(this articles model)
  25. {
  26. if (model == null)
  27. {
  28. return null;
  29. }
  30. return new ArticlesDbo
  31. {
  32. CreatedAt = model.created_at.ToDbo(),
  33. Fields = model.articles_fields_fk.OrderBy(fields => fields.property).Select(fields => fields.ToDbo()).ToList(),
  34. Id = model.id,
  35. PictureCaption = model.picture_caption,
  36. PictureUrl = model.picture_url,
  37. Text = model.text,
  38. Type = model.type,
  39. UpdatedAt = model.updated_at.ToDbo()
  40. };
  41. }
  42. public static string ToDbPediaModel(this LuOrderByDbo orderByDbo)
  43. {
  44. return string.Join(" ", orderByDbo.Fields.Select(dbo =>
  45. {
  46. var order = dbo.Asc ? "ASC" : "DESC";
  47. return $"{order}(?{dbo.Name})";
  48. }));
  49. }
  50. }
  51. }