예제 #1
0
        public async Task <IActionResult> PutUser([FromRoute] int id, [FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostUserExamTaken([FromBody] UserExamTaken userExamTaken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.UserExamTaken.Add(userExamTaken);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (UserExamTakenExists(userExamTaken.UserId, userExamTaken.ExamId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetUserExamTaken", new { id = userExamTaken.UserId }, userExamTaken));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,QuestionText,CorrectAnswer,WrongAnswers,Score,ExamId,Row,Definition,Visibility")] Question question)
        {
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "Id", "Id", question.ExamId);
            return(View(question));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,CreatorId,ExamTitle")] Exam exam)
        {
            if (ModelState.IsValid)
            {
                _context.Add(exam);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CreatorId"] = new SelectList(_context.Users, "Id", "Id", exam.CreatorId);
            return(View(exam));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Score,Answered,CorrectAnswer,QuestionId,UserId")] QuestionResult questionResult)
        {
            if (ModelState.IsValid)
            {
                _context.Add(questionResult);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["QuestionId"] = new SelectList(_context.Questions, "Id", "Id", questionResult.QuestionId);
            ViewData["UserId"]     = new SelectList(_context.Users, "Id", "Id", questionResult.UserId);
            return(View(questionResult));
        }
        public async Task <IActionResult> Create([Bind("Id,FullName,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                using (var sha256 = SHA256.Create())
                {
                    // Send a sample text to hash.
                    var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(user.Password));
                    // Get the hashed string.
                    user.Password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                }

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

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