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.

ArticlesBusiness.cs 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Linq;
  2. using Luticate2.Utils.Business;
  3. using Luticate2.Utils.Dbo.Basic;
  4. using Luticate2.Utils.Dbo.PaginatedRequest;
  5. using Luticate2.Utils.Dbo.Result;
  6. using Luticate2.Utils.Interfaces;
  7. using Luticate2.Utils.Utils;
  8. using WebApiWebSem.DataAccess;
  9. using WebApiWebSem.Dbo.Articles;
  10. using WebApiWebSem.Dbo.ArticlesFields;
  11. namespace WebApiWebSem.Business
  12. {
  13. public class ArticlesBusiness : LuCrudBusiness<ArticlesDataAccess, ArticlesAddDbo, ArticlesDbo, ArticlesEditDbo, string>
  14. {
  15. private readonly DbPediaDataAccess _dbPediaDataAccess;
  16. public ArticlesBusiness(ArticlesDataAccess dataAccess, ILuNotificationsBusiness notificationsBusiness, DbPediaDataAccess dbPediaDataAccess) : base(dataAccess, notificationsBusiness)
  17. {
  18. _dbPediaDataAccess = dbPediaDataAccess;
  19. EntityType = "articles";
  20. }
  21. public override LuResult<LuPaginatedDbo<ArticlesDbo>> GetMultiple(LuPaginatedRequestDbo request)
  22. {
  23. var result = _dbPediaDataAccess.GetMultiple(request);
  24. if (result.Status == LuStatus.BackendError)
  25. {
  26. return base.GetMultiple(request);
  27. }
  28. foreach (var articlesAddDbo in result.Data.Data.Select(dbo => new ArticlesAddDbo
  29. {
  30. Fields = dbo.Fields.Select(fieldsDbo => new ArticlesFieldsAddDbo
  31. {
  32. Property = fieldsDbo.Property,
  33. Type = fieldsDbo.Type,
  34. Value = fieldsDbo.Value
  35. }).ToList(),
  36. Id = dbo.Id,
  37. PictureCaption = dbo.PictureCaption,
  38. PictureUrl = dbo.PictureUrl,
  39. Text = dbo.Text,
  40. Type = dbo.Type
  41. }))
  42. {
  43. var res = DataAccess.GetSingleById(articlesAddDbo.Id);
  44. if (res)
  45. {
  46. DataAccess.EditSingleByIdId(articlesAddDbo.Id, new ArticlesEditDbo
  47. {
  48. Fields = articlesAddDbo.Fields.Select(dbo => new ArticlesFieldsEditDbo
  49. {
  50. Property = dbo.Property,
  51. Type = dbo.Type,
  52. Value = dbo.Value
  53. }).ToList(),
  54. PictureCaption = articlesAddDbo.PictureCaption,
  55. PictureUrl = articlesAddDbo.PictureUrl,
  56. Text = articlesAddDbo.Text
  57. });
  58. }
  59. else if (res.Status == LuStatus.NotFound)
  60. {
  61. DataAccess.AddDbo(articlesAddDbo);
  62. }
  63. }
  64. return result;
  65. }
  66. }
  67. }