private async Task CreateWithdraw(StudioContext context) { var employee = await context.Employees.OrderBy(row => row.UserId).FirstAsync(); var equipment = await context.Equipments.OrderBy(row => row.Id).FirstAsync(); var equipment2 = await context.Equipments.OrderBy(row => row.Id).Skip(1).FirstAsync(); var photoshoot = await context.PhotoShoots.OrderBy(row => row.Id).FirstAsync(); var photoshoot2 = await context.PhotoShoots.OrderBy(row => row.Id).Skip(1).FirstAsync(); var withdraw = new EquipmentWithdraw { WithdrawDate = DateTime.Now, ExpectedDevolutionDate = DateTime.Now + TimeSpan.FromHours(5), EffectiveDevolutionDate = DateTime.Now + TimeSpan.FromHours(3), Employee = employee, EmployeeCpf = employee.UserId, Equipment = equipment, EquipmentId = equipment.Id, PhotoShootId = photoshoot.Id, PhotoShoot = photoshoot }; var date = DateTime.Now + TimeSpan.FromDays(2); var withdraw2 = new EquipmentWithdraw { WithdrawDate = date, ExpectedDevolutionDate = date + TimeSpan.FromHours(5), EffectiveDevolutionDate = date + TimeSpan.FromHours(3), Employee = employee, EmployeeCpf = employee.UserId, Equipment = equipment2, EquipmentId = equipment2.Id, PhotoShootId = photoshoot2.Id, PhotoShoot = photoshoot2 }; await context.EquipmentWithdraws.AddAsync(withdraw); await context.EquipmentWithdraws.AddAsync(withdraw2); await context.SaveChangesAsync(); }
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); }
public Task <OutputWithdraw> OutputFor(EquipmentWithdraw withdraw, CancellationToken token = default) { return(Create(withdraw, _outputFlags, token)); }