public IHttpActionResult PutQuestion(Guid id, UpdateQuestion newQuestion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var question = db.Questions.Find(id);

            question.QuestionBody    = newQuestion.QuestionBody;
            db.Entry(question).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public bool UpdateQuestion(int IDQuestion, int level, int status)
        {
            SqlConnection sqlConnection = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=HangWeb;Data Source=DESKTOP-MLI7UBI");

            string cmdString = "UPDATE msQuestion SET Difficulty=" + level + ", Status=" + status + " WHERE IDQuestion=" + IDQuestion;

            SqlCommand    sqlCommand = new SqlCommand();
            SqlDataReader UpdateQuestion;

            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.CommandText = cmdString;
            sqlConnection.Open();

            try
            {
                UpdateQuestion = sqlCommand.ExecuteReader();
                UpdateQuestion.Close();
                sqlCommand.Dispose();
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        public async Task UpdateQuestion(PangulDbContext db, UserContext user, UpdateQuestion model)
        {
            model.UserContext   = user;
            model.Derived.Topic = model.Topic == null ? null : await _topicService.RequireTopic(db, user, model.Topic);

            await _updateQuestion.Execute(db, model);
        }
Example #4
0
        public async Task <HttpResponseMessage> UpdateQuestion([FromBody] QuestionDto question)
        {
            var command = new UpdateQuestion(question);
            var result  = await _commandDispatcher.DispatchAsync(command) as IdentityResult;

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(result.Identity)
            });
        }
        public async Task <IActionResult> PutQuestionAsync([FromBody] UpdateQuestion command)
        {
            await rules
            .NoDuplicateQuestionText()
            .QuestionMustNotBeAnswered()
            .Apply(command, ModelState);

            command.UserId = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await service.Execute(command);

            return(Ok());
        }
        public IApiResult Update(UpdateQuestion operation)
        {
            var result = operation.ExecuteAsync().Result;

            if (result is ValidationsOutput)
            {
                return(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                });
            }
            else
            {
                return(new ApiResult <object>()
                {
                    Status = ApiResult <object> .ApiStatus.Success
                });
            }
        }
        public async Task Execute(UpdateQuestion command)
        {
            var existingQuestion = await writeContext.SurveyQuestionBank
                                   .FindAsync(command.QuestionId);

            if (existingQuestion == null)
            {
                throw new EntityNotFoundException(typeof(SurveyQuestionBank), command.QuestionId);
            }

            existingQuestion.DsQuestion     = command.QuestionText;
            existingQuestion.CdQuestionType = command.QuestionType;
            existingQuestion.CdCodeType     = command.CodeType;
            existingQuestion.InBankQuestion = command.SaveToBank;
            existingQuestion.IdChanged      = command.UserId;
            existingQuestion.DtChanged      = DateTime.Now;

            await writeContext.SaveChangesAsync();
        }
        public async Task Execute(PangulDbContext db, UpdateQuestion command)
        {
            command.Validate();

            // Get existing question
            var question = await _getQuestion.Execute(db, new GetQuestion()
            {
                UserContext     = command.UserContext,
                LightWeightOnly = false,
                QuestionId      = command.QuestionId,
                RowVersion      = command.RowVersion,
            });

            if (question == null)
            {
                throw new PangulCommandFailedException(CommandFailureType.MissingData, $"No such question ({command.QuestionId}, {command.RowVersion})");
            }

            // Verify user has permission
            await _internalUserPermissionService.RequireWriteAccessFor(question, command.UserContext);

            // Get tag lists
            var tags     = command.Tags ?? new string[0];
            var newTags  = tags.Where(i => question.Tags.All(j => j.Tag != i) && !string.IsNullOrWhiteSpace(i));
            var dropTags = question.Tags.Where(i => tags.All(j => j != i.Tag));

            // Update properties
            command.ApplyTo(question);

            // Drop old tags
            foreach (var tag in dropTags)
            {
                db.QuestionTag.Remove(tag);
            }

            // Create tags for those not present
            await db.QuestionTag.AddRangeAsync(newTags.Select(t => new QuestionTag
            {
                Tag        = t,
                QuestionId = question.QuestionId
            }));
        }
Example #9
0
        public ActionResult UpdateQuestion(int id, UpdateQuestion updateQuestion)
        {
            var db           = new DatabaseContext();
            var prevQuestion = db.Questions.FirstOrDefault(q => q.Id == updateQuestion.Id);

            if (prevQuestion == null)
            {
                return(NotFound());
            }
            else if (updateQuestion.Id != id)
            {
                return(BadRequest(new { error = $"Endpoint Id ({id}) and object Id ({updateQuestion.Id}) differ." }));
            }
            else
            {
                prevQuestion.QuestionTitle        = updateQuestion.QuestionTitle;
                prevQuestion.QuestionText         = updateQuestion.QuestionText;
                prevQuestion.VoteValue            = updateQuestion.VoteValue;
                prevQuestion.LastModifiedDateTime = DateTime.UtcNow;
                db.SaveChanges();
                return(Ok(prevQuestion));
            }
        }
        public IHttpActionResult Update(UpdateQuestion question)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                Question quest = _questionService.Find(_ => _.Code == question.Code,
                                                       _ => _.Options,
                                                       _ => _.QuestionObjectives);

                if (quest != null)
                {
                    IList <QuestionObjective> questionObjectives = new List <QuestionObjective>();

                    LearningOutcome learningOutcome;
                    if (question.LearningOutcomes == null)
                    {
                        learningOutcome = _learingOutcomeService.Find(_ => _.MainObjective.CourseCode == quest.CourseCode &&
                                                                      _.MainObjective.Order == 0, _ => _.MainObjective);

                        question.LearningOutcomes = new List <int> {
                            learningOutcome.Id
                        };
                    }

                    foreach (var lo in question.LearningOutcomes)
                    {
                        foreach (var c in question.Chapters)
                        {
                            questionObjectives.Add(new QuestionObjective
                            {
                                QuestionCode = quest.Code, LearningOutcomeId = lo, ChapterId = c
                            });
                        }
                    }

                    if (_questionService.Update(quest, new Question
                    {
                        LevelId = question.Level,
                        IsExamQuestion = question.IsExam,
                        Content = question.Content,
                        TypeId = question.Type,
                        Mark = question.Mark,
                        QuestionObjectives = questionObjectives,
                        Options = ModelBuilder.CreateOptions(question.Options)
                    }))
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception ex)
            {
                _loggingService.Write(ex);
                return(InternalServerError(ex));
            }
        }
 public async Task <IActionResult> Update(UpdateQuestion _updateQuestion)
 {
     return(Ok(await Mediator.Send(_updateQuestion)));
 }