コード例 #1
0
        public async Task <IActionResult> PutTest([FromRoute] int id, [FromBody] Test test)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != test.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
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));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,QuestionText,AnswerDescription,UserId")] Question question)
 {
     if (ModelState.IsValid)
     {
         db.Entry(question).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(question));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "Id,EslLevelName")] EslLevel eslLevel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eslLevel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eslLevel));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "Id,GrammaCategoryName")] GrammaCategory grammaCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(grammaCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(grammaCategory));
 }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "Id,LexicTypeName")] LexicType lexicType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lexicType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(lexicType));
 }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description")] Theme theme)
 {
     if (ModelState.IsValid)
     {
         db.Entry(theme).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(theme));
 }
コード例 #8
0
 public ActionResult Edit([Bind(Include = "Id,GrammaCategory,EslLevel,Body,Answer")] GrammaQuestion grammaQuestion)
 {
     if (ModelState.IsValid)
     {
         grammaQuestion.ModifiedAt      = DateTime.Now;
         db.Entry(grammaQuestion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(grammaQuestion));
 }
コード例 #9
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));
        }