示例#1
0
        public HttpResponseMessage GetTestQuestions(int userID)
        {
            var db = new afterugdevEntities3();

            db.Configuration.ProxyCreationEnabled = false;

            var Chapter1Questions = from Questions in db.QuestionsAfterUG
                                    //where (Questions.ChapterID == 1)
                                    select new { QuestionID = Questions.QuestionID, ChapterID = Questions.ChapterID };

            var NonMatchingChapter1 = (from Questions in Chapter1Questions
                                       where !db.TestChild.Any(f => f.QuestionID == Questions.QuestionID && f.UserID == userID)
                                       select new
                                       { QuestionID = Questions.QuestionID, ChapterID = Questions.ChapterID });



            string json = Newtonsoft.Json.JsonConvert.SerializeObject(questionsQuery, Newtonsoft.Json.Formatting.Indented,
                                                                      new Newtonsoft.Json.JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }
                                                                      );

            return(new HttpResponseMessage()
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
示例#2
0
        // GET: api/Question
        public HttpResponseMessage Get()
        {
            var db = new afterugdevEntities3();

            var query = (from b in db.QuestionsAfterUG
                         select b).ToList();

            return(new HttpResponseMessage()
            {
                Content = new StringContent(JArray.FromObject(query).ToString(), Encoding.UTF8, "application/json")
            });
        }
        public HttpResponseMessage Post([FromBody] List <Attempts> listOfAttempts)
        {
            var db = new afterugdevEntities3();

            //List<Company> companies = new List<Company>();

            //listOfAttempts.ForEach(n => db.Attempts.AddRange(n));
            foreach (var attempt in listOfAttempts)
            {
                db.Attempts.Add(attempt);
            }

            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges

                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                           ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }



            return(new HttpResponseMessage()
            {
                Content = new StringContent("Success", Encoding.UTF8, "application/json")
            });
        }
示例#4
0
        public HttpResponseMessage GetTestQuestions(int testNo, int userID)
        {
            var db = new afterugdevEntities3();

            db.Configuration.ProxyCreationEnabled = false;

            var questionsQuery = (from b in db.QuestionsAfterUG.AsNoTracking()
                                  where ((b.QuestionID >= (((testNo - 1) * 5) + 1) && b.QuestionID <= (testNo * 5)))
                                  select new
            {
                b.QuestionID,
                b.QuestionType,
                b.Question,
                b.IsQuestionReviewed,
                b.IsQuestionSpinned,
                b.IsCorrectChoiceVerified,
                b.CorrectChoiceID,
                b.Choices,
                b.ForgetNotes,
                b.QuestionTags,
                b.UserAfterUGNotes,
                b.UserNotes,
                Attempts = b.Attempts.Where(a => a.UserID == userID)
            }).ToList();


            string json = Newtonsoft.Json.JsonConvert.SerializeObject(questionsQuery, Newtonsoft.Json.Formatting.Indented,
                                                                      new Newtonsoft.Json.JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            }
                                                                      );

            return(new HttpResponseMessage()
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }