public async Task <IActionResult> Create(AgendamentoDto dto)
        {
            ViewBag.Periodo  = Combos.retornarOpcoesPeriodo();
            ViewBag.TipoSala = Combos.retornarOpcoesSala();

            dto.Validate();
            if (dto.Invalid)
            {
                TempData["Notificacao"] = new BadRequestDto(dto.Notifications, TipoNotificacao.Warning);
                return(View(dto));
            }

            await _agendamentoService.CriarAsync(dto);

            if (_agendamentoService.Invalid)
            {
                TempData["Notificacao"] = new BadRequestDto(_agendamentoService.Notifications, TipoNotificacao.Warning);
                return(View(dto));
            }

            TempData["Notificacao"] = new BadRequestDto(new List <Notification>()
            {
                new Notification("CadastrarAgendamento", "Agendamento cadastrado com sucesso.")
            }, TipoNotificacao.Success);
            ViewBag.Controller = "Agendamentos";
            return(View("_Confirmacao"));
        }
        public ActionResult Liberar(AgendamentoDto model)
        {
            var value       = Request.Cookies[FormsAuthentication.FormsCookieName].Value;
            var agendamento = _serviceAgendamento.Finalizar(value, model);

            return(RedirectToAction("Index"));
        }
 public void Validate(AgendamentoDto dto)
 {
     if (dto.DescricaoDataAgendamento.IsNullOrEmpty())
     {
         throw new ApplicationException("Agendamento: O campo 'Data' é obrigatório..");
     }
 }
Example #4
0
        public IActionResult Put(int id, AgendamentoDto agendamentoDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != agendamentoDto.Id)
            {
                return(BadRequest("Identificadores do agendamento estão divergentes"));
            }

            if (!Exists(id))
            {
                return(NotFound());
            }

            _agendamentoRepository.BeginTransaction();

            // editando
            _agendamentoService.Put(agendamentoDto);

            if (_notification.Any)
            {
                _agendamentoRepository.RollbackTransaction();
                return(BadRequest());
            }

            _agendamentoRepository.CommitTransaction();

            return(NoContent());
        }
        public AgendamentoDto AgendarHorario(Agenda agenda)
        {
            bool validacao = true;

            var isValid = this.ValidarAgendamento(agenda);

            foreach (var valido in isValid)
            {
                if (!valido.Sucesso)
                {
                    validacao = false;
                }
            }

            if (!validacao)
            {
                _estoqueRepository.Save(agenda);
            }

            var agendamentoDto = new AgendamentoDto
            {
                Status             = agenda.Status,
                NomeFornecedor     = agenda.Fornecedor.Nome,
                Placa              = agenda.Placa,
                Vaga               = agenda.Vaga,
                ValidacaoDetalhada = isValid
            };

            return(agendamentoDto);
        }
 public Agendamento Add(AgendamentoDto dto)
 {
     return(new Agendamento
     {
         DataHora = ValidarDataHora.CreateInstance.JoinDataHora(dto.Data, dto.Hora),
         IdMedico = ValidarId.CreateInstance.SetId("Código Médico", dto.IdMedico),
         IdPaciente = ValidarId.CreateInstance.SetId("Código Paciente", dto.IdPaciente)
     });
 }
