コード例 #1
0
        public ActionResult Create([Bind(Include = "Tutor,Student")] AssociateTutor associateTutor)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user              = _db.Users.Find(associateTutor.Tutor.Id);
                Student         student           = _db.Students.Find(associateTutor.Student.Id);
                AssociateTutor  newAssociateTutor = new AssociateTutor
                {
                    Tutor   = user,
                    Student = student
                };
                _db.AssociateTutors.Add(newAssociateTutor);
                try
                {
                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Exception x = ex;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Create", "AssociateTutors"));
            }
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            AssociateTutor associateTutor = _db.AssociateTutors.Find(id);

            _db.AssociateTutors.Remove(associateTutor);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id")] AssociateTutor associateTutor)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(associateTutor).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(associateTutor));
 }
コード例 #4
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssociateTutor associateTutor = _db.AssociateTutors.Find(id);

            if (associateTutor == null)
            {
                return(HttpNotFound());
            }
            return(View(associateTutor));
        }
コード例 #5
0
        public ActionResult GetStudents(string id)
        {
            var allStudents = _db.Students.OrderBy(s => s.FirstName).ToList();
            var students    = new List <Student>(); // Don't include student(s) for whom this tutor is already PrimaryTutor

            // Or for whom this tutor is already Associate Tutor.
            foreach (Student student in allStudents)
            {
                // Check Associate Tutors for duplication:
                using (var context = new SenecaContext())
                {
                    var sqlString = "SELECT * FROM AssociateTutor WHERE Student_Id = " + student.Id;
                    sqlString += " AND Tutor_Id = '" + id + "'";
                    AssociateTutor existingAssociateTutor = null;
                    try
                    {
                        existingAssociateTutor = context.Database.SqlQuery <AssociateTutor>(sqlString).Single();
                    }
                    catch (Exception ex)
                    {
                        var x = ex;
                        existingAssociateTutor = null;
                    }

                    if (existingAssociateTutor == null)
                    {
                        if (student.PrimaryTutor == null)
                        {
                            students.Add(student);
                        }
                        else
                        {
                            if (student.PrimaryTutor.Id != id)
                            {
                                students.Add(student);
                            }
                        }
                    }
                }
            }
            String json = JsonConvert.SerializeObject(students, Formatting.Indented);

            return(Content(json, "application/json"));
        }
コード例 #6
0
        // GET: AssociateTutors/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssociateTutor associateTutor = _db.AssociateTutors.Find(id);

            if (associateTutor == null)
            {
                return(HttpNotFound());
            }
            using (var context = new SenecaContext())
            {
                var sqlString = "SELECT Tutor_Id FROM AssociateTutor WHERE Id = " + associateTutor.Id;
                var tutorId   = context.Database.SqlQuery <string>(sqlString).FirstOrDefault();
                associateTutor.Tutor = _db.Users.Find(tutorId);

                sqlString = "SELECT Student_Id FROM AssociateTutor WHERE Id = " + associateTutor.Id;
                var studentId = context.Database.SqlQuery <int>(sqlString).FirstOrDefault();
                associateTutor.Student = _db.Students.Find(studentId);
            }
            return(View(associateTutor));
        }