Example #1
0
        public StudentTeacherEditViewModel Update(StudentTeacherEditViewModel StudentTeacherEditViewModel)
        {
            StudentTeacher StudentTeacher = StudentTeacherRepo.Update(StudentTeacherEditViewModel.ToModel());

            unitOfWork.commit();
            return(StudentTeacher.ToEditableViewModel());
        }
        public ActionResult DeleteStudentTeacher(StudentTeacherInfo studentTeacherInfo)
        {
            try
            {
                StudentTeacher studentTeacher = db.StudentTeachers.Where(st => st.StudentId == studentTeacherInfo.studentId && st.TeacherId == studentTeacherInfo.teacherId).FirstOrDefault();

                if (studentTeacher != null)
                {
                    db.StudentTeachers.Remove(studentTeacher);
                    db.SaveChanges();

                    return(Json(new
                    {
                        msg = "Successfully Deleted This Teacher From The Student"
                    }));
                }


                else
                {
                    return(Json(new
                    {
                        msg = "Can't Delete This Teacher From The Student"
                    }));
                }
            }
            catch
            {
                return(Json(new
                {
                    msg = "Can't Delete This Teacher From The Student"
                }));
            }
        }
        public JsonResult addTeachertostudent(int TeacherId, int StudentId)
        {
            StudentTeacher Studentteacher = db.StudentTeachers.SingleOrDefault(a => a.StudentId == StudentId);

            if (Studentteacher == null)
            {
                StudentTeacher studentTeacher0 = new StudentTeacher()
                {
                    TeacherId = TeacherId,
                    StudentId = StudentId
                };

                db.StudentTeachers.Add(Studentteacher);
                db.SaveChanges();
                return(Json(new { Response = "Added" }, JsonRequestBehavior.AllowGet));
            }
            if (Studentteacher.TeacherId == TeacherId || TeacherId == 0)
            {
                return(Json(new { Response = "Already exist  " }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                Studentteacher.TeacherId       = TeacherId;
                db.Entry(Studentteacher).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Json(new { Response = "response " }, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            StudentTeacher studentTeacher = db.StudentTeachers.Find(id);

            db.StudentTeachers.Remove(studentTeacher);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #5
0
 public static StudentTeacherEditViewModel ToEditableViewModel(this StudentTeacher Model)
 {
     return(new StudentTeacherEditViewModel()
     {
         ID = Model.ID,
         StudentID = Model.StudentID,
         TeacherID = Model.TeacherID
     });
 }
Example #6
0
 public static StudentTeacherViewModel ToViewModel(this StudentTeacher Model)
 {
     return(new StudentTeacherViewModel()
     {
         ID = Model.ID,
         StudentID = Model.StudentID,
         TeacherID = Model.TeacherID,
         Teacher = Model.Teacher.ToViewModel()
     });
 }
 public ActionResult Edit([Bind(Include = "StudentId,FacultyId")] StudentTeacher studentTeacher)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentTeacher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StudentId = new SelectList(db.Students, "StudentID", "Name", studentTeacher.StudentId);
     return(View(studentTeacher));
 }
Example #8
0
        public ActionResult Create([Bind(Include = "ID,StudentId,TeacherId")] StudentTeacher studentTeacher)
        {
            if (ModelState.IsValid)
            {
                db.StudentTeachers.Add(studentTeacher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StudentId = new SelectList(db.Students, "ID", "Name", studentTeacher.StudentId);
            ViewBag.TeacherId = new SelectList(db.Teachers, "ID", "Name", studentTeacher.TeacherId);
            return(View(studentTeacher));
        }
Example #9
0
        // GET: StudentTeachers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentTeacher studentTeacher = db.StudentTeachers.Find(id);

            if (studentTeacher == null)
            {
                return(HttpNotFound());
            }
            return(View(studentTeacher));
        }
        // GET: StudentTeachers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentTeacher studentTeacher = db.StudentTeachers.Find(id);

            if (studentTeacher == null)
            {
                return(HttpNotFound());
            }
            ViewBag.StudentId = new SelectList(db.Students, "StudentID", "Name", studentTeacher.StudentId);
            return(View(studentTeacher));
        }
Example #11
0
        // ADD AND REMOVE STUDENTS FUNCTIONS
        public void AddStudentToList(string username, string teacherName)
        {
            using (var db = new QuizBucketContext())
            {
                var addStudent =
                    from student in db.Students
                    where student.StudentName == username
                    select student;
                var relatedTeacher =
                    from teacher in db.Teachers
                    where teacher.TeacherName == teacherName
                    select teacher;

                int studentId = 0;
                int teacherId = 0;

                foreach (var item in addStudent)
                {
                    studentId = item.StudentId;
                }
                foreach (var item in relatedTeacher)
                {
                    teacherId = item.TeacherId;
                }

                var doesExist = db.StudentTeachers.Where(st => st.StudentId == studentId && st.TeacherId == teacherId).FirstOrDefault();

                if (!db.StudentTeachers.Contains(doesExist))
                {
                    var studentTeacher = new StudentTeacher
                    {
                        StudentId = studentId,
                        TeacherId = teacherId
                    };
                    db.StudentTeachers.Add(studentTeacher);
                    db.SaveChanges();
                }
                else
                {
                    throw new ArgumentException("Cannot duplicated student!");
                }
            }
        }
        // GET: Student/Edit
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Student        student        = db.Students.Find(id);
            StudentTeacher studentTeacher = (StudentTeacher)db.StudentTeachers.SingleOrDefault(a => a.StudentId == id);


            if (student == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FieldId        = new SelectList(db.Fields, "ID", "Name", student.FieldId);
            ViewBag.GovernorateId  = new SelectList(db.Governorates, "ID", "Name", student.GovernorateId);
            ViewBag.NeighborhoodId = new SelectList(db.Neighborhoods, "ID", "Name", student.NeighborhoodId);
            ViewBag.TeacherId      = new SelectList(db.Teachers, "ID", "Name", studentTeacher != null? studentTeacher.TeacherId:0);
            return(View(student));
        }
        /// <summary>
        /// Here we adds student to teacher by his id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <TeacherResult> AddStudentToTeacherById(int?id, int?teacherId)
        {
            var studentTeacher = new StudentTeacher();

            studentTeacher.StudentId = id;

            studentTeacher.TeacherId = teacherId;

            await this.context.StudentsTeachers.AddAsync(studentTeacher);

            var result = await this.context.SaveChangesAsync();

            if (result > 0)
            {
                return(new TeacherResult(true));
            }
            else
            {
                return(new TeacherResult(false));
            }
        }
        public ActionResult AddTeacher(StudentTeacherInfo studentTeacherInfo)
        {
            try
            {
                var teacherExist = db.StudentTeachers.Where(st => st.StudentId == studentTeacherInfo.studentId && st.TeacherId == studentTeacherInfo.teacherId).FirstOrDefault();
                if (teacherExist == null)
                {
                    StudentTeacher studentTeacher = new StudentTeacher();
                    studentTeacher.TeacherId = studentTeacherInfo.teacherId;
                    studentTeacher.StudentId = studentTeacherInfo.studentId;
                    if (ModelState.IsValid)
                    {
                        db.StudentTeachers.Add(studentTeacher);
                        db.SaveChanges();
                    }

                    return(Json(new
                    {
                        msg = "Successfully Added This Teacher To The Student"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        msg = "This Teacher Is Already Applied To The Student"
                    }));
                }
            }
            catch
            {
                return(Json(new
                {
                    msg = "Can't Add This Teacher To The Student"
                }));
            }
        }
Example #15
0
        public bool AddNewStudentTeacher([FromBody] StudentTeacher data)
        {
            try
            {
                checkOnAccess(this.Request.Headers);
            }
            catch (Exception ex)
            {
                throw ex;
            };

            var db = new DBModel();

            var query = (from u in db.Users
                         where u.UserName == data.userName
                         select u).First();

            if (data.role == "student")
            {
                Student student = new Student()
                {
                    UserName = data.userName,
                    Name     = query.Name,
                    SchoolId = data.schoolId,
                    Grade    = data.grade
                };

                try
                {
                    query.Role = "student";
                    db.Students.Add(student);
                    query.FinishedSignUP = 1;
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                };
            }

            else
            {
                Teacher teacher = new Teacher()
                {
                    UserName = data.userName,
                    Name     = query.Name,
                    SchoolId = data.schoolId,
                };

                try
                {
                    query.Role = "teacher";
                    db.Teachers.Add(teacher);
                    db.SaveChanges();

                    int teacherId = GetUserID(data.userName, "teacher");

                    foreach (var item in data.categories)
                    {
                        db.TeacherCategories.Add(new TeacherCategory()
                        {
                            TeacherId = teacherId,
                            Category  = item
                        });
                    }
                    ;

                    query.FinishedSignUP = 1;
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    throw ex;
                };
            };
        }
Example #16
0
 public void AddMember(StudentTeacher m)
 {
     _context.StudentTeacher.Add(m);
     _context.SaveChanges();
 }
 public void AddTeacherToStudent(StudentTeacher stdtTeacher)
 {
     _db.StudentTeachers.Add(stdtTeacher);
     _db.SaveChanges();
 }