Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ExerciseId,ExerciseName,CategoryId")] Exercis exercis)
        {
            if (id != exercis.ExerciseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(exercis);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExercisExists(exercis.ExerciseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", exercis.CategoryId);
            return(View(exercis));
        }
Exemplo n.º 2
0
        public IHttpActionResult PutExercis(int id, Exercis exercis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Exercis exercis = db.Exercises.Find(id);

            db.Exercises.Remove(exercis);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "ID,Name,HowTo,Equipment,ResourceVideo,ResourcePhoto,ResourceText")] Exercis exercis)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exercis).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(exercis));
 }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description")] Exercis exercis)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exercis).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(exercis));
 }
Exemplo n.º 6
0
        public IHttpActionResult GetExercis(int id)
        {
            Exercis exercis = db.Exercises.Find(id);

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

            return(Ok(exercis));
        }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "ExID,ExName,ExDesc,ExPic1,ExVid,RXID,DurID")] Exercis exercis)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exercis).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RXID = new SelectList(db.Rx2, "RXID", "RxName", exercis.RXID);
     return(View(exercis));
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,NumReps,RestTime,Weight,Workout_Id")] Exercis exercis)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exercis).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Workout_Id = new SelectList(db.Workouts, "Id", "Name", exercis.Workout_Id);
     return(View(exercis));
 }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Exercis exercis)
        {
            if (ModelState.IsValid)
            {
                db.Exercises.Add(exercis);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(exercis));
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ID,Name,HowTo,Equipment,ResourceVideo,ResourcePhoto,ResourceText")] Exercis exercis)
        {
            if (ModelState.IsValid)
            {
                db.Exercises.Add(exercis);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(exercis));
        }
Exemplo n.º 11
0
        public IHttpActionResult PostExercis(Exercis exercis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Exercises.Add(exercis);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = exercis.Id }, exercis));
        }
Exemplo n.º 12
0
        public ActionResult Create([Bind(Include = "ExID,ExName,ExDesc,ExPic1,ExVid,RxID,DurID")] Exercis exercis)
        {
            if (ModelState.IsValid)
            {
                db.Exercises.Add(exercis);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RxID = new SelectList(db.RXes, "RxID", "RxName", exercis.RxID);
            return(View(exercis));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Create([Bind("ExerciseId,ExerciseName,CategoryId")] Exercis exercis)
        {
            if (ModelState.IsValid)
            {
                _context.Add(exercis);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", exercis.CategoryId);
            return(View(exercis));
        }
Exemplo n.º 14
0
        public IHttpActionResult DeleteExercis(int id)
        {
            Exercis exercis = db.Exercises.Find(id);

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

            db.Exercises.Remove(exercis);
            db.SaveChanges();

            return(Ok(exercis));
        }
Exemplo n.º 15
0
        // GET: Exercis/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Exercis exercis = db.Exercises.Find(id);

            if (exercis == null)
            {
                return(HttpNotFound());
            }
            return(View(exercis));
        }
Exemplo n.º 16
0
        // GET: Exercis/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Exercis exercis = db.Exercises.Find(id);

            if (exercis == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Workout_Id = new SelectList(db.Workouts, "Id", "Name", exercis.Workout_Id);
            return(View(exercis));
        }
Exemplo n.º 17
0
        // GET: Exercis/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Exercis exercis = db.Exercises.Find(id);

            if (exercis == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RXID = new SelectList(db.Rx2, "RXID", "RxName", exercis.RXID);
            return(View(exercis));
        }
Exemplo n.º 18
0
        public ActionResult Edit(ExerciseViewModel exerciseVM)
        {
            Exercis exercise = new Exercis();

            exercise               = db.Exercises.SingleOrDefault(x => x.Id == exerciseVM.Exercise.Id);
            exercise.Question      = exerciseVM.Exercise.Question;
            exercise.Hint          = exerciseVM.Exercise.Hint;
            exercise.CorrectAnswer = exerciseVM.Exercise.CorrectAnswer;
            exercise.Answer1       = exerciseVM.Exercise.Answer1;
            exercise.Answer2       = exerciseVM.Exercise.Answer2;
            exercise.Answer3       = exerciseVM.Exercise.Answer3;
            exercise.Answer4       = exerciseVM.Exercise.Answer4;

            if (ModelState.IsValid)
            {
                db.Entry(exercise).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Show", "Example", new { exampleID = exerciseVM.Exercise.ExampleID }));
        }
Exemplo n.º 19
0
        public ActionResult StoreStudentRecord(ExampleViewModel exampleVM)
        {
            bool    checkExist      = false;
            int     userID          = (int)Session["userID"];
            int     exerciseID      = exampleVM.StudentRecord.ExerciseID;
            Exercis currentExercise = db.Exercises.SingleOrDefault(x => x.Id == exerciseID);
            string  submittedAnswer = exampleVM.StudentRecord.TempAnswer;
            string  correctAnswer   = "";

            if (currentExercise.CorrectAnswer == "Answer1")
            {
                correctAnswer = currentExercise.Answer1;
            }
            else if (currentExercise.CorrectAnswer == "Answer2")
            {
                correctAnswer = currentExercise.Answer2;
            }
            else if (currentExercise.CorrectAnswer == "Answer3")
            {
                correctAnswer = currentExercise.Answer3;
            }
            else if (currentExercise.CorrectAnswer == "Answer4")
            {
                correctAnswer = currentExercise.Answer4;
            }


            checkExist = db.StudentRecords.Any(x => x.UserID == userID && x.ExerciseID == exerciseID);
            StudentRecord existingStudentRecord = db.StudentRecords.SingleOrDefault(x => x.UserID == userID && x.ExerciseID == exerciseID);

            if (checkExist && existingStudentRecord.CorrectAttempt == null)
            {
                //if student record exist update the record.

                if (existingStudentRecord.Attempt2 == null)
                {
                    existingStudentRecord.Attempt2 = submittedAnswer;
                    if (submittedAnswer == correctAnswer)
                    {
                        existingStudentRecord.CorrectAttempt = "Attempt2";
                    }
                }
                else if (existingStudentRecord.Attempt3 == null)
                {
                    existingStudentRecord.Attempt3 = submittedAnswer;
                    if (submittedAnswer == correctAnswer)
                    {
                        existingStudentRecord.CorrectAttempt = "Attempt3";
                    }
                }
                else
                {
                    existingStudentRecord.Attempt4 = submittedAnswer;
                    if (submittedAnswer == correctAnswer)
                    {
                        existingStudentRecord.CorrectAttempt = "Attempt4";
                    }
                }

                existingStudentRecord.Date = DateTime.Now;

                if (ModelState.IsValid)
                {
                    db.Entry(existingStudentRecord).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else if (!checkExist)
            {
                //if student record not exist then create a new student record

                StudentRecord newStudentRecord = new StudentRecord();
                newStudentRecord.UserID     = userID;
                newStudentRecord.ExerciseID = exerciseID;
                newStudentRecord.Attempt1   = submittedAnswer;

                if (submittedAnswer == correctAnswer)
                {
                    newStudentRecord.CorrectAttempt = "Attempt1";
                }

                newStudentRecord.Date = DateTime.Now;

                db.StudentRecords.Add(newStudentRecord);
                db.SaveChanges();
            }

            //send feedback
            string feedbackMessage;

            if (submittedAnswer == correctAnswer)
            {
                feedbackMessage = "Well done! Correct Answer.";
            }
            else
            {
                feedbackMessage = "Wrong Answer!";
            }

            return(RedirectToAction("Show", "Example", new { exampleID = currentExercise.ExampleID, feedback = feedbackMessage }));
        }