1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Luticate2.Auth.Auth.DataAccess;
- using Luticate2.Auth.Auth.DataAccess.Models;
- using Luticate2.Auth.Auth.Dbo;
- using Luticate2.Auth.Utils.Business.Crud;
- using Luticate2.Auth.Utils.Business.Fields;
- using Luticate2.Auth.Utils.Dbo.Fields;
- using Luticate2.Auth.Utils.Dbo.Result;
- using Microsoft.EntityFrameworkCore;
-
- namespace Luticate2.Auth.Auth.Business
- {
- 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 addResult = ConvertDboToModel(partialInput, dbo);
- if (!addResult)
- {
- return addResult.To<bool>();
- }
-
- var model = addResult.Data;
- 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 convertResult = ConvertModelToDbo(partialResponse, addedModel);
- if (!convertResult)
- {
- return convertResult.To<IList<LuGroupDbo>>();
- }
- addedDbos.Add(convertResult.Data);
- }
-
- return LuResult<IList<LuGroupDbo>>.Ok(addedDbos);
- }
- }
- }
|