Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("CourseId,InstructorId,TermId")] TeachingAssignment teachingAssignment)
        {
            if (id != teachingAssignment.CourseId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(teachingAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeachingAssignmentExists(teachingAssignment.CourseId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]     = new SelectList(_context.Courses, "CourseId", "CourseId", teachingAssignment.CourseId);
            ViewData["InstructorId"] = new SelectList(_context.Instructor, "InstructorId", "InstructorId", teachingAssignment.InstructorId);
            ViewData["TermId"]       = new SelectList(_context.StudyTerm, "TermId", "TermId", teachingAssignment.TermId);
            return(View(teachingAssignment));
        }
        public ActionResult DeleteConfirmed(int?id, string id1, int?id2)
        {
            TeachingAssignment teachingAssignment = db.TeachingAssignments.Find(id, id1, id2);

            db.TeachingAssignments.Remove(teachingAssignment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TeachingAssignment teachingAssignment = db.TeachingAssignment.Find(id);

            db.TeachingAssignment.Remove(teachingAssignment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult EditTeachingAssignment(int assignmentId, TeachingAssignmentModel model)
        {
            var oldAssignment = _teachingAssignmentService.GetTeachingAssignment(assignmentId);

            // if no class is found
            if (oldAssignment == null)
            {
                return(NotFound());
            }

            // check if foreign key(s), unique key(s) are invalid
            if (!IsKeyValid(model))
            {
                return(StatusCode(_resp.code, _resp));
            }

            // check if model matches with data annotation in front-end model
            if (ModelState.IsValid)
            {
                var newAssignment = new TeachingAssignment(oldAssignment);

                newAssignment.TeacherID = model.TeacherID;
                newAssignment.ClassID   = model.ClassID;
                newAssignment.SubjectID = model.SubjectID;

                // check for (teacherId, classId, subjectId)
                if (newAssignment.TeacherID != oldAssignment.TeacherID || newAssignment.ClassID != oldAssignment.ClassID || newAssignment.SubjectID != oldAssignment.SubjectID)
                {
                    if (_exist.TeachingAssignmentExist(newAssignment.TeacherID, newAssignment.ClassID, newAssignment.SubjectID))
                    {
                        _resp.code = 400; // bad request
                        _resp.messages.Add(new { Teacher = "Already assign teacher for this class with this subject" });
                        return(StatusCode(_resp.code, _resp));
                    }
                }

                // bind value(s)
                oldAssignment.TeacherID = newAssignment.TeacherID;
                oldAssignment.ClassID   = newAssignment.ClassID;
                oldAssignment.SubjectID = newAssignment.SubjectID;

                _teachingAssignmentService.Update();

                return(Ok(oldAssignment));
            }
            else
            {
                var errors = new List <string>();
                foreach (var state in ModelState)
                {
                    foreach (var error in state.Value.Errors)
                    {
                        errors.Add(error.ErrorMessage);
                    }
                }
                return(BadRequest(errors));
            }
        }
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            TeachingAssignment teachingAssignment = await db.TeachingAssignments.FindAsync(id);

            db.TeachingAssignments.Remove(teachingAssignment);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Instructor_ID,Course_ID,Term_ID")] TeachingAssignment teachingAssignment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(teachingAssignment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Course_ID     = new SelectList(db.Courses, "Course_ID", "Course_Name", teachingAssignment.Course_ID);
     ViewBag.Instructor_ID = new SelectList(db.Instructors, "Instructor_ID", "Instructor_First_Name", teachingAssignment.Instructor_ID);
     ViewBag.Term_ID       = new SelectList(db.Terms, "Term_ID", "Term_Name", teachingAssignment.Term_ID);
     return(View(teachingAssignment));
 }
        // GET: TeachingAssignments/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachingAssignment teachingAssignment = db.TeachingAssignments.Find(id);

            if (teachingAssignment == null)
            {
                return(HttpNotFound());
            }
            return(View(teachingAssignment));
        }
        // GET: TeachingAssignments/Details/5
        public ActionResult Details(int?id, string id1, int?id2)
        {
            if (id == null || id1.Equals(null) || id2 == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachingAssignment teachingAssignment = db.TeachingAssignments.Find(id, id1, id2);

            if (teachingAssignment == null)
            {
                return(HttpNotFound());
            }
            return(View(teachingAssignment));
        }
        public ActionResult Create([Bind(Include = "InstructorID,CourseID,TermID")] TeachingAssignment teachingAssignment)
        {
            if (ModelState.IsValid)
            {
                db.TeachingAssignments.Add(teachingAssignment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseID     = new SelectList(db.Courses, "CourseID", "CourseName", teachingAssignment.CourseID);
            ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "InstructorFirstName", teachingAssignment.InstructorID);
            ViewBag.TermID       = new SelectList(db.StudyTerms, "TermID", "TermName", teachingAssignment.TermID);
            return(View(teachingAssignment));
        }
        // GET: TeachingAssignments/Delete/5
        public async Task <ActionResult> Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachingAssignment teachingAssignment = await db.TeachingAssignments.FindAsync(id);

            if (teachingAssignment == null)
            {
                return(HttpNotFound());
            }
            return(View(teachingAssignment));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Create([Bind("CourseId,InstructorId,TermId")] TeachingAssignment teachingAssignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teachingAssignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]     = new SelectList(_context.Courses, "CourseId", "CourseId", teachingAssignment.CourseId);
            ViewData["InstructorId"] = new SelectList(_context.Instructor, "InstructorId", "InstructorId", teachingAssignment.InstructorId);
            ViewData["TermId"]       = new SelectList(_context.StudyTerm, "TermId", "TermId", teachingAssignment.TermId);
            return(View(teachingAssignment));
        }
        public async Task <ActionResult> Edit([Bind(Include = "InstructorID,CourseID,TermID")] TeachingAssignment teachingAssignment)
        {
            if (ModelState.IsValid)
            {
                db.Entry(teachingAssignment).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CourseID     = new SelectList(db.Courses, "CourseID", "CourseName", teachingAssignment.CourseID);
            ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "InstructorFirstName", teachingAssignment.InstructorID);
            ViewBag.TermID       = new SelectList(db.StudyTerms, "TermID", "TermName", teachingAssignment.TermID);
            return(View(teachingAssignment));
        }
        // GET: TeachingAssignments/Edit/5
        public ActionResult Edit(int?id, string id1, int?id2)
        {
            if (id == null || id1.Equals(null) || id2 == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachingAssignment teachingAssignment = db.TeachingAssignments.Find(id, id1, id2);

            if (teachingAssignment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Course_ID     = new SelectList(db.Courses, "Course_ID", "Course_Name", teachingAssignment.Course_ID);
            ViewBag.Instructor_ID = new SelectList(db.Instructors, "Instructor_ID", "Instructor_First_Name", teachingAssignment.Instructor_ID);
            ViewBag.Term_ID       = new SelectList(db.Terms, "Term_ID", "Term_Name", teachingAssignment.Term_ID);
            return(View(teachingAssignment));
        }
        // GET: TeachingAssignments/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TeachingAssignment teachingAssignment = db.TeachingAssignments.Find(id);

            if (teachingAssignment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CourseID     = new SelectList(db.Courses, "CourseID", "CourseName", teachingAssignment.CourseID);
            ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "InstructorFirstName", teachingAssignment.InstructorID);
            ViewBag.TermID       = new SelectList(db.StudyTerms, "TermID", "TermName", teachingAssignment.TermID);
            return(View(teachingAssignment));
        }
        // [Authorize(Roles = "Manager")]
        public ActionResult CreateTeachingAssignment(TeachingAssignmentModel model)
        {
            if (ModelState.IsValid)
            {
                if (!IsKeyValid(model))
                {
                    return(StatusCode(_resp.code, _resp));
                }

                if (_exist.TeachingAssignmentExist(model.TeacherID, model.ClassID, model.SubjectID))
                {
                    _resp.code = 400; // 400: Bad Request
                    _resp.messages.Add("Invalid unique key");
                    return(BadRequest(_resp));
                }

                TeachingAssignment teachingAssign = new TeachingAssignment
                {
                    TeacherID = model.TeacherID,
                    ClassID   = model.ClassID,
                    SubjectID = model.SubjectID
                };

                // create teacher
                _teachingAssignmentService.CreateTeachingAssignment(teachingAssign);

                return(StatusCode(201)); // 201: Created
            }
            else
            {
                // response helper method
                var errors = new List <string>();
                foreach (var state in ModelState)
                {
                    foreach (var error in state.Value.Errors)
                    {
                        errors.Add(error.ErrorMessage);
                    }
                }
                return(BadRequest(errors));
            }
        }
Ejemplo n.º 16
0
 public void DeleteTeachingAssignment(TeachingAssignment teachingAssignment)
 {
     _unitOfWork.TeachingAssignment.Remove(teachingAssignment);
     _unitOfWork.Complete();
 }
Ejemplo n.º 17
0
 public void CreateTeachingAssignment(TeachingAssignment teachingAssignment)
 {
     _unitOfWork.TeachingAssignment.Add(teachingAssignment);
     _unitOfWork.Complete();
 }