12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using Luticate2.Utils.DataAccess;
- using Luticate2.Utils.Dbo.Filter;
- using Microsoft.EntityFrameworkCore;
- using WebApiWebSem.DataAccess.Models;
- using WebApiWebSem.Dbo.Articles;
-
- namespace WebApiWebSem.DataAccess
- {
- public class ArticlesDataAccess : LuEfCrudDataAccess<articles, ArticlesAddDbo, ArticlesDbo, ArticlesEditDbo, WsDbContext, string>
- {
- protected static IList<string> Types = new List<string>{"persons", "locations", "countries"};
-
- public ArticlesDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
- {
- }
-
- protected override object GetId(string id)
- {
- return id;
- }
-
- protected override IQueryable<articles> GetGetQueryable(WsDbContext db, IQueryable<articles> table)
- {
- return table.Include(articles => articles.articles_fields_fk);
- }
-
- protected override DbSet<articles> GetTable(WsDbContext db)
- {
- return db.articles;
- }
-
- protected string GetFilterType(LuFilterDbo filter)
- {
- var type = filter.GetFilterString("type", null);
- if (type == null || !Types.Contains(type.ToLower()))
- {
- return null;
- }
- return type.ToLower();
- }
-
- protected override Expression<Func<articles, bool>> GetFilterExpression(LuFilterDbo filter)
- {
- var type = GetFilterType(filter);
- return articles => type == null || articles.type == type;
- }
-
- protected override articles GetModelFromTCreate(ArticlesAddDbo obj)
- {
- return new articles
- {
- id = obj.Id,
- picture_caption = obj.PictureCaption,
- picture_url = obj.PictureUrl,
- type = obj.Type,
- articles_fields_fk = obj.Fields.Select(dbo => new articles_fields
- {
- property = dbo.Property,
- type = dbo.Type,
- value = dbo.Value
- }).ToList(),
- text = obj.Text
- };
- }
-
- protected override void EditModelFromTUpdate(ArticlesEditDbo obj, articles model)
- {
- model.picture_caption = obj.PictureCaption;
- model.picture_url = obj.PictureUrl;
- model.articles_fields_fk = obj.Fields.Select(dbo => new articles_fields
- {
- value = dbo.Value,
- property = dbo.Property,
- type = dbo.Type
- }).ToList();
- model.text = obj.Text;
- }
-
- protected override ArticlesDbo GetDboFromModel(articles model)
- {
- return model.ToDbo();
- }
- }
- }
|