12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.Linq;
- using Luticate2.Utils.Business;
- using Luticate2.Utils.Dbo.Basic;
- using Luticate2.Utils.Dbo.PaginatedRequest;
- using Luticate2.Utils.Dbo.Result;
- using Luticate2.Utils.Interfaces;
- using Luticate2.Utils.Utils;
- using WebApiWebSem.DataAccess;
- using WebApiWebSem.Dbo.Articles;
- using WebApiWebSem.Dbo.ArticlesFields;
-
- namespace WebApiWebSem.Business
- {
- public class ArticlesBusiness : LuCrudBusiness<ArticlesDataAccess, ArticlesAddDbo, ArticlesDbo, ArticlesEditDbo, string>
- {
- private readonly DbPediaDataAccess _dbPediaDataAccess;
-
- public ArticlesBusiness(ArticlesDataAccess dataAccess, ILuNotificationsBusiness notificationsBusiness, DbPediaDataAccess dbPediaDataAccess) : base(dataAccess, notificationsBusiness)
- {
- _dbPediaDataAccess = dbPediaDataAccess;
- EntityType = "articles";
- }
-
- public override LuResult<LuPaginatedDbo<ArticlesDbo>> GetMultiple(LuPaginatedRequestDbo request)
- {
- var result = _dbPediaDataAccess.GetMultiple(request);
- if (result.Status == LuStatus.BackendError)
- {
- return base.GetMultiple(request);
- }
- foreach (var articlesAddDbo in result.Data.Data.Select(dbo => new ArticlesAddDbo
- {
- Fields = dbo.Fields.Select(fieldsDbo => new ArticlesFieldsAddDbo
- {
- Property = fieldsDbo.Property,
- Type = fieldsDbo.Type,
- Value = fieldsDbo.Value
- }).ToList(),
- Id = dbo.Id,
- PictureCaption = dbo.PictureCaption,
- PictureUrl = dbo.PictureUrl,
- Text = dbo.Text,
- Type = dbo.Type
- }))
- {
- var res = DataAccess.GetSingleById(articlesAddDbo.Id);
- if (res)
- {
- DataAccess.EditSingleByIdId(articlesAddDbo.Id, new ArticlesEditDbo
- {
- Fields = articlesAddDbo.Fields.Select(dbo => new ArticlesFieldsEditDbo
- {
- Property = dbo.Property,
- Type = dbo.Type,
- Value = dbo.Value
- }).ToList(),
- PictureCaption = articlesAddDbo.PictureCaption,
- PictureUrl = articlesAddDbo.PictureUrl,
- Text = articlesAddDbo.Text
- });
- }
- else if (res.Status == LuStatus.NotFound)
- {
- DataAccess.AddDbo(articlesAddDbo);
- }
- }
- return result;
- }
- }
- }
|