Beispiel #1
0
        public IHttpActionResult PutQuestion(int id, Question question)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,QuestionText,AnswerDescription,UserId,Answers")] Question question)
        {
            if (ModelState.IsValid)
            {
                question.UserId = "tempUserId";


                //db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Answers ON");
                //question.Id = db.Questions.Max(q => q.Id) + 1;

                for (int i = 1; i <= question.Answers.Count; i++)
                {
                    question.Answers[i - 1].QuestionAnswerId = i;
                    //question.Answers[i - 1].Id = db.Answers.Max(a=>a.Id) + 1;
                }
                //db.Database.Connection.Open();
                //db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Questions ON");
                //question.Id = db.Questions.Max(q => q.Id) + 1;
                db.Questions.Add(question);

                //db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Answers OFF");
                db.SaveChanges();
                //db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Questions OFF");
                //db.Database.Connection.Close();
                return(RedirectToAction("Index"));
            }

            return(View(question));
        }
Beispiel #3
0
        public async Task <int> CreateAsync(QuestionViewModel questionViewModel)
        {
            var question = _mapper.Map <Question>(questionViewModel);

            await _context.Questions.AddAsync(question);

            _context.SaveChanges();

            return(question.Id);
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,EslLevelName")] EslLevel eslLevel)
        {
            if (ModelState.IsValid)
            {
                db.EslLevels.Add(eslLevel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eslLevel));
        }
        public ActionResult Create([Bind(Include = "Id,GrammaCategoryName")] GrammaCategory grammaCategory)
        {
            if (ModelState.IsValid)
            {
                db.GrammaCategories.Add(grammaCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(grammaCategory));
        }
        public ActionResult Create([Bind(Include = "Id,LexicTypeName")] LexicType lexicType)
        {
            if (ModelState.IsValid)
            {
                db.LexicTypes.Add(lexicType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lexicType));
        }
        public IActionResult Post([FromBody] Question question)
        {
            if (question == null)
            {
                return(BadRequest());
            }

            db.Questions.Add(question);
            db.SaveChanges();
            return(Ok(question));
        }
        public ActionResult Create([Bind(Include = "Id,GrammaCategory,EslLevel,Body,Answer")] GrammaQuestion grammaQuestion)
        {
            if (ModelState.IsValid)
            {
                grammaQuestion.ModifiedAt = DateTime.Now;
                db.GrammaQuestions.Add(grammaQuestion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(grammaQuestion));
        }
Beispiel #9
0
        public IActionResult Ask([FromQuery] string content)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                return(BadRequest("The Question Content can not be empty"));
            }

            _context.Questions.Add(new QuestionDB {
                Content = content
            });
            _context.SaveChanges();

            RefreshClients();

            return(Ok());
        }
Beispiel #10
0
        public Question Save(Question entity)
        {
            using (var ctx = new QuestionsContext())
            {
                ctx.Questions.Add(entity);
                ctx.SaveChanges();
            }

            return(entity);
        }
Beispiel #11
0
        public IHttpActionResult PutUserPerformance(string userEmail, UserPerformance userPerformance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (userEmail != userPerformance.UserId)
            {
                return(BadRequest());
            }

            UserPerformance currentPerformance = db.UserPerformances.First(x => x.UserId == userEmail);

            if (currentPerformance != null)
            {
                userPerformance.CorrectAnswerCount += currentPerformance.CorrectAnswerCount;
                userPerformance.TotalGamesCount    += currentPerformance.TotalGamesCount;
                userPerformance.TotalQuestions     += currentPerformance.TotalQuestions;
            }


            db.Entry(userPerformance).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserPerformanceExists(userPerformance.UserId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public QuestionsController(QuestionsContext context)
 {
     this.db = context;
     if (!db.Questions.Any())
     {
         db.Questions.Add(new Question {
             QuestionText = "Чем меряются⁣ ⁣между ⁣собой любители армрестлинга?", Answers = "Силой рук || Остротой зубов || Быстротой ног || Размерами животов"
         });
         db.SaveChanges();
     }
 }
Beispiel #13
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Theme theme, int[] selectedQuestions)
        {
            if (selectedQuestions != null)
            {
                foreach (var questionId in selectedQuestions)
                {
                    var questinon = db.Questions.Find(questionId);
                    theme.Questions.Add(questinon);
                }
            }

            if (ModelState.IsValid)
            {
                db.Themes.Add(theme);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(theme));
        }
Beispiel #14
0
        public bool DeleteById(long idQuestion)
        {
            bool returnValue = false;

            using (var ctx = new QuestionsContext())
            {
                var entRemove = ctx.Questions.Find(idQuestion);
                ctx.Questions.Remove(entRemove);
                ctx.SaveChanges();

                returnValue = true;
            }
            return(returnValue);
        }
Beispiel #15
0
        public Question Update(Question entity)
        {
            Question returnValue = null;

            using (var ctx = new QuestionsContext())
            {
                returnValue = ctx.Questions.Find(entity.ID);

                if (returnValue == null)
                {
                    throw new QuestionLibaryException("The item with [ID={0}] does not exist.", entity.ID.ToString());
                }

                returnValue.Description = entity.Description;
                returnValue.Number      = entity.Number;

                ctx.SaveChanges();
            }

            return(returnValue);
        }