예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Codigo,Data,Validade,Desconto,Utilizado")] Cupom cupom)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cupom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cupom));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Titulo,CabecalhoTexto1_Index,Texto1_Index,Logo,NotaDeCorte,Video_Index,CabecalhoTexto2_Index,Texto2_Index,CabecalhoTexto3_Index,Texto3_Index,TextoAlvo_Index,TextoGrafico_Index,TextoComputador_Index,EnderecoLinha1,EnderecoLinha2,EnderecoLinha3")] Configuracao configuracao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(configuracao);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(configuracao));
        }
        public async Task <IActionResult> Create([Bind("Id,AvaliacaoId,Descricao")] PerguntaAvaliacao perguntaAvaliacao)
        {
            if (ModelState.IsValid)
            {
                _dbContext.Add(perguntaAvaliacao);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction("Index", "Avaliacoes", new { perguntaId = perguntaAvaliacao.Id }));
            }
            return(View(perguntaAvaliacao));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,Descricao,Valor")] Desconto desconto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(desconto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(desconto));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Descricao,Preco")] Curso curso)
        {
            if (ModelState.IsValid)
            {
                _context.Add(curso);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(curso));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,UserId,NotaQuestionario,Nome,Email,WhatsApp")] Aluno aluno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(aluno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(aluno));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("Id,CursoId,AlunoId,Liberado,Data")] Matricula matricula)
        {
            if (ModelState.IsValid)
            {
                _context.Add(matricula);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AlunoId"] = new SelectList(_context.Alunos, "Id", "Id", matricula.AlunoId);
            ViewData["CursoId"] = new SelectList(_context.Cursos, "Id", "Id", matricula.CursoId);
            return(View(matricula));
        }
        public async Task <IActionResult> Create([Bind("Id,Descricao")] PerguntaQuestionario perguntaQuestionario)
        {
            if (ModelState.IsValid)
            {
                // Só há um questionário
                perguntaQuestionario.QuestionarioId = 1;

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(perguntaQuestionario));
        }
        public async Task <IActionResult> Create([Bind("Id,PerguntaAvaliacaoId,Descricao,Correta,Escolhida")] RespostaAvaliacao respostaAvaliacao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(respostaAvaliacao);

                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                PerguntaAvaliacao perguntaAvaliacao = await _context.PerguntasAvaliacao.FirstOrDefaultAsync(a => a.Id == respostaAvaliacao.PerguntaAvaliacaoId);

                return(RedirectToAction("Index", "Avaliacoes", new { id = perguntaAvaliacao.AvaliacaoId, perguntaId = respostaAvaliacao.PerguntaAvaliacaoId }));
            }
            ViewData["PerguntaAvaliacaoId"] = new SelectList(_context.PerguntasAvaliacao, "Id", "Id", respostaAvaliacao.PerguntaAvaliacaoId);
            return(View(respostaAvaliacao));
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Id,ModuloId,Descricao")] Avaliacao avaliacao)
        {
            if (ModelState.IsValid)
            {
                _context.Add(avaliacao);
                await _context.SaveChangesAsync();

                var modulo = await _context.Modulos.FindAsync(avaliacao.ModuloId);

                modulo.AvaliacaoId = avaliacao.Id;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(avaliacao));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("Id,CursoId,Descricao")] Modulo modulo)
        {
            if (ModelState.IsValid)
            {
                var seq = await _context.Modulos.Where(m => m.CursoId == modulo.CursoId).OrderByDescending(m => m.NumeroModulo).FirstOrDefaultAsync();

                if (seq == null)
                {
                    modulo.NumeroModulo = 1;
                }
                else
                {
                    modulo.NumeroModulo = seq.NumeroModulo + 1;
                }

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

                return(RedirectToAction("Index", "Cursos", new { id = modulo.CursoId, moduloId = modulo.Id }));
            }
            ViewData["CursoId"] = new SelectList(_context.Cursos, "Id", "Id", modulo.CursoId);
            return(View(modulo));
        }
예제 #12
0
        public async Task <IActionResult> Create([Bind("Id,ModuloId,NumeroAula,Descricao,Video,MaterialApoio,ArquivosApoio")] Aula aula)
        {
            if (ModelState.IsValid)
            {
                var seq = await _context.Aulas.Where(a => a.ModuloId == aula.ModuloId).OrderByDescending(a => a.NumeroAula).FirstOrDefaultAsync();


                if (aula.Video != null && aula.Video.Contains("https://youtu.be/"))
                {
                    string newPath = aula.Video.Replace("https://youtu.be/", "https://www.youtube.com/watch?v=");

                    aula.Video = newPath;
                }

                if (seq == null)
                {
                    aula.NumeroAula = 1;
                }
                else
                {
                    aula.NumeroAula = seq.NumeroAula + 1;
                }

                aula.Modulo = null;

                _context.Add(aula);

                await _context.SaveChangesAsync();

                Modulo modulo = _context.Modulos.Find(aula.ModuloId);
                return(RedirectToAction("Index", "Cursos", new { id = modulo.CursoId, moduloId = aula.ModuloId }));
            }
            ViewData["CursoId"]  = new SelectList(_context.Cursos, "Id", "Nome");
            ViewData["ModuloId"] = new SelectList(_context.Modulos, "Id", "Descricao", aula.ModuloId);
            return(View(aula));
        }
예제 #13
0
        // GET: UsersController/Delete/5
        public async Task <ActionResult> Delete(string email)
        {
            var user = await _userManager.FindByEmailAsync(email);

            var aluno = await _dbContext.Alunos.Where(a => a.Email == email).SingleOrDefaultAsync();

            if (aluno != null)
            {
                await _dbContext.RemoverDadosAlunoAsync(aluno.Id);

                _dbContext.Alunos.Remove(aluno);
                await _dbContext.SaveChangesAsync();
            }

            _ = await _userManager.DeleteAsync(user);

            return(RedirectToAction("Index"));
        }
예제 #14
0
        public async Task <IActionResult> OnPostAsync()
        {
            string msg;

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                msg = _loc.GetLocalizedString(culture, "Unable to load user with ID '{0}'.", _userManager.GetUserId(User));
                return(NotFound(msg));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

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

                if (!setPhoneResult.Succeeded)
                {
                    StatusMessage = _loc.GetLocalizedString(culture, "Unexpected error when trying to set phone number.");
                    return(RedirectToPage());
                }
            }

            if (Input.Nome != user.Nome)
            {
                user.Nome = Input.Nome;

                Aluno a = _dbContext.Alunos.Where(a => a.UserId == user.Id).SingleOrDefault();

                if (a != null)
                {
                    a.Nome = user.Nome;
                    await _dbContext.SaveChangesAsync();
                }

                var claims = await _userManager.GetClaimsAsync(user);

                var result = await _userManager.RemoveClaimsAsync(user, claims);

                if (!result.Succeeded)
                {
                    StatusMessage = _loc.GetLocalizedString(culture, "Cannot remove user existing claims.");
                    return(RedirectToPage());
                }

                result = await _userManager.AddClaimAsync(user, new Claim("Nome", user.Nome));

                if (!result.Succeeded)
                {
                    StatusMessage = _loc.GetLocalizedString(culture, "Cannot add claim to user.");
                    return(RedirectToPage());
                }
            }

            await _userManager.UpdateAsync(user);

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = _loc.GetLocalizedString(culture, "Your profile has been updated");
            return(RedirectToPage());
            //return RedirectToPage($"~/{culture}");
        }
예제 #15
0
        public async Task <IActionResult> Index(IndexVM modelo)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = modelo.InputModel.Email,
                    Email    = modelo.InputModel.Email,
                    Nome     = modelo.InputModel.Nome,
                    WhatsApp = modelo.InputModel.WhatsApp
                };

                var result = await _userManager.CreateAsync(user, modelo.InputModel.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim("Nome", user.Nome));

                    _logger.LogInformation("User created a new account with password.");

                    await _dbContext.Alunos.AddAsync(new Aluno { UserId = user.Id, Nome = user.Nome, Email = user.Email, WhatsApp = user.WhatsApp });

                    await _dbContext.SaveChangesAsync();

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        //values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        values: new { area = "Identity", userId = user.Id, code, culture },
                        protocol: Request.Scheme);

                    var mailHeader = _loc.GetLocalizedString(culture, "Confirm your email");
                    //var mailBody = _loc.GetLocalizedString(culture, "Please confirm your account by <a href='{0}'>clicking here</a>.", HtmlEncoder.Default.Encode(callbackUrl));
                    var mailBody = _loc.GetLocalizedString(culture, "Please confirm your account by <a href='{0}'>clicking here</a>.", callbackUrl);

                    //mailBody = mailBody.Replace("amp;amp;", "");

                    await _emailSender.SendEmailAsync(modelo.InputModel.Email, mailHeader, mailBody);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        //return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
                        return(RedirectToPage("/Account/RegisterConfirmation", new { area = "Identity", email = modelo.InputModel.Email, culture }));
                    }
                    else
                    {
                        //await _signInManager.SignInAsync(user, isPersistent: false);
                        //return LocalRedirect(returnUrl);
                    }
                }
                foreach (var error in result.Errors)
                {
                    // model binding error already localized by ExpressLocalization
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            modelo.CheckoutIds = new List <String>();

            modelo.Configuracao = await _dbContext.Configuracoes.FirstOrDefaultAsync();

            modelo.Cursos = _dbContext.Cursos.ToList();

            return(View(modelo));
        }
예제 #16
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = Input.Email,
                    Email    = Input.Email,
                    Nome     = Input.Nome
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim("Nome", user.Nome));

                    IEnumerable <Aluno> alunos = _dbContext.Alunos.Where(a => a.Email == user.Email).ToList();

                    if (alunos != null)
                    {
                        _dbContext.Alunos.RemoveRange(alunos);
                    }

                    await _dbContext.Alunos.AddAsync(new Aluno { UserId = user.Id, Nome = user.Nome, Email = user.Email, WhatsApp = user.WhatsApp });

                    await _dbContext.SaveChangesAsync();

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        //values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        values: new { area = "Identity", userId = user.Id, code = code, culture },
                        protocol: Request.Scheme);

                    var mailHeader = _loc.GetLocalizedString(culture, "Confirm your email");
                    //var mailBody = _loc.GetLocalizedString(culture, "Please confirm your account by <a href='{0}'>clicking here</a>.", HtmlEncoder.Default.Encode(callbackUrl));
                    var mailBody = _loc.GetLocalizedString(culture, "Please confirm your account by <a href='{0}'>clicking here</a>.", callbackUrl);

                    //mailBody = mailBody.Replace("amp;amp;", "");

                    await _emailSender.SendEmailAsync(Input.Email, mailHeader, mailBody);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        //return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, culture }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    // model binding error already localized by ExpressLocalization
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }