using System; using System.Linq; using Luticate2.Utils.DataAccess; using Microsoft.EntityFrameworkCore; using WebApiWebSem.DataAccess.Models; using WebApiWebSem.Dbo.Articles; namespace WebApiWebSem.DataAccess { public class ArticlesDataAccess : LuEfCrudDataAccess { public ArticlesDataAccess(IServiceProvider serviceProvider) : base(serviceProvider) { } protected override object GetId(string id) { return id; } protected override IQueryable GetGetQueryable(WsDbContext db, IQueryable table) { return table.Include(articles => articles.articles_fields_fk); } protected override DbSet GetTable(WsDbContext db) { return db.articles; } 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(); } } }