Example #7
0
        public void AlterarStatusLaboratorio(AgendamentoDto agendamentoDto, StatusAgendamento status)
        {
            var agendamento = contexo.Agendamentos.Where(x => x.Status == StatusAgendamento.Aberto);

            if (agendamentoDto.Id != 0)
            {
                agendamento = agendamento.Where(x => x.Id == agendamentoDto.Id);
            }

            if (agendamentoDto.IdDisciplina != 0)
            {
                agendamento = agendamento.Where(x => x.Disciplina.Id == agendamentoDto.IdDisciplina);
            }

            if (agendamentoDto.IdLaboratorio != 0)
            {
                agendamento = agendamento.Where(x => x.Laboratorio.Id == agendamentoDto.IdLaboratorio);
            }

            if (agendamentoDto.HorarioInicial != null && agendamentoDto?.HorarioInicial != DateTime.MinValue)
            {
                agendamento = agendamento.Where(x => x.HorarioInicial == agendamentoDto.HorarioInicial);
            }

            if (agendamentoDto.HorarioFinal != null && agendamentoDto?.HorarioFinal != DateTime.MinValue)
            {
                agendamento = agendamento.Where(x => x.HorarioFinal == agendamentoDto.HorarioFinal);
            }

            var result = agendamento.ToList();

            if (result.Count == 0)
            {
                throw new ObjectNotFoundException("Não foi encontrado nenhum agendamento.");
            }

            if (result.Count > 1)
            {
                throw new Exception("Inclua mais informações, para que seja liberado somente um horário.");
            }

            var horario = result.First();

            if (horario.HorarioFinal < DateTime.Now)
            {
                throw new Exception("Horárío já finalizado.");
            }

            if (horario.HorarioInicial < DateTime.Now)
            {
                throw new Exception("Horário em andamento.");
            }

            horario.Status = status;
            contexo.Agendamentos.AddOrUpdate(horario);
            contexo.SaveChanges();
        }
Example #8
0
 public void AtualizarAgendamento(AgendamentoDto agendamentoDto)
 {
     DataAgendamento      = DateTime.Parse(agendamentoDto.DataAgendamentoStr);
     DataFinalAgendamento = DateTime.Parse(agendamentoDto.DataFinalAgendamentoStr);
     Observacao           = agendamentoDto.Observacao;
     ServicoId            = agendamentoDto.ServicoId;
     UserId            = agendamentoDto.UserId;
     EstabelecimentoId = agendamentoDto.EstabelecimentoId;
 }
Example #9
0
        public void Put(AgendamentoDto agendamentoDto)
        {
            var agendamento = agendamentoDto.ToModel();

            if (!IsValid(agendamento))
            {
                return;
            }

            _agendamentoRepository.Put(agendamento);
        }
Example #10
0
        public ActionResult Cadastrar(AgendamentoDto model)
        {
            var value = Request.Cookies[FormsAuthentication.FormsCookieName].Value;

            model.HorarioInicial = DateTime.Parse(model.DiaInicial + " " + model.HoraInicial);
            model.HorarioFinal   = DateTime.Parse(model.DiaFinal + " " + model.HoraFinal);


            var agendamento = _serviceAgendamento.Cadastrar(value, model);

            return(RedirectToAction("Index"));
        }
