Esempio n. 1
0
        public async Task <IActionResult> Create(OrdemServicoViewModel ordemServicoViewModel)
        {
            bool hasErrors = !ModelState.IsValid;

            if (!hasErrors)
            {
                hasErrors = ResponseHasErrors(await _ordemServicoAppService.Add(ordemServicoViewModel));
            }

            if (hasErrors)
            {
                ViewData["ConvenioId"]    = new SelectList(_convenioAppService.GetAll().Result, "Id", "Nome", ordemServicoViewModel.Convenio?.Id);
                ViewData["MedicoId"]      = new SelectList(_medicoAppService.GetAll().Result, "Id", "Nome", ordemServicoViewModel.Medico?.Id);
                ViewData["PacienteId"]    = new SelectList(_pacienteAppService.GetAll().Result, "Id", "Nome", ordemServicoViewModel.Paciente?.Id);
                ViewData["PostoColetaId"] = new SelectList(_postoColetaAppService.GetAll().Result, "Id", "Descricao", ordemServicoViewModel.PostoColeta?.Id);

                return(View(ordemServicoViewModel));
            }
            ordemServicoViewModel = await _ordemServicoAppService.GetByNumber(ordemServicoViewModel.Numero);

            return(RedirectToAction("edit", "ordem", new { id = ordemServicoViewModel.Id }));
        }
 public async Task <IActionResult> Post([FromBody] OrdemServicoViewModel viewModel)
 {
     return(!ModelState.IsValid ?
            CustomResponse(ModelState) :
            CustomResponse(await _ordemServicoAppService.Add(viewModel)));
 }