Example #1
0
        public async Task Cadastrar([FromBody] CadastrarModel model)
        {
            model.ValidarCadastro();

            var verificaCpf = await _context
                              .Cliente
                              .AnyAsync(c => c.Cpf == model.Cpf);

            if (verificaCpf)
            {
                throw new Exception("CPF já cadastrado.");
            }

            var cliente = new Dominio.Entities.Cliente()
            {
                Cpf                = model.Cpf,
                NomeCompleto       = model.NomeCompleto,
                DataNascimento     = model.DataNascimento,
                Email              = model.Email,
                Telefone           = model.Telefone,
                DataCriacaoCliente = DateTime.Now
            };

            _context.Cliente.Add(cliente);

            await _context.SaveChangesAsync();
        }
Example #2
0
        public async Task Cadastrar([FromBody] CadastrarModel model)
        {
            model.ValidarCadastro();

            var verificaCpf = await _context
                              .Cliente
                              .AnyAsync(c => c.Cpf == model.Cpf);

            if (!verificaCpf)
            {
                throw new Exception("CPF não cadastrado.");
            }

            var verificaData = await _context
                               .Reserva
                               .Where(q => q.QuartoId == model.QuartoId)
                               .Where(r => r.StatusId == Status.EmAndamento)
                               .Where(d => d.DataSaida >= model.DataEntrada && d.DataEntrada < model.DataSaida)
                               .Include(s => s.StatusReserva)
                               .FirstOrDefaultAsync();

            if (verificaData != null)
            {
                throw new Exception($"Quarto {model.QuartoId} estará reservado nesta data.");
            }

            var quarto = await _context
                         .Quarto
                         .Where(q => q.QuartoId == model.QuartoId)
                         .FirstOrDefaultAsync();

            var reserva = new Dominio.Entities.Reserva
            {
                Cpf                = model.Cpf,
                QuartoId           = model.QuartoId,
                DataEntrada        = model.DataEntrada,
                DataSaida          = model.DataSaida,
                Hospedes           = new List <HospedeCpf>(),
                DataCriacaoReserva = DateTime.Now,
                StatusId           = Status.EmAndamento
            };

            _context.Reserva.Add(reserva);
            await _context.SaveChangesAsync();
        }
Example #3
0
        public async Task Editar(string cpf, [FromBody] CadastrarModel model)
        {
            model.ValidarCadastro();

            var cliente = await _context
                          .Cliente
                          .Where(c => c.Cpf == cpf)
                          .FirstOrDefaultAsync();

            if (cliente == null)
            {
                throw new Exception("Cpf não cadastrado.");
            }

            cliente.Cpf            = model.Cpf;
            cliente.NomeCompleto   = model.NomeCompleto;
            cliente.DataNascimento = model.DataNascimento;
            cliente.Email          = model.Email;
            cliente.Telefone       = model.Telefone;

            await _context.SaveChangesAsync();
        }