Example #11
0
        public HttpResponseMessage AlterarAgendamento(AgendamentoDto agendamentoDto)
        {
            if (agendamentoDto == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var agendamento = AgendamentoRegras.CreateInstance.Edit(agendamentoDto);

            _uow.AgendamentoRepositorio.Atualizar(agendamento);
            _uow.Commit();
            return(Request.CreateResponse(HttpStatusCode.OK, agendamento));
        }
Example #12
0
        public HttpResponseMessage RegistroNovoAgendamento(AgendamentoDto agendamentoDto)
        {
            if (agendamentoDto == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var agendamento = AgendamentoRegras.CreateInstance.Add(agendamentoDto);

            _uow.AgendamentoRepositorio.Adicionar(agendamento);
            _uow.Commit();
            return(Request.CreateResponse(HttpStatusCode.OK, agendamento));
        }
Example #13
0
        public void TestaCreateComInformacoesObrigatoriasNulas()
        {
            var agendamentoDto = new AgendamentoDto();
            var retorno        = _agendamentoService.Create(agendamentoDto);

            Assert.IsTrue(retorno.Result.StatusCode == (int)EStatusCode.ERRO_VALIDACAO);
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe a data agendamento!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe a data final agendamento!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe o serviço!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Nenhum usuário vinculado!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Nenhum estabelecimento vinculado!"));

            Assert.IsTrue(retorno.Result.Errors.Count == 5);
        }
Example #14
0
        public void Cadastrar(AgendamentoDto agendamentoDto)
        {
            var laboratorio = contexo.Laboratorios.Where(x => x.Id == agendamentoDto.IdLaboratorio).FirstOrDefault();

            if (laboratorio == null)
            {
                throw new ObjectNotFoundException("Laboratório não cadastrado.");
            }

            var disciplina = contexo.Disciplinas.Where(x => x.Id == agendamentoDto.IdDisciplina).FirstOrDefault();

            if (disciplina == null)
            {
                throw new ObjectNotFoundException("Disciplina não cadastrada.");
            }

            if (agendamentoDto.HorarioInicial == DateTime.MinValue)
            {
                throw  new Exception("Insira um horário inicial");
            }

            if (agendamentoDto.HorarioFinal == DateTime.MinValue)
            {
                throw new Exception("Insira um horário final");
            }
            var horarioAgendamento = contexo.Agendamentos
                                     .Where(x => x.Status == StatusAgendamento.Aberto && ((x.HorarioInicial <= agendamentoDto.HorarioInicial &&
                                                                                           x.HorarioFinal >= agendamentoDto.HorarioInicial) ||
                                                                                          (x.HorarioInicial <= agendamentoDto.HorarioFinal &&
                                                                                           x.HorarioFinal >= agendamentoDto.HorarioFinal)))
                                     .FirstOrDefault();

            if (horarioAgendamento != null)
            {
                throw new Exception("Horário já reservado.");
            }

            var agendamento = new Agendamento()
            {
                Disciplina     = disciplina,
                Laboratorio    = laboratorio,
                HorarioInicial = agendamentoDto.HorarioInicial,
                HorarioFinal   = agendamentoDto.HorarioFinal,
                Status         = StatusAgendamento.Aberto
            };

            contexo.Agendamentos.AddOrUpdate(agendamento);
            contexo.SaveChanges();
        }
Example #15
0
 public IHttpActionResult Cadastrar(AgendamentoDto agendamentoDto)
 {
     try
     {
         serviceAgendamento.Cadastrar(agendamentoDto);
         return(Ok());
     }
     catch (ObjectNotFoundException e)
     {
         return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, e.Message)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #16
0
 public IHttpActionResult FinalizarAgendamento(AgendamentoDto agendamentoDto)
 {
     try
     {
         serviceAgendamento.AlterarStatusLaboratorio(agendamentoDto, StatusAgendamento.Concluido);
         return(Ok());
     }
     catch (ObjectNotFoundException e)
     {
         return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, e.Message)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public bool SaveAgendamento(AgendamentoDto dto)
        {
            Contexto.Agendamento.Add(new Agendamento()
            {
                IdPasta         = dto.IdPasta,
                IdProcesso      = dto.IdProcesso,
                Titulo          = dto.Titulo,
                Descricao       = dto.Descricao,
                DataAgendamento = Convert.ToDateTime(dto.DescricaoDataAgendamento),
                Horario         = dto.Horario,
                IdUsuario       = SessionUser.IdUsuario,
                Concluido       = dto.Concluido
            });
            Contexto.SaveChanges();

            return(true);
        }
Example #18
0
        public async Task EditarAsync(AgendamentoDto dto)
        {
            if (dto.Id == null)
            {
                AddNotification("EditarAgendamento", MensagemValidacao.CampoInvalido);
                return;
            }

            var sala = await _salaService.ObterAsync(dto.SalaId);

            var usuario = await _usuarioService.Obter(dto.UsuarioId);

            ValidarSalaUsuario(sala, usuario);
            if (Invalid)
            {
                return;
            }

            var agendamentoEditar = await _agendamentoRepository.ObterAsync(dto.Id.Value);

            if (agendamentoEditar == null)
            {
                AddNotification("EditarAgendamento", MensagemValidacao.Agendamento.NaoExiste);
                return;
            }

            await ValidarAgendamentoDoUsuario(dto.Periodo, dto.DataAgendada, usuario.Id, "EditarAgendamento");

            if (Invalid)
            {
                return;
            }

            var agendamentoDuplicado = await _agendamentoRepository.ObterAsync(dto.SalaId, dto.Periodo, dto.DataAgendada);

            if (agendamentoDuplicado != null && agendamentoEditar.UsuarioId != agendamentoDuplicado.UsuarioId && (agendamentoDuplicado.Status == EnumStatusAgendamento.Aprovado || agendamentoDuplicado.Status == EnumStatusAgendamento.Pendente))
            {
                AddNotification("EditarAgendamento", MensagemValidacao.Agendamento.JaExiste);
                return;
            }

            agendamentoEditar.Editar(dto.DataAgendada, dto.Periodo, dto.SalaId);
            agendamentoEditar.AtualizarAgendamento(Guid.Empty, dto.Status, null);

            await _agendamentoRepository.EditarAsync(agendamentoEditar);
        }
Example #19
0
        public bool Cancelar(string token, AgendamentoDto model)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:54438/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("Authorization", token);

                var response = client.PutAsJsonAsync("agendamento/liberar", model).Result;

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }

                return(false);
            }
        }
        public bool EditAgendamento(AgendamentoDto dto)
        {
            var agendamento = (from a in Contexto.Agendamento
                               where a.Id == dto.Id
                               select a).FirstOrDefault();

            agendamento.IdPasta         = dto.IdPasta;
            agendamento.IdProcesso      = dto.IdProcesso;
            agendamento.Titulo          = dto.Titulo;
            agendamento.Descricao       = dto.Descricao;
            agendamento.DataAgendamento = Convert.ToDateTime(dto.DescricaoDataAgendamento);
            agendamento.Horario         = dto.Horario;
            agendamento.IdUsuario       = SessionUser.IdUsuario;
            agendamento.Concluido       = dto.Concluido;

            Contexto.SaveChanges();

            return(true);
        }
Example #21
0
        public List <AgendamentoDto> BuscarAgendamentos(AgendamentoDto agendamento)
        {
            try
            {
                if (agendamento.NumeroSalaLaboratorio > 0)
                {
                    if (String.IsNullOrEmpty(agendamento.BlocoLaboratorio))
                    {
                        throw new ArgumentNullException("É necessário o bloco da sala para realizar a consulta corretamente.");
                    }
                }
                var consulta = contexo.Agendamentos.Where(x => x.Status == StatusAgendamento.Aberto);

                if (agendamento.IdDisciplina > 0)
                {
                    consulta = consulta.Where(x => x.Disciplina.Id == agendamento.IdDisciplina);
                }

                if (agendamento.IdLaboratorio > 0)
                {
                    consulta = consulta.Where(x => x.Laboratorio.Id == agendamento.IdLaboratorio);
                }

                if (!String.IsNullOrEmpty(agendamento.BlocoLaboratorio))
                {
                    consulta = consulta.Where(x => x.Laboratorio.Bloco == agendamento.BlocoLaboratorio);
                }

                if (agendamento.NumeroSalaLaboratorio > 0)
                {
                    consulta = consulta.Where(x => x.Laboratorio.NumeroSala == agendamento.NumeroSalaLaboratorio);
                }

                return(Mapper.Map <List <Agendamento>, List <AgendamentoDto> >(consulta.ToList()));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #22
0
        public async Task CriarAsync(AgendamentoDto dto)
        {
            var sala = await _salaService.ObterAsync(dto.SalaId);

            var usuario = await _usuarioService.Obter(dto.UsuarioId);

            ValidarSalaUsuario(sala, usuario);
            if (Invalid)
            {
                return;
            }

            await ValidarAgendamentoDoUsuario(dto.Periodo, dto.DataAgendada, usuario.Id, "CadastrarAgendamento");

            if (Invalid)
            {
                return;
            }

            var agendamentoExiste = await _agendamentoRepository.ObterAsync(dto.SalaId, dto.Periodo, dto.DataAgendada);

            if (agendamentoExiste != null && (agendamentoExiste.Status == EnumStatusAgendamento.Aprovado || agendamentoExiste.Status == EnumStatusAgendamento.Pendente))
            {
                AddNotification("CadastrarAgendamento", MensagemValidacao.Agendamento.JaExiste);
                return;
            }

            var agendamento = new Agendamento(dto.DataAgendada, dto.Periodo, dto.SalaId, dto.UsuarioId);

            try
            {
                await _agendamentoRepository.CriarAsync(agendamento);
            }
            catch (Exception ex)
            {
                AddNotification("CadastrarAgendamento", MensagemValidacao.ContacteSuporte);
                return;
            }
        }
Example #23
0
        public IActionResult Post(AgendamentoDto agendamentoDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _agendamentoRepository.BeginTransaction();

            // cadastrando
            _agendamentoService.Post(agendamentoDto);

            if (_notification.Any)
            {
                _agendamentoRepository.RollbackTransaction();
                return(BadRequest());
            }

            _agendamentoRepository.CommitTransaction();

            return(Created(agendamentoDto));
        }
Example #24
0
        public async Task <ResultDto <bool> > Update(AgendamentoDto agendamentoDto)
        {
            var agendamentoDtoValidate = new AgendamentoDtoValidate(agendamentoDto);

            if (!agendamentoDtoValidate.Validate())
            {
                return(await Task.FromResult(ResultDto <bool> .Validation(agendamentoDtoValidate.Mensagens)));
            }

            var agendamento = await _agendamentoRepository.ObterPorId(agendamentoDto.AgendamentoId);

            agendamento.AtualizarAgendamento(agendamentoDto);

            if (await _agendamentoRepository.ValidaAgendamentoDuplicados(agendamento.EstabelecimentoId, agendamento.AgendamentoId, agendamento.DataAgendamento, agendamento.DataFinalAgendamento))
            {
                return(await Task.FromResult(ResultDto <bool> .Validation("Horário já possui agendamento!")));
            }

            await _agendamentoRepository.Update(agendamento);

            return(await Task.FromResult(ResultDto <bool> .Success(true)));
        }
Example #25
0
        public async Task <ResultDto <AgendamentoDto> > Create(AgendamentoDto agendamentoDto)
        {
            var agendamentoDtoValidate = new AgendamentoDtoValidate(agendamentoDto);

            if (!agendamentoDtoValidate.Validate())
            {
                return(await Task.FromResult(ResultDto <AgendamentoDto> .Validation(agendamentoDtoValidate.Mensagens)));
            }

            var agendamento = _mapper.Map <Agendamento>(agendamentoDto);

            agendamento.SituacaoId   = (int)ESituacao.ATIVO;
            agendamento.DataCadastro = DateTime.Now;

            if (await _agendamentoRepository.ValidaAgendamentoDuplicados(agendamento.EstabelecimentoId, agendamento.AgendamentoId, agendamento.DataAgendamento, agendamento.DataFinalAgendamento))
            {
                return(await Task.FromResult(ResultDto <AgendamentoDto> .Validation("Horário já possui agendamento!")));
            }

            await _agendamentoRepository.Create(agendamento);

            return(await Task.FromResult(ResultDto <AgendamentoDto> .Success(_mapper.Map <AgendamentoDto>(agendamento))));
        }
Example #26
0
 public AgendamentoController()
 {
     Agendamento = new AgendamentoDto();
 }
Example #27
0
 public AgendamentoDtoValidate(AgendamentoDto agendamentoDto)
 {
     _agendamentoDto = agendamentoDto;
     Mensagens       = new List <string>();
 }
 public async Task <ResultDto <bool> > Put(int id, [FromBody] AgendamentoDto agendamentoDto)
 {
     return(await _agendamentoService.Update(agendamentoDto));
 }
 public async Task <ResultDto <AgendamentoDto> > Post([FromBody] AgendamentoDto agendamentoDto)
 {
     return(await _agendamentoService.Create(agendamentoDto));
 }