12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography.X509Certificates;
- using Luticate2.Auth.Business.Crud;
- using Luticate2.Auth.Business.Fields;
- using Luticate2.Auth.DataAccess;
- using Luticate2.Auth.DataAccess.Models;
- using Luticate2.Auth.Dbo.Auth;
- using Luticate2.Auth.Dbo.Fields;
- using Luticate2.Auth.Dbo.Pagination;
- using Luticate2.Auth.Dbo.Result;
- using Microsoft.EntityFrameworkCore;
-
- namespace Luticate2.Auth.Business.Auth
- {
- public class LuGroupsBusiness : LuEfCrudBusiness<LuGroupDbo, LuGroups, Luticate2DbContext>
- {
- public LuGroupsBusiness(IServiceProvider serviceProvider) : base(serviceProvider)
- {
- }
-
- protected override LuResult<IQueryable<LuGroups>> Include(LuPartialFieldsDbo partialResponse, IQueryable<LuGroups> queryable)
- {
- var included = queryable;
- if (partialResponse.Fields.IsIncluded<LuGroupDbo>(x => x.Metadata))
- {
- included = included.Include(x => x.IdNavigation);
- }
-
- return LuResult<IQueryable<LuGroups>>.Ok(included);
- }
-
- // protected override LuResult<IQueryable<LuGroups>> Filter(LuFilterDbo filter, IQueryable<LuGroups> queryable)
- // {
- // return LuResult<IQueryable<LuGroups>>.Ok(queryable.Where(groups => groups.LuGroupsObjects.Any(objects => objects.Priority == 0)));
- // }
-
- public override LuResult<IList<LuGroupDbo>> Create(LuPartialFieldsDbo partialResponse,
- LuPartialFieldsDbo partialInput, IEnumerable<LuGroupDbo> dbos)
- {
- var addedDbos = new List<LuGroupDbo>();
- var addedModels = new List<LuGroups>();
- var createResult = Execute((context, set) =>
- {
- foreach (var dbo in dbos)
- {
- var model = new LuGroups();
- var addResult = ConvertDboToModel(partialInput, dbo, model);
- if (!addResult)
- {
- return addResult.To<bool>();
- }
- model.IdNavigation = new LuObjectsMetadata();
- set.Add(model);
- addedModels.Add(model);
- }
-
- context.SaveChanges();
-
- return LuResult<bool>.Ok(true);
- });
-
- if (!createResult)
- {
- return createResult.To<IList<LuGroupDbo>>();
- }
-
- var ids = addedModels.Select(x => x.Id);
-
- foreach (var addedModel in addedModels)
- {
- var addedDbo = new LuGroupDbo();
- var convertResult = ConvertModelToDbo(partialResponse, addedModel, addedDbo);
- if (!convertResult)
- {
- return convertResult.To<IList<LuGroupDbo>>();
- }
- addedDbos.Add(addedDbo);
- }
-
- return LuResult<IList<LuGroupDbo>>.Ok(addedDbos);
- }
- }
- }
|