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 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);
- }
- }
- }
|