public DisciplinaViewModel Update(DisciplinaViewModel obj)
 {
     BeginTransaction();
     _disciplinaService.Update(Mapper.Map <DisciplinaViewModel, Disciplina>(obj));
     Commit();
     return(obj);
 }
        // GET: Disciplinas/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await _context.Disciplinas.Include(a => a.Curso).Include(a => a.Professor)

                        .FirstOrDefaultAsync(m => m.Id == id);

            if (model == null)
            {
                return(NotFound());
            }
            var disciplinaViewModel = new DisciplinaViewModel
            {
                Id                      = model.Id,
                area_formação           = model.area_formação,
                carga_horaria_discplina = model.carga_horaria_discplina,
                creditos_discplina      = model.creditos_discplina,
                nome_disciplina         = model.nome_disciplina,
                Curso                   = model.Curso,
                id_curso                = model.id_curso,
                id_professor            = model.id_professor,
                Professor               = model.Professor,
            };

            return(View(disciplinaViewModel));
        }
示例#3
0
        public async Task<dynamic> PostDisciplina([FromBody] DisciplinaViewModel model)
        {
            ICollection<UsuarioDisciplina> usuarioDisciplina = new List<UsuarioDisciplina>();
            if (model.UsuarioDisciplina != null)
            {
                foreach (var item in model.UsuarioDisciplina)
                {
                    usuarioDisciplina.Add(_mapper.Map<UsuarioDisciplina>(item));
                }
            }

            _mapper.Map<ICollection<UsuarioDisciplina>>(model.UsuarioDisciplina);
            Disciplina disciplina = _mapper.Map<Disciplina>(model);
            disciplina.UsuarioDisciplina = usuarioDisciplina;
            _context.Disciplina.Add(disciplina);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (DisciplinaExists(disciplina.IdDisciplina))
                {
                    return Conflict(new { message = "Esta disciplina já existe" });
                }
                else
                {
                    throw;
                }
            }

            return CreatedAtAction("GetDisciplina", new { id = disciplina.IdDisciplina }, disciplina);
        }
示例#4
0
        public void TesteDetails()
        {
            //Arrange
            var dadosViewModel = new DisciplinaViewModel()
            {
                Ativo        = true,
                Nome         = "Teste",
                Area         = new Area(),
                AreaId       = new Guid(),
                Bibliografia = "teste",
                Descricao    = "teste",
                DisciplinaId = new Guid(),
                Nivel        = "Alta Compexidade"
            };

            //Arrange
            Guid id = new Guid();

            _disciplinaAppServiceMock.Setup(a => a.GetById(dadosViewModel.DisciplinaId)).Returns(dadosViewModel).Verifiable();

            //Act
            _disciplina.Details(id);

            //Assert
            _repository.VerifyAll();
        }
        public IEnumerable <DisciplinaViewModel> ResultadoPesquisaDisciplina(DisciplinaViewModel form)
        {
            var disciplina = Mapper.Map <DisciplinaViewModel, Disciplina>(form);

            return
                (Mapper.Map <IEnumerable <Disciplina>, IEnumerable <DisciplinaViewModel> >(
                     _disciplinaService.ResultadoPesquisaDisciplina(disciplina)));
        }
        public ActionResult Search(DisciplinaViewModel form)
        {
            ViewBag.AreaId = new SelectList(_areaAppService.GetAll(), "AreaId", "Descricao", "Selecione");
            var iNscrBqTopico = _disciplinaAppService.ResultadoPesquisaDisciplina(form);

            ViewBag.Nivel = new SelectList(new ListaNiveis().Niveis(), "Key", "Value", "Selecione");
            return(View(iNscrBqTopico));
        }
        public IActionResult Cadastrar()
        {
            var viewModel = new DisciplinaViewModel();

            PreencheCombosTela(viewModel);

            return(View("Form", viewModel));
        }
        // GET: Disciplinas/Create
        public IActionResult Create()
        {
            var disciplina = new DisciplinaViewModel();

            disciplina.cursos      = GetCurso();
            disciplina.professores = GetProfessor();
            return(View(disciplina));
        }
        public DisciplinaViewModel Add(DisciplinaViewModel obj)
        {
            var disciplina = Mapper.Map <DisciplinaViewModel, Disciplina>(obj);

            BeginTransaction();
            _disciplinaService.Add(disciplina);
            Commit();
            return(obj);
        }
示例#10
0
        public ActionResult Update(int id)
        {
            MDisciplina         mDisciplina     = new MDisciplina();
            DisciplinaViewModel viewModel       = new DisciplinaViewModel();
            MTipoDisciplina     mTipoDisciplina = new MTipoDisciplina();

            viewModel.disciplina          = mDisciplina.BringOne(c => c.idDisciplina == id);
            viewModel.listaTipoDisciplina = mTipoDisciplina.BringAll();
            return(View(viewModel));
        }
示例#11
0
        public ActionResult Create()
        {
            //MDisciplina mDisciplina = new MDisciplina();
            MTipoDisciplina     mTipoDisciplina = new MTipoDisciplina();
            DisciplinaViewModel viewModel       = new DisciplinaViewModel();

            viewModel.listaTipoDisciplina = mTipoDisciplina.BringAll();
            ViewBag.Message = TempData["Message"];
            return(View(viewModel));
        }
        public async Task <IActionResult> Edit(int id, DisciplinaViewModel disciplinaViewModel)
        {
            if (id != disciplinaViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var curso = await _context.Cursos.FirstOrDefaultAsync(t => t.Id == disciplinaViewModel.id_curso);

                    var professor = await _context.Professores.FirstOrDefaultAsync(t => t.Id == disciplinaViewModel.id_professor);

                    if (curso == null)
                    {
                        return(NotFound());
                    }
                    if (professor == null)
                    {
                        return(NotFound());
                    }

                    var disciplina = new Disciplina
                    {
                        Id                      = disciplinaViewModel.Id,
                        area_formação           = disciplinaViewModel.area_formação,
                        carga_horaria_discplina = disciplinaViewModel.carga_horaria_discplina,
                        creditos_discplina      = disciplinaViewModel.creditos_discplina,
                        nome_disciplina         = disciplinaViewModel.nome_disciplina,
                        Curso                   = curso,
                        Professor               = professor,
                        id_curso                = disciplinaViewModel.id_curso,
                        id_professor            = disciplinaViewModel.id_professor,
                    };
                    _context.Update(disciplina);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DisciplinaModelExists(disciplinaViewModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            disciplinaViewModel.cursos = GetCurso();
            return(View(disciplinaViewModel));
        }
        public IActionResult Editar(DisciplinaViewModel viewModel)
        {
            var resultado = appService.Atualizar(viewModel);

            if (resultado.Successo)
            {
                resultado.RedirecionarPara(Url.Action(nameof(Index)));
            }

            return(Json(resultado.Retorno()));
        }
 public ActionResult Atribuicao(DisciplinaViewModel disciplinaViewModel)
 {
     ViewBag.ProjetoId = new SelectList(_projetoAppService.GetAll(), "ProjetoId", "NomeProjeto",
                                        "Selecione");
     ViewBag.AreaId       = new SelectList(_areaAppService.GetAll(), "AreaId", "Descricao", "Selecione");
     ViewBag.MestreId     = new SelectList(_mestreAppService.GetAll(), "MestreId", "Nome", "Selecione");
     ViewBag.DisciplinaId = new SelectList(_disciplinaAppService.GetAll(), "DisciplinaId", "Descricao",
                                           "Selecione");
     ViewBag.Nivel = new SelectList(new ListaNiveis().Niveis(), "Key", "Value", "Selecione");
     return(View(_disciplinaAppService.ResultadoPesquisaDisciplinaAtribuicao(disciplinaViewModel)));
 }
        public ConfigurationProfile()
        {
            Shared.Conversores.Configuracao.Registrar(this);
            this.AllowNullCollections = true;

            AlunoViewModel.Mapping(this);
            DisciplinaViewModel.Mapping(this);
            TurmaViewModel.Mapping(this);
            TurmaAlunoViewModel.Mapping(this);
            TurmaDisciplinaViewModel.Mapping(this);
        }
示例#16
0
        public async Task Adicionar(DisciplinaViewModel disciplinaViewModel)
        {
            var disciplina = _mapper.Map <Disciplina>(disciplinaViewModel);

            if (!ExecutarValidacao(new DisciplinaValidation(), disciplina))
            {
                return;
            }

            _disciplinaRepository.Adicionar(disciplina);
            await _disciplinaRepository.UnitOfWork.Commit();
        }
        public async Task <IActionResult> EditarDisciplina(Guid id)
        {
            Disciplina disciplinaModel = await _contexto.Disciplinas.Where(c => c.Id == id).FirstOrDefaultAsync();

            DisciplinaViewModel disciplinaEditavel = new DisciplinaViewModel()
            {
                Id      = disciplinaModel.Id,
                Nome    = disciplinaModel.Nome,
                Periodo = disciplinaModel.Periodo,
            };

            return(View(disciplinaEditavel));
        }
        public async Task <ActionResult <DisciplinaViewModel> > EditarDisciplina([FromBody] DisciplinaViewModel disciplinaViewModel)
        {
            if (ModelState.IsValid)
            {
                var model = _disciplinaViewModel
                            .ConverterViewModelParaModel(disciplinaViewModel);

                return(Ok(_disciplinaViewModel
                          .ConverterModelParaViewModel(await _disciplinaRepository.Update(model))));
            }

            return(BadRequest());
        }
        public ActionResult Create(DisciplinaViewModel disciplinaViewModel)
        {
            if (ModelState.IsValid)
            {
                _disciplinaAppService.Add(disciplinaViewModel);
                return(RedirectToAction("Index"));
            }


            ViewBag.AreaId = new SelectList(_areaAppService.GetAll(), "AreaId", "Descricao", "Selecione");
            ViewBag.Nivel  = new SelectList(new ListaNiveis().Niveis(), "Key", "Value", "Selecione");
            return(RedirectToAction("Index"));
        }
示例#20
0
        public async Task<IActionResult> PutDisciplina(int id, DisciplinaViewModel model)
        {
            var existingParent = _context.Disciplina
                                .Where(p => p.IdDisciplina == id)
                                .Include(p => p.UsuarioDisciplina)
                                .SingleOrDefault();

            if (existingParent != null)
            {
                DisciplinaViewModel parentValues = new DisciplinaViewModel
                {
                    Descricao = model.Descricao,
                    Materia = model.Materia,
                    Turno = model.Turno,
                    IdDisciplina = model.IdDisciplina
                };
                // Update parent
                _context.Entry(existingParent).CurrentValues.SetValues(parentValues);
                
                foreach (var existingChild in existingParent.UsuarioDisciplina.ToList())
                {
                    if (!model.UsuarioDisciplina.Any(c => c.DisciplinaIdDisciplina == existingChild.DisciplinaIdDisciplina && c.UsuarioCpf == existingChild.UsuarioCpf))
                        _context.UsuarioDisciplina.Remove(existingChild);
                }
                foreach (var childModel in model.UsuarioDisciplina)
                {
                    if (!_context.UsuarioDisciplina.Any(usr => usr.DisciplinaIdDisciplina == childModel.DisciplinaIdDisciplina && usr.UsuarioCpf == childModel.UsuarioCpf) && childModel.DisciplinaIdDisciplina != 0)
                    {
                        UsuarioDisciplina usrDisc = _mapper.Map<UsuarioDisciplina>(childModel);
                        existingParent.UsuarioDisciplina.Add(usrDisc);
                    }
                }
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DisciplinaExists(id))
                {
                    return NotFound(new { msg = "Não foi possível encontrar a disciplina" });
                }
                else
                {
                    throw;
                }
            }
            return StatusCode(200, new { msg = $"Disciplina {existingParent.Materia} alterada com sucesso" });
        }
        public async Task <IActionResult> EditarDisciplina(DisciplinaViewModel model)
        {
            Disciplina disciplinaEditada = await _contexto.Disciplinas.Where(d => d.Id == model.Id).FirstOrDefaultAsync();

            disciplinaEditada.Nome    = model.Nome;
            disciplinaEditada.Periodo = model.Periodo;

            _contexto.Disciplinas.UpdateRange(disciplinaEditada);
            await _contexto.SaveChangesAsync();

            await _contexto.DisposeAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public ActionResult Edit(DisciplinaViewModel disciplinaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(disciplinaViewModel));
            }

            _disciplinaAppService.Update(disciplinaViewModel);
            ViewBag.Nivel  = new SelectList(new ListaNiveis().Niveis(), "Key", "Value", "Selecione");
            ViewBag.AreaId = new SelectList(_areaAppService.GetAll(), "AreaId", "Descricao", "Selecione");
            var disciplina = _disciplinaAppService.GetAll();

            return(View("Index", disciplina));
        }
        public async Task <ActionResult <bool> > SalvarDisciplina([FromBody] DisciplinaViewModel disciplinaViewModel)
        {
            if (ModelState.IsValid)
            {
                var model = _disciplinaViewModel
                            .ConverterViewModelParaModel(disciplinaViewModel);

                if (await _disciplinaRepository.Create(model))
                {
                    return(Ok());
                }
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Create([Bind("Id,NomeDisciplina")] DisciplinaViewModel disciplinaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(disciplinaViewModel));
            }

            var aluno = _mapper.Map <Disciplina>(disciplinaViewModel);
            await _disciplinaService.Adicionar(aluno);

            if (!OperacaoValida())
            {
                return(View(disciplinaViewModel));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> NovaDisciplina(DisciplinaViewModel model)
        {
            if (model != null)
            {
                Disciplina novaDisciplina = new Disciplina()
                {
                    Id      = Guid.NewGuid(),
                    Nome    = model.Nome,
                    Periodo = model.Periodo,
                };

                await _contexto.Disciplinas.AddRangeAsync(novaDisciplina);

                await _contexto.SaveChangesAsync();

                await _contexto.DisposeAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#26
0
        public async Task <IActionResult> Cadastrar(DisciplinaViewModel disciplinaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Cadastro", disciplinaViewModel));
            }

            await _disciplinaService.Adicionar(disciplinaViewModel);

            if (!OperacaoValida)
            {
                return(PartialView("_Cadastro", disciplinaViewModel));
            }

            TempData["Sucesso"] = "Disciplina cadastrada com sucesso!";

            var url = Url.Action("ObterDisciplinas", "Disciplinas");

            return(Json(new { success = true, url }));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,NomeDisciplina")] DisciplinaViewModel disciplinaViewModel)
        {
            if (id != disciplinaViewModel.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(disciplinaViewModel));
            }

            var disciplina = _mapper.Map <Disciplina>(disciplinaViewModel);
            await _disciplinaService.Atualizar(disciplina);

            if (!OperacaoValida())
            {
                return(View(disciplinaViewModel));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(DisciplinaViewModel disciplinaViewModel)
        {
            if (ModelState.IsValid)
            {
                var curso = await _context.Cursos.FirstOrDefaultAsync(t => t.Id == disciplinaViewModel.id_curso);

                var professor = await _context.Professores.FirstOrDefaultAsync(t => t.Id == disciplinaViewModel.id_professor);

                if (curso == null)
                {
                    return(NotFound());
                }
                if (professor == null)
                {
                    return(NotFound());
                }

                var disciplina = new Disciplina
                {
                    Id                      = disciplinaViewModel.Id,
                    area_formação           = disciplinaViewModel.area_formação,
                    carga_horaria_discplina = disciplinaViewModel.carga_horaria_discplina,
                    creditos_discplina      = disciplinaViewModel.creditos_discplina,
                    nome_disciplina         = disciplinaViewModel.nome_disciplina,
                    Curso                   = curso,
                    Professor               = professor,
                    id_curso                = disciplinaViewModel.id_curso,
                    id_professor            = disciplinaViewModel.id_professor,
                };

                _context.Add(disciplina);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(disciplinaViewModel));
        }
示例#29
0
        public void TesteCreateNovaDisciplinaFalho()
        {
            //Arrange
            var dadosViewModel = new DisciplinaViewModel()
            {
                Ativo        = true,
                Nome         = "",
                Area         = new Area(),
                AreaId       = new Guid(),
                Bibliografia = "",
                Descricao    = "",
                DisciplinaId = new Guid(),
                Nivel        = ""
            };

            _disciplinaAppServiceMock.Setup(a => a.Add(dadosViewModel)).Returns(dadosViewModel).Verifiable();

            //Act
            _disciplina.Create(dadosViewModel);

            //Assert
            _repository.VerifyAll();
        }
示例#30
0
        public void TestIndex()
        {
            //Arrange
            var dadosViewModel = new DisciplinaViewModel()
            {
                Ativo        = true,
                Nome         = "Teste",
                Area         = new Area(),
                AreaId       = new Guid(),
                Bibliografia = "teste",
                Descricao    = "teste",
                DisciplinaId = new Guid(),
                Nivel        = "Alta Compexidade"
            };

            _disciplinaAppServiceMock.Setup(a => a.GetAll()).Returns(It.IsAny <ICollection <DisciplinaViewModel> >()).Verifiable();
            _areaAppServiceMock.Setup(a => a.GetAll()).Returns(It.IsAny <IEnumerable <AreaViewModel> >()).Verifiable();

            //Act
            _disciplina.Index();

            //Assert
            _repository.VerifyAll();
        }