Ejemplo n.º 1
0
        public async Task SuggestQuestion(QuestionSuggestion questionSuggestion, string username)
        {
            var user = await this.context.Users.FirstOrDefaultAsync(u => u.UserName == username);

            if (user == null)
            {
                return;
            }

            questionSuggestion.User        = user;
            questionSuggestion.SuggestedOn = DateTime.Now;

            if (questionSuggestion.CorrectAnswer == questionSuggestion.FirstOption ||
                questionSuggestion.CorrectAnswer == questionSuggestion.SecondOption ||
                questionSuggestion.CorrectAnswer == questionSuggestion.ThirdOption ||
                questionSuggestion.CorrectAnswer == questionSuggestion.FourthOption)
            {
                await this.context.QuestionSuggestions.AddAsync(questionSuggestion);
            }
            else
            {
                return;
            }

            await this.notificationService.CreateQuestionSuggestionNotification(user, questionSuggestion);

            await this.context.SaveChangesAsync();
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            if (await IsNotAuthenticated())
            {
                return(GetErrorPage());
            }

            QuestionSuggestion questionSuggestion = db.QuestionSuggestions.Find(id);

            db.QuestionSuggestions.Remove(questionSuggestion);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task CreateQuestionSuggestionNotification(QuizaldoUser user, QuestionSuggestion questionSuggestion)
        {
            var notification = new Notification();

            notification.Text = $"{user.UserName} has suggested a question:\n " +
                                $"{questionSuggestion.QuestionName} with correct answer:\n " +
                                $"{questionSuggestion.CorrectAnswer}.";
            notification.CreatedOn = DateTime.Now;
            notification.UserId    = user.Id;
            notification.User      = user;

            await this.context.Notifications.AddAsync(notification);

            await this.context.SaveChangesAsync();
        }
        public async Task <ActionResult> Edit([Bind(Include = "QuestionId,SuggestionId")] QuestionSuggestion questionSuggestion)
        {
            if (await IsNotAuthenticated())
            {
                return(GetErrorPage());
            }

            if (ModelState.IsValid)
            {
                db.Entry(questionSuggestion).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.QuestionId   = new SelectList(db.Questions, "Id", "Text", questionSuggestion.QuestionId);
            ViewBag.SuggestionId = new SelectList(db.Suggestions, "Id", "Text", questionSuggestion.SuggestionId);
            return(View(questionSuggestion));
        }
        // GET: QuestionSuggestions/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (await IsNotAuthenticated())
            {
                return(GetErrorPage());
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            QuestionSuggestion questionSuggestion = db.QuestionSuggestions.Find(id);

            if (questionSuggestion == null)
            {
                return(HttpNotFound());
            }
            return(View(questionSuggestion));
        }
        // GET: QuestionSuggestions/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (await IsNotAuthenticated())
            {
                return(GetErrorPage());
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            QuestionSuggestion questionSuggestion = db.QuestionSuggestions.Find(id);

            if (questionSuggestion == null)
            {
                return(HttpNotFound());
            }
            ViewBag.QuestionId   = new SelectList(db.Questions, "Id", "Text", questionSuggestion.QuestionId);
            ViewBag.SuggestionId = new SelectList(db.Suggestions, "Id", "Text", questionSuggestion.SuggestionId);
            return(View(questionSuggestion));
        }