Exemplo n.º 1
0
        public async Task <IActionResult> Novo([FromBody] CriarBlocoDaAgendaDto criarBlocoDaAgendaDto)
        {
            var blocoAgenda = await this.CriarBlocoDaAgenda(criarBlocoDaAgendaDto);

            await this.LigarBlocoDaAgendaEstabelecimento(criarBlocoDaAgendaDto.EstabelecimentoId, blocoAgenda.Id);

            await this.LigarBlocoDaAgendaCliente(blocoAgenda.Id);

            // await this.LigarBlocoDaAgendaFuncionario(criarBlocoDaAgendaDto.FuncionarioId,blocoAgenda.Id);

            return(StatusCode(201));
        }
Exemplo n.º 2
0
        // public async Task<ICollection<UsuarioBlocoDaAgenda>> AgendaDeUsuarioLogadoAgendaFuncinario(int id)
        // {
        //     var x = await GetAllUsuariosBlocosDaAgenda()
        //                         .Include(i => i.Usuario)
        //                         .Include(i => i.BlocoDaAgenda)
        //                             .ThenInclude(i => i.Prestadores)
        //                             .ThenInclude(i => i.Conta)
        //                         .Include(i => i.BlocoDaAgenda)
        //                             .ThenInclude(i => i.Servicos)
        //                         .Include(i => i.BlocoDaAgenda)
        //                             .ThenInclude(i => i.Local)
        //                         .Include(i => i.BlocoDaAgenda)
        //                             .ThenInclude(i => i.Clientes)
        //                         .Where(x => x.BlocoDaAgenda.Prestadores.ToList().Any(i=> i.Conta.Id == id)).ToListAsync();
        //     return x;
        // }

        public async Task <BlocoDaAgenda> CriarBlocoDaAgenda(CriarBlocoDaAgendaDto criarBlocoDaAgendaDto)
        {
            DateTime myDate = DateTime.ParseExact(criarBlocoDaAgendaDto.Inicio, "dd-MM-yyyy HH:mm:ss,fff",
                                                  System.Globalization.CultureInfo.InvariantCulture);

            var usuarioCliente = await this.context.Usuarios.FirstOrDefaultAsync(x => x.Email == criarBlocoDaAgendaDto.ClienteEmail);

            var funcionarioPrestador = await this.context.Funcionarios.Include(i => i.Conta).FirstOrDefaultAsync(x => x.Id == criarBlocoDaAgendaDto.FuncionarioId);

            var local = await this.context.Estabelecimentos.Include(i => i.Agenda).FirstOrDefaultAsync(x => x.Id == criarBlocoDaAgendaDto.FuncionarioId);

            var servicoPrestado = await this.context.Servicos.FirstOrDefaultAsync(x => x.Id == criarBlocoDaAgendaDto.ServicoId);


            BlocoDaAgenda novoBloco = new BlocoDaAgenda {
                Comeco    = myDate,
                Cancelado = false,
                Servicos  = new List <Servico> {
                    servicoPrestado
                },
                Local       = local,
                Prestadores = new List <Funcionario> {
                    funcionarioPrestador
                },
                // Clientes = new List<UsuarioBlocoDaAgenda>()
            };

            novoBloco.Clientes = new List <UsuarioBlocoDaAgenda> {
                new UsuarioBlocoDaAgenda {
                    Usuario = usuarioCliente, BlocoDaAgenda = novoBloco
                }
            };

            await this.context.BlocosDaAgenda.AddAsync(novoBloco);

            await this.context.SaveChangesAsync();

            //System.Console.WriteLine(local.Agenda);
            // if (local.Agenda == null)
            // {
            //     local.Agenda  =new List<BlocoDaAgenda>{novoBloco};
            // }
            // else
            // {
            //     local.Agenda.Add(novoBloco);
            // }
            // await this.context.SaveChangesAsync();
            return(novoBloco);
        }