Beispiel #1
0
        public async Task <IActionResult> UpdateWithdraw(int id, InputWithdraw input)
        {
            var entry = await _context.EquipmentWithdraws.FindAsync(id);

            if (entry == null)
            {
                return(NotFound());
            }

            var references = await FindReferences(input);

            if (references == null)
            {
                return(NotFound());
            }

            var updated = input.ToModel(references.Value);

            entry.WithdrawDate            = updated.WithdrawDate;
            entry.ExpectedDevolutionDate  = updated.ExpectedDevolutionDate;
            entry.EffectiveDevolutionDate = updated.EffectiveDevolutionDate;
            entry.PhotoShootId            = updated.PhotoShootId;
            entry.PhotoShoot  = updated.PhotoShoot;
            entry.EmployeeCpf = updated.EmployeeCpf;
            entry.Employee    = updated.Employee;
            entry.EquipmentId = updated.EquipmentId;
            entry.Equipment   = updated.Equipment;

            await _context.SaveChangesAsync();

            return(Ok(await _withdrawHandler.OutputFor(entry)));
        }
Beispiel #2
0
        private async Task <(Employee, Equipment, PhotoShoot)?> FindReferences(InputWithdraw input)
        {
            var employee = await _context.Employees.FindAsync(input.EmployeeCpf);

            if (employee == null)
            {
                return(null);
            }

            var equipment = await _context.Equipments.FindAsync(input.EquipmentId);

            if (equipment == null)
            {
                return(null);
            }

            var shoot = await
                        _context
                        .PhotoShoots
                        .FirstOrDefaultAsync(row => row.ResourceId == input.PhotoShootId);

            if (shoot == null)
            {
                return(null);
            }

            return(employee, equipment, shoot);
        }
Beispiel #3
0
        public async Task <IActionResult> AddWithdraw(InputWithdraw input)
        {
            var references = await FindReferences(input);

            if (references == null)
            {
                return(NotFound());
            }

            var withdraw = input.ToModel(references.Value);

            await _context.EquipmentWithdraws.AddAsync(withdraw);

            await _context.SaveChangesAsync();

            return(Ok(await _withdrawHandler.OutputFor(withdraw)));
        }