示例#1
0
        public async Task <OutputEquipmentDetails> Create(EquipmentDetails details, Flags flags,
                                                          CancellationToken token = default)
        {
            var result = new OutputEquipmentDetails
            {
                Id     = details.Id,
                Name   = details.Name,
                Price  = details.Price,
                TypeId = details.TypeId
            };

            if ((flags & Flags.Type) != 0)
            {
                if (details.Type == null)
                {
                    await _context
                    .Entry(details)
                    .Reference(row => row.Type)
                    .LoadAsync(token);
                }

                result.Type = new OutputEquipmentType(details.Type);
            }

            if ((flags & Flags.Equipments) != 0)
            {
                EquipmentHandler = EquipmentHandler
                                   ?? throw new ArgumentNullException(nameof(EquipmentHandler));

                if (details.Equipments == null)
                {
                    await _context
                    .Entry(details)
                    .Collection(row => row.Equipments)
                    .LoadAsync(token);
                }

                var equipments = details.Equipments !
                                 .Select(async equipment =>
                                         await EquipmentHandler.Create(equipment, _equipmentFlags, token)
                                         );

                result.Equipments = await Task.WhenAll(equipments);
            }

            return(result);
        }
示例#2
0
        public async Task <OutputWithdraw> Create(EquipmentWithdraw withdraw, Flags flags, CancellationToken token)
        {
            var result = new OutputWithdraw
            {
                Id                      = withdraw.Id,
                WithdrawDate            = withdraw.WithdrawDate,
                PredictedDevolutionDate = withdraw.ExpectedDevolutionDate,
                EffectiveDevolutionDate = withdraw.EffectiveDevolutionDate
            };

            if ((flags & Flags.Employee) != 0)
            {
                if (withdraw.Employee == null)
                {
                    await _context
                    .Entry(withdraw)
                    .Reference(row => row.Employee)
                    .LoadAsync(token);
                }

                if (withdraw.Employee !.User == null)
                {
                    await _context
                    .Entry(withdraw.Employee)
                    .Reference(row => row.User)
                    .LoadAsync(token);
                }

                result.Employee = new OutputEmployee(withdraw.Employee);
            }

            if ((flags & Flags.Equipment) != 0)
            {
                EquipmentHandler = EquipmentHandler
                                   ?? throw new ArgumentNullException(nameof(EquipmentHandler));

                if (withdraw.Equipment == null)
                {
                    await _context.Entry(withdraw)
                    .Reference(row => row.Equipment)
                    .LoadAsync(token);
                }

                result.Equipment = await EquipmentHandler.Create(withdraw.Equipment, _equipmentFlags, token);
            }


            if ((flags & Flags.PhotoShoot) != 0)
            {
                if (withdraw.PhotoShoot == null)
                {
                    await _context.Entry(withdraw)
                    .Reference(row => row.PhotoShoot)
                    .LoadAsync(token);
                }

                result.PhotoShoot = new OutputPhotoShoot(withdraw.PhotoShoot, false);
            }

            return(result);
        }
示例#3
0
 public OutputEquipmentHandler Bind(OutputEquipmentHandler handler)
 {
     EquipmentHandler = handler;
     return(handler);
 }