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.

LuGroupsBusiness.cs 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using Luticate2.Auth.Business.Crud;
  6. using Luticate2.Auth.Business.Fields;
  7. using Luticate2.Auth.DataAccess;
  8. using Luticate2.Auth.DataAccess.Models;
  9. using Luticate2.Auth.Dbo.Auth;
  10. using Luticate2.Auth.Dbo.Fields;
  11. using Luticate2.Auth.Dbo.Pagination;
  12. using Luticate2.Auth.Dbo.Result;
  13. using Microsoft.EntityFrameworkCore;
  14. namespace Luticate2.Auth.Business.Auth
  15. {
  16. public class LuGroupsBusiness : LuEfCrudBusiness<LuGroupDbo, LuGroups, Luticate2DbContext>
  17. {
  18. public LuGroupsBusiness(IServiceProvider serviceProvider) : base(serviceProvider)
  19. {
  20. }
  21. protected override LuResult<IQueryable<LuGroups>> Include(LuPartialFieldsDbo partialResponse, IQueryable<LuGroups> queryable)
  22. {
  23. var included = queryable;
  24. if (partialResponse.Fields.IsIncluded<LuGroupDbo>(x => x.Metadata))
  25. {
  26. included = included.Include(x => x.IdNavigation);
  27. }
  28. return LuResult<IQueryable<LuGroups>>.Ok(included);
  29. }
  30. // protected override LuResult<IQueryable<LuGroups>> Filter(LuFilterDbo filter, IQueryable<LuGroups> queryable)
  31. // {
  32. // return LuResult<IQueryable<LuGroups>>.Ok(queryable.Where(groups => groups.LuGroupsObjects.Any(objects => objects.Priority == 0)));
  33. // }
  34. public override LuResult<IList<LuGroupDbo>> Create(LuPartialFieldsDbo partialResponse,
  35. LuPartialFieldsDbo partialInput, IEnumerable<LuGroupDbo> dbos)
  36. {
  37. var addedDbos = new List<LuGroupDbo>();
  38. var addedModels = new List<LuGroups>();
  39. var createResult = Execute((context, set) =>
  40. {
  41. foreach (var dbo in dbos)
  42. {
  43. var model = new LuGroups();
  44. var addResult = ConvertDboToModel(partialInput, dbo, model);
  45. if (!addResult)
  46. {
  47. return addResult.To<bool>();
  48. }
  49. model.IdNavigation = new LuObjectsMetadata();
  50. set.Add(model);
  51. addedModels.Add(model);
  52. }
  53. context.SaveChanges();
  54. return LuResult<bool>.Ok(true);
  55. });
  56. if (!createResult)
  57. {
  58. return createResult.To<IList<LuGroupDbo>>();
  59. }
  60. var ids = addedModels.Select(x => x.Id);
  61. foreach (var addedModel in addedModels)
  62. {
  63. var addedDbo = new LuGroupDbo();
  64. var convertResult = ConvertModelToDbo(partialResponse, addedModel, addedDbo);
  65. if (!convertResult)
  66. {
  67. return convertResult.To<IList<LuGroupDbo>>();
  68. }
  69. addedDbos.Add(addedDbo);
  70. }
  71. return LuResult<IList<LuGroupDbo>>.Ok(addedDbos);
  72. }
  73. }
  74. }