示例#1
0
        public async Task <IActionResult> PutFilmGenres(int id, FilmGenres filmGenres)
        {
            if (id != filmGenres.Id)
            {
                return(BadRequest());
            }

            _context.Entry(filmGenres).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FilmGenresExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <OutputEquipment> Create(Equipment equipment, Flags flags, CancellationToken token = default)
        {
            var result = new OutputEquipment
            {
                DetailsId = equipment.DetailsId,
                Id        = equipment.Id,
                Available = equipment.Available
            };

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

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

                result.Details = await DetailsHandler.Create(equipment.Details, _detailsFlags, token);
            }

            return(result);
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// Método AtualizaFerias
        /// </summary>
        /// <param name="ferias"></param>
        public void AtualizaFerias(Ferias ferias)
        {
            Ferias f = _context.Ferias.Find(ferias.ferias_id);

            f.dataFim               = ferias.dataFim;
            f.dataInicio            = ferias.dataInicio;
            _context.Entry(f).State = EntityState.Modified;
        }
        public async Task <IActionResult> GetDetails(int id, CancellationToken token = default)
        {
            var result = await _context.EquipmentDetails.FindAsync(id);

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

            await _context.Entry(result).Collection(
                details => details.Equipments
                ).LoadAsync(token);

            await _context.Entry(result).Reference(
                details => details.Type
                ).LoadAsync(token);

            return(Ok(await _detailsHandler.OutputFor(result, token)));
        }
示例#6
0
        public async Task <IEnumerable <OutputEquipment> > ListEquipments(CancellationToken token = default)
        {
            var result = await _context.Equipments
                         .Where(equipment => !equipment.IsArchived)
                         .ToListAsync(token);

            foreach (var row in result)
            {
                await _context.Entry(row)
                .Reference(item => item.Details)
                .LoadAsync(token);

                await _context.Entry(row.Details)
                .Reference(item => item.Type)
                .LoadAsync(token);
            }

            return(await Task.WhenAll(
                       result.Select(async row => await _equipmentHandler.OutputFor(row, token))
                       ));
        }
示例#7
0
        private async Task <IActionResult> UpdateEntry(InputEmployee input)
        {
            string cpf = input.Cpf;

            var entry = await _context.Employees
                        .FindAsync(cpf);

            await _context.Entry(entry)
            .Reference(row => row.User)
            .LoadAsync();

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

            var occupation = await _context.Occupations.FindAsync(input.OccupationId);

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

            Employee updated = input.ToModel(occupation, _passwordHash);

            entry.User.Name       = updated.User.Name;
            entry.User.SocialName = updated.User.SocialName;
            entry.User.BirthDate  = updated.User.BirthDate;
            entry.User.Phone      = updated.User.Phone;
            entry.User.Email      = updated.User.Email;
            entry.Gender          = updated.Gender;
            entry.Rg           = updated.Rg;
            entry.OccupationId = updated.OccupationId;
            entry.AccessLevel  = updated.AccessLevel;

            // we ignore password changes if the input
            // did not request one.

            if (input.Password != null)
            {
                entry.User.Password = updated.User.Password;
            }

            await _context.SaveChangesAsync();

            return(Ok(new OutputEmployee(entry)));
        }
示例#8
0
 /// <summary>
 /// Método AtualizaPessoa
 /// </summary>
 /// <param name="pessoa"></param>
 public void AtualizaPessoa(Pessoa pessoa)
 {
     _context.Entry(pessoa).State = EntityState.Modified;
 }
示例#9
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);
        }
示例#10
0
 /// <summary>
 /// Método AtualizarAula
 /// </summary>
 /// <param name="aula"></param>
 public void AtualizarAula(Aula aula)
 {
     _context.Entry(aula).State = EntityState.Modified;
 }