public async Task <IActionResult> Edit(int id, Disciplina disciplina)
        {
            if (!ModelState.IsValid)
            {
                var cursos = await _cursoService.FindAllAsync();

                var viewModel = new DisciplinaFormViewModel {
                    Disciplina = disciplina
                };
                return(View(viewModel));
            }

            if (id != disciplina.Id)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id mismatch" }));
            }

            try
            {
                await _disciplinaService.UpdateAsync(disciplina);

                return(RedirectToAction(nameof(Index)));
            }
            catch (NotFoundException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
            catch (DbConcurrencyException e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }
        public async Task <IActionResult> Create()
        {
            var cursos = await _cursoService.FindAllAsync();

            var viewModel = new DisciplinaFormViewModel {
                Cursos = cursos
            };

            return(View(viewModel));
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] DisciplinaFormViewModel model)
        {
            var result = await _disciplinaService
                         .Cadastrar(_mapper.Map <Disciplina>(model));

            if (result.IsValid)
            {
                return(Ok(_mapper.Map <DisciplinaViewModel>(result.Entity)));
            }

            return(BadRequest(result.Result));
        }
コード例 #4
0
        public async Task <IActionResult> Put(Guid id, [FromBody] DisciplinaFormViewModel model)
        {
            if (!await _disciplinaService.Existe(id))
            {
                return(RegistroNaoEncontrado(id));
            }

            var result = await _disciplinaService.Editar(id, _mapper.Map <Disciplina>(model));

            if (result.IsValid)
            {
                return(Ok(_mapper.Map <DisciplinaViewModel>(result.Entity)));
            }

            return(BadRequest(result.Result));
        }
        public async Task <IActionResult> Create(Disciplina disciplina)
        {
            if (!ModelState.IsValid)
            {
                var cursos = await _cursoService.FindAllAsync();

                var viewModel = new DisciplinaFormViewModel {
                    Disciplina = disciplina, Cursos = cursos
                };
                return(View(viewModel));
            }

            await _disciplinaService.InsertAsync(disciplina);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error), new { message = "Id not provided" }));
            }
            var obj = await _disciplinaService.FindByIdAsync(id.Value);

            if (obj == null)
            {
                return(RedirectToAction(nameof(Error), new { messsage = "Id not found" }));
            }

            List <Curso> cursos = await _cursoService.FindAllAsync();

            DisciplinaFormViewModel viewModel = new DisciplinaFormViewModel {
                Disciplina = obj, Cursos = cursos
            };

            return(View(viewModel));
        }