Esempio n. 1
0
        public async Task <IActionResult> PutQuestion(long id, QuestionDTO questionDTO)
        {
            if (id != questionDTO.Id)
            {
                return(BadRequest());
            }

            var question = await _context.Question.FindAsync(id);

            if (question == null)
            {
                return(NotFound());
            }

            question = UpdatePutableFields(question, questionDTO);

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSessionQuestion(long id, string action, long count = 0)
        {
            var SessionQuestion = await _context.SessionQuestion.FindAsync(id);

            if (SessionQuestion == null)
            {
                return(NotFound());
            }
            if (action.Equals("requeue") && count > 0 && count <= 3)
            {
                SessionQuestion.ResultTypeId          = 2;
                _context.Entry(SessionQuestion).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                // Cap it at the required number of attempts; if you miss a question twice in a row, should still only be 3
                var existingCount = fetchExistingQuestionCount(SessionQuestion);
                for (int i = 0; i < count - existingCount; i++)
                {
                    var NewSessionQuestion = new SessionQuestion
                    {
                        QuestionId    = SessionQuestion.QuestionId,
                        ResultTypeId  = 1,
                        TestSessionId = SessionQuestion.TestSessionId
                    };
                    _context.SessionQuestion.Add(NewSessionQuestion);
                    await _context.SaveChangesAsync();
                }
            }
            else if (action.Equals("answer"))
            {
                SessionQuestion.ResultTypeId          = 3;
                _context.Entry(SessionQuestion).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            else
            {
                return(BadRequest("Unable to determine a proper action to take"));
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutUser(long id, UserDTO UserDTO)
        {
            if (id != UserDTO.Id)
            {
                return(BadRequest());
            }

            var User = await _context.User.FindAsync(id);

            if (User == null)
            {
                return(NotFound());
            }

            User = UpdatePutableFields(User, UserDTO);

            _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> PutTopic(long id, TopicDTO TopicDTO)
        {
            if (id != TopicDTO.Id)
            {
                return(BadRequest());
            }

            var Topic = await _context.Topic.FindAsync(id);

            if (Topic == null)
            {
                return(NotFound());
            }

            Topic = UpdatePutableFields(Topic, TopicDTO);

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutResultType(long id, ResultTypeDTO ResultTypeDTO)
        {
            if (id != ResultTypeDTO.Id)
            {
                return(BadRequest());
            }

            var ResultType = await _context.ResultType.FindAsync(id);

            if (ResultType == null)
            {
                return(NotFound());
            }

            ResultType = UpdatePutableFields(ResultType, ResultTypeDTO);

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

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

            return(NoContent());
        }