コード例 #1
0
        public async Task <IActionResult> Create([Bind("QuestionsID,QuestionsToClient,QuestionsState")] Questions questions, string[] selectedDifficulty)
        {
            if (selectedDifficulty != null)
            {
                questions.Answer = new List <Answer>();
                foreach (var difficulty in selectedDifficulty)
                {
                    var difficultyToAdd = new Answer {
                        QuestionsID = questions.QuestionsID, DifficultyID = int.Parse(difficulty)
                    };
                    questions.Answer.Add(difficultyToAdd);
                }
            }


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

                return(RedirectToAction("Index"));
            }
            Select_YN_Rebind();

            /*
             * PopulateAssignedDifficultyData(questions);
             */
            return(View(questions));
        }
コード例 #2
0
        public async Task <IActionResult> Create(string sortOrder, string currentFilter, string searchString, int?page, bool concluir, [Bind("TuristAnswerID,SurveyNumber,AnswerDate,TuristAnswerState,TuristID,AnswerID")] TuristAnswer turistAnswer)
        {
            var user = await _userManager.GetUserAsync(User);

            string nome  = user.UserName;
            string email = user.Email;
            string phone = user.PhoneNumber;

            ViewData["CurrentSort"] = sortOrder;

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }



            var lista = from z in _context.Questions.Include(a => a.Answer) select z;

            int pageSize = 1;

            var listadeturistas = _context.Turist.Where(t => (t.Email == email));

            foreach (var item in listadeturistas)
            {
                turistAnswer.TuristID = item.TuristID;
            }



            if (ModelState.IsValid && ModelState.Count > 0)
            {
                if (turistAnswer.AnswerID != 0)
                {
                    turistAnswer.SurveyNumber      = 1;
                    turistAnswer.AnswerDate        = System.DateTime.Today;
                    turistAnswer.TuristAnswerState = true;
                    _context.Add(turistAnswer);
                    await _context.SaveChangesAsync();
                }
            }
            if (concluir)
            {
                return(RedirectToAction("Details"));
            }
            else
            {
                return(View(await PaginatedList <Questions> .CreateAsync(lista.AsNoTracking(), page ?? 1, pageSize)));

                /* ViewData["AnswerID"] = new SelectList(_context.Answer, "AnswerID", "AnswerID", turistAnswer.AnswerID);
                 * ViewData["TuristID"] = new SelectList(_context.Turist, "TuristID", "TuristID", turistAnswer.TuristID);*/
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("TuristID,TuristName,Phone,Genre,Birthday,NIF,Email,EmergencyContact,TuristState,TypeTurist")] Turist turist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(turist);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(turist));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("AnswerID,PossibleAnswer,QuestionsID,DifficultyID")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(answer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Questions"));
            }
            ViewData["DifficultyID"] = new SelectList(_context.Difficulty, "DifficultyID", "DifficultyID", answer.DifficultyID);
            ViewData["QuestionsID"]  = new SelectList(_context.Questions, "QuestionsID", "QuestionsID", answer.QuestionsID);
            return(View(answer));
        }
コード例 #5
0
        public async Task <IActionResult> Register([Bind("TuristID,TuristName,Phone,Genre,Birthday,NIF,Email,EmergencyContact,TuristState")] Turist turist, RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.TuristName, Email = model.Email, PhoneNumber = model.Phone,
                };
                turist = new Turist
                {
                    Email            = model.Email,
                    TuristName       = model.TuristName,
                    Phone            = model.Phone,
                    NIF              = model.NIF,
                    Genre            = model.Genre,
                    Birthday         = model.Birthday,
                    EmergencyContact = model.EmergencyContact,
                    TypeTurist       = model.TypeTurist,
                    TuristState      = true
                };

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

                if (result.Succeeded)
                {
                    if (turist.TypeTurist == "Admin")
                    {
                        await _userManager.AddToRoleAsync(user, "Admin");
                    }
                    if (turist.TypeTurist == "Professor")
                    {
                        await _userManager.AddToRoleAsync(user, "Professor");
                    }
                    if (turist.TypeTurist == "Turista")
                    {
                        await _userManager.AddToRoleAsync(user, "Turista");
                    }


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


                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

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


                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

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