示例#1
0
        public async Task <IActionResult> Create(TurmaViewModel turma)
        {
            var   user   = _userManager.GetUserAsync(User);
            Turma create = new Turma
            {
                Professor        = (Professor)await user,
                DataCriacao      = DateTime.Now,
                MaxPonto         = 1000,
                AreaConhecimento = turma.AreaConhecimento,
                Descricao        = turma.Descricao,
                ChaveAcesso      = turma.ChaveAcesso,
                Nome             = turma.Nome
            };

            if (ModelState.IsValid)
            {
                _context.Add(create);
                await _context.SaveChangesAsync();

                LogUsuariosController log = new LogUsuariosController(_context);
                await log.SetLog("Create Turma : " + turma.Nome, create.Professor.Id);

                TempData["alert"] = $"{turma.Nome} foi criada";
                return(RedirectToAction(nameof(IndexProfessor)));
            }
            return(View(turma));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Descricao,AreaConhecimento,ChaveAcesso,ProfessorId")] Turma turma)
        {
            if (id != turma.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(turma);
                    await _context.SaveChangesAsync();

                    var user = (ApplicationUser)await _userManager.GetUserAsync(User);

                    LogUsuariosController log = new LogUsuariosController(_context);
                    await log.SetLog("Edit Turma => Id:" + turma.Id + ", Nome:" + turma.Nome, user.Id);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TurmaExists(turma.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProfessorId"] = new SelectList(_context.Professores, "Id", "Nome", turma.ProfessorId);
            return(View(turma));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("Ra,Nome,Sobrenome,Ativo,DataNascimento,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] Aluno aluno)
        {
            if (id != aluno.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aluno);
                    await _context.SaveChangesAsync();

                    var user = _userManager.GetUserAsync(User);
                    LogUsuariosController log = new LogUsuariosController(_context);
                    await log.SetLog("Editar Aluno : " + aluno.FullName, user.Id);

                    TempData["alert"] = $"{aluno.FullName} editado";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AlunoExists(aluno.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
示例#4
0
        public async Task <IActionResult> EntrarTurma(int id, [Bind("Id,ChaveAcesso")] Turma chave)
        {
            var turma = await _context.Turmas.Include("Alunos.Aluno").SingleOrDefaultAsync(m => m.Id == id);

            var   user       = _userManager.GetUserAsync(User);
            Aluno aluno      = (Aluno)await user;
            var   alunoturma = _context.AlunoTurmas.Where(x => x.AlunoId == aluno.Id && x.TurmaId == turma.Id && x.Ativo == true).SingleOrDefault();

            //var senha = chave.ChaveAcesso.Equals(null)  ? "" : chave.ChaveAcesso;
            // if (!turma.IAluno.Contains(aluno))
            if (alunoturma == null)
            {
                if (chave.ChaveAcesso == null)
                {
                    AlunoTurma at = new AlunoTurma
                    {
                        AlunoId       = aluno.Id,
                        TurmaId       = turma.Id,
                        Ativo         = true,
                        DataIngressao = DateTime.Now
                    };
                    _context.AlunoTurmas.Update(at);
                }
                else
                {
                    if (chave.ChaveAcesso.Equals(turma.ChaveAcesso))
                    {
                        AlunoTurma at = new AlunoTurma
                        {
                            AlunoId       = aluno.Id,
                            TurmaId       = turma.Id,
                            Ativo         = true,
                            DataIngressao = DateTime.Now
                        };
                        _context.AlunoTurmas.Update(at);
                    }
                    else
                    {
                        return(NotFound());
                    }
                }

                await _context.SaveChangesAsync();

                LogUsuariosController log = new LogUsuariosController(_context);
                await log.SetLog($"{aluno.FullName} entrou na turma {turma.Nome}", aluno.Id);

                TempData["alert"] = $"Você entrou na turma";
            }
            else
            {
                TempData["alert"] = $"Você ja está na turma";
                return(RedirectToAction(nameof(Index)));
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#5
0
        public async Task <IActionResult> Create(ModuloViewModel modulo)
        {
            var user = (ApplicationUser)await _userManager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                Modulo mod = new Modulo
                {
                    Nome       = modulo.Nome,
                    Descricao  = modulo.Descricao,
                    TurmaId    = modulo.TurmaId,
                    Url        = modulo.Url,
                    Resposta   = modulo.Resposta,
                    Texto      = modulo.Texto,
                    Tipo       = (TipoMod)modulo.Tipo,
                    MaxPonto   = modulo.MaxPonto,
                    Respondido = false,
                    DataMax    = modulo.DataMax
                };


                var turma = await _context.Turmas.FirstOrDefaultAsync(x => x.Id == modulo.TurmaId);

                var pontos = _context.Turmas.Include(x => x.Modulos).Where(t => t.Id == modulo.TurmaId).Sum(x => x.Modulos.Sum(t => t.MaxPonto));
                if (pontos + modulo.MaxPonto > turma.MaxPonto)
                {
                    TempData["alert"] = $"Pontuação máxima ultrapassada";
                    return(RedirectToAction(nameof(Index)));
                }

                if (modulo.Arquivo != null)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        await modulo.Arquivo.CopyToAsync(memoryStream);

                        mod.Arquivo = memoryStream.ToArray();
                    }
                }

                turma.PontoAtual += modulo.MaxPonto;
                _context.Update(turma);
                _context.Add(mod);
                await _context.SaveChangesAsync();

                LogUsuariosController log = new LogUsuariosController(_context);
                await log.SetLog("Create Modulo :" + mod.Nome, user.Id);

                TempData["alert"] = $"{mod.Nome} foi criado";

                return(RedirectToPage("/Turmas/Home/", mod.TurmaId));
            }
            ViewData["TurmaId"] = new SelectList(_context.Turmas.Where(x => x.ProfessorId == user.Id), "Id", "Id", modulo.TurmaId);
            return(View(modulo));
        }
示例#6
0
        public async Task <IActionResult> RespAluno(int id, ModuloPontuacaoViewModel mp)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (id != mp.modulo.Id)
                    {
                        return(NotFound());
                    }

                    var user = (Aluno)await _userManager.GetUserAsync(User);

                    var mod = await _context.Modulos.SingleOrDefaultAsync(m => m.Id == id);

                    //mod.Resposta = modulo.Resposta;
                    mod.Respondido = true;
                    //Os pontos, o professor adiciona
                    Pontuacao p = new Pontuacao
                    {
                        AlunoId    = user.Id,
                        Data       = DateTime.Now,
                        ModuloId   = mod.Id,
                        Respondido = true,
                        Resposta   = mp.pontuacao.Resposta,
                        TurmaId    = mod.TurmaId
                    };

                    PontuacaoController   pc  = new PontuacaoController(_context);
                    LogUsuariosController log = new LogUsuariosController(_context);

                    _context.Update(mod);
                    pc.AddResposta(p);
                    await log.SetLog("Resposta inserida : " + mod.Nome, user.Id);

                    await _context.SaveChangesAsync();

                    TempData["alert"] = $"{mp.modulo.Nome} foi respondido";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModuloExists(mp.modulo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
示例#7
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var turma = await _context.Turmas.SingleOrDefaultAsync(m => m.Id == id);

            _context.Turmas.Remove(turma);
            await _context.SaveChangesAsync();

            var user = (ApplicationUser)await _userManager.GetUserAsync(User);

            LogUsuariosController log = new LogUsuariosController(_context);
            await log.SetLog("Delete Turma => Id:" + turma.Id + ", Nome:" + turma.Nome, user.Id);

            return(RedirectToAction(nameof(Index)));
        }
示例#8
0
        public async Task AddPoint(int id, int pontos)
        {
            var p = await _context.Pontuacoes.SingleOrDefaultAsync(m => m.Id == id);

            // (m => m.ModuloId==pontuacao.ModuloId && m.AlunoId==pontuacao.AlunoId);

            //Pontuacao p = pontuacao;
            p.Pontos = pontos;

            _context.Pontuacoes.Update(p);
            _context.SaveChanges();

            LogUsuariosController log = new LogUsuariosController(_context);
            await log.SetLog(p.Pontos + " pontos ganho : Módulo- " + p.ModuloId + " Turma-" + p.TurmaId, p.AlunoId);
        }
示例#9
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var modulo = await _context.Modulos.SingleOrDefaultAsync(m => m.Id == id);

            _context.Modulos.Remove(modulo);
            await _context.SaveChangesAsync();

            var user = await _userManager.GetUserAsync(User);

            LogUsuariosController log = new LogUsuariosController(_context);
            await log.SetLog("Delete Modulo : " + modulo.Nome + " " + modulo.Id, user.Id);

            TempData["alert"] = $"{modulo.Nome} foi deletado";

            return(RedirectToAction(nameof(Index)));
        }
示例#10
0
        public async Task <IActionResult> RespProfessor(int id, [Bind("Id,Pontos,idpontuacao")] Modulo modulo)
        {
            var user = (Professor)await _userManager.GetUserAsync(User);

            PontuacaoController   pc  = new PontuacaoController(_context);
            LogUsuariosController log = new LogUsuariosController(_context);

            await pc.AddPoint(modulo.idpontuacao, modulo.Pontos);

            await log.SetLog("Nota inserida : " + modulo.Nome, user.Id);

            TempData["alert"] = $"{modulo.Nome} foi atribuido nota";

            var mod = await _context.Modulos.Include(m => m.Pontuacao).SingleOrDefaultAsync(m => m.Id == id);

            return(View("Respostas/RespProfessor", mod));
        }
示例#11
0
        public async Task <IActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var email = user.Email;

            if (model.Email != email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, model.Email);

                if (!setEmailResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting email for user with ID '{user.Id}'.");
                }
            }

            var phoneNumber = user.PhoneNumber;

            if (model.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    throw new ApplicationException($"Unexpected error occurred setting phone number for user with ID '{user.Id}'.");
                }
            }
            LogUsuariosController log = new LogUsuariosController(_context);
            await log.SetLog("Update usuário : " + user.FullName, user.Id);

            StatusMessage = "Perfil atualizado com sucesso";
            return(RedirectToAction(nameof(Index)));
        }
示例#12
0
        public async Task <IActionResult> Sair(int id)
        {
            var   user  = _userManager.GetUserAsync(User);
            Aluno aluno = (Aluno)await user;

            var alunoturma =
                _context.AlunoTurmas
                .SingleOrDefault(y => y.AlunoId == aluno.Id && y.TurmaId == id && y.Ativo == true);

            alunoturma.Ativo = false;
            _context.AlunoTurmas.Update(alunoturma);
            await _context.SaveChangesAsync();

            LogUsuariosController log = new LogUsuariosController(_context);
            await log.SetLog($"{aluno.FullName} saiu da turma {alunoturma.TurmaId}", aluno.Id);

            TempData["alert"] = $"Você saiu da turma";

            return(RedirectToAction(nameof(Index)));
        }
示例#13
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Descricao,Url,TurmaId")] Modulo modulo)
        {
            var user = (Professor)await _userManager.GetUserAsync(User);

            if (id != modulo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(modulo);
                    await _context.SaveChangesAsync();

                    LogUsuariosController log = new LogUsuariosController(_context);
                    await log.SetLog("Update Modulo : " + modulo.Nome, user.Id);

                    TempData["alert"] = $"{modulo.Nome} foi alterado";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModuloExists(modulo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TurmaId"] = new SelectList(_context.Turmas, "Id", "Id", modulo.TurmaId);
            return(View(modulo));
        }
示例#14
0
        public async Task <IActionResult> AddAluno(int id, TurmaModificationModel model)
        {
            if (id != model.TurmaId)
            {
                return(NotFound());
            }

            var turma = await _context.Turmas.Include("Alunos.Aluno").SingleOrDefaultAsync(i => i.Id == id);

            var context = _context.AlunoTurmas;

            if (ModelState.IsValid)
            {
                try
                {
                    foreach (int userId in model.IdsToAdd ?? new int[] { })
                    {
                        Aluno user = await _context.Alunos.SingleOrDefaultAsync(y => y.Id == userId);

                        if (user != null)
                        {
                            AlunoTurma at = new AlunoTurma
                            {
                                AlunoId       = user.Id,
                                TurmaId       = turma.Id,
                                Ativo         = true,
                                DataIngressao = DateTime.Now
                            };
                            _context.AlunoTurmas.Update(at);
                        }
                    }
                    await _context.SaveChangesAsync();

                    foreach (int userId in model.IdsToDelete ?? new int[] { })
                    {
                        Aluno user = await _context.Alunos.SingleOrDefaultAsync(y => y.Id == userId);

                        if (user != null)
                        {
                            var alunoturma = _context.AlunoTurmas
                                             .SingleOrDefault(y => y.AlunoId == user.Id && y.TurmaId == id && y.Ativo == true);
                            alunoturma.Ativo = false;
                            _context.AlunoTurmas.Update(alunoturma);
                        }
                    }
                    await _context.SaveChangesAsync();

                    var usuario = (ApplicationUser)await _userManager.GetUserAsync(User);

                    LogUsuariosController log = new LogUsuariosController(_context);
                    await log.SetLog("Update Alunos da Turma => Id:" + turma.Id + ", Nome:" + turma.Nome, usuario.Id);

                    TempData["alert"] = $"Lista de alunos atualizada";
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(NotFound());
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(await AddAluno(model.TurmaId));
        }
示例#15
0
        public async Task <IActionResult> RespAlunoOnline(int id, [Bind("Id,Resposta")] Modulo modulo)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (id != modulo.Id)
                    {
                        return(NotFound());
                    }

                    var user  = _userManager.GetUserAsync(User);
                    var aluno = (Aluno)await user;
                    var mod   = await _context.Modulos.SingleOrDefaultAsync(m => m.Id == id);

                    int x;

                    //string myJson = "  { 'Acerto' : 's','Ponto': '3', 'y' = '1', 'x' = '2' }";
                    //classe de dados de envio
                    RequisicaoResposta RR = new RequisicaoResposta
                    {
                        aluno    = aluno.Id,
                        modulo   = mod.Id,
                        resposta = modulo.Resposta
                    };
                    RequisicaoResposta resulthttp;


                    using (var client = new HttpClient())
                    {
                        // var response = await client.PostAsync(
                        //   "http://localhost:64466/api/values",
                        //  new StringContent(myJson, Encoding.UTF8, "application/json"));
                        HttpRequestMessage request =
                            //  new HttpRequestMessage(HttpMethod.Post, "http://localhost:64466/api/values");
                            new HttpRequestMessage(HttpMethod.Post, mod.Url);

                        string json = JsonConvert.SerializeObject(RR);
                        request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

                        HttpClient          http     = new HttpClient();
                        HttpResponseMessage response = await http.SendAsync(request);

                        var responseString = await response.Content.ReadAsStringAsync();

                        var post = JsonConvert.DeserializeObject <RequisicaoResposta>(responseString.ToString());
                        resulthttp = post;
                        x          = post.ponto;
                    }

                    PontuacaoController   pc  = new PontuacaoController(_context);
                    LogUsuariosController log = new LogUsuariosController(_context);

                    //tratar porcentagem de acerto
                    if (resulthttp.Acerto.Equals(true))
                    {
                        mod.Resposta   = resulthttp.resposta;
                        mod.Pontos     = resulthttp.ponto;
                        mod.Respondido = true;
                    }
                    else
                    {
                        mod.Pontos     = 0;
                        mod.Respondido = true;
                    }

                    Pontuacao p = new Pontuacao
                    {
                        AlunoId    = aluno.Id,
                        Data       = DateTime.Now,
                        ModuloId   = mod.Id,
                        Respondido = true,
                        Resposta   = mod.Resposta,
                        TurmaId    = mod.TurmaId,
                        Pontos     = resulthttp.ponto
                    };


                    _context.Update(mod);
                    pc.AddResposta(p);
                    await log.SetLog("Resposta inserida : " + mod.Nome, user.Id);

                    await _context.SaveChangesAsync();

                    TempData["alert"] = $"{mod.Nome} foi respondido";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModuloExists(modulo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }