Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LuGroupsBusiness.cs 2.8KB

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