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.

ArticlesDataAccess.cs 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Linq;
  3. using Luticate2.Utils.DataAccess;
  4. using Microsoft.EntityFrameworkCore;
  5. using WebApiWebSem.DataAccess.Models;
  6. using WebApiWebSem.Dbo.Articles;
  7. namespace WebApiWebSem.DataAccess
  8. {
  9. public class ArticlesDataAccess : LuEfCrudDataAccess<articles, ArticlesAddDbo, ArticlesDbo, ArticlesEditDbo, WsDbContext, string>
  10. {
  11. public ArticlesDataAccess(IServiceProvider serviceProvider) : base(serviceProvider)
  12. {
  13. }
  14. protected override object GetId(string id)
  15. {
  16. return id;
  17. }
  18. protected override IQueryable<articles> GetGetQueryable(WsDbContext db, IQueryable<articles> table)
  19. {
  20. return table.Include(articles => articles.articles_fields_fk);
  21. }
  22. protected override DbSet<articles> GetTable(WsDbContext db)
  23. {
  24. return db.articles;
  25. }
  26. protected override articles GetModelFromTCreate(ArticlesAddDbo obj)
  27. {
  28. return new articles
  29. {
  30. id = obj.Id,
  31. picture_caption = obj.PictureCaption,
  32. picture_url = obj.PictureUrl,
  33. type = obj.Type,
  34. articles_fields_fk = obj.Fields.Select(dbo => new articles_fields
  35. {
  36. property = dbo.Property,
  37. type = dbo.Type,
  38. value = dbo.Value
  39. }).ToList(),
  40. text = obj.Text
  41. };
  42. }
  43. protected override void EditModelFromTUpdate(ArticlesEditDbo obj, articles model)
  44. {
  45. model.picture_caption = obj.PictureCaption;
  46. model.picture_url = obj.PictureUrl;
  47. model.articles_fields_fk = obj.Fields.Select(dbo => new articles_fields
  48. {
  49. value = dbo.Value,
  50. property = dbo.Property,
  51. type = dbo.Type
  52. }).ToList();
  53. model.text = obj.Text;
  54. }
  55. protected override ArticlesDbo GetDboFromModel(articles model)
  56. {
  57. return model.ToDbo();
  58. }
  59. }
  60. }