Example #1
0
 public CourseRatingPage(Course c, Enrolled e)
 {
     InitializeComponent();
     _historyService = new HistoryService((string)Application.Current.Properties["jwt"]);
     chosenCourse    = new EnrolledViewModel(c, e);
     BindingContext  = chosenCourse;
 }
Example #2
0
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false},
        /// false if the student is already enrolled in the Class.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            // Query db for ClassID from given Course(subject/num) and Semester(season/year)
            var query =
                from cl in db.Class
                join cr in db.Course on cl.CourseId equals cr.CourseId
                join sm in db.Semester on cl.SemesterId equals sm.SemesterId
                where cr.DeptAbbr == subject && cr.Number == num && sm.Season == season && sm.Year == year
                select cl.ClassId;

            uint classID = query.First();

            Enrolled newEnroll = new Enrolled();

            newEnroll.ClassId = classID;
            newEnroll.SId     = uid;
            newEnroll.Grade   = "--";

            // try adding the new enrolled info to the db. Only return true if the changes are applied successfully.
            try
            {
                db.Enrolled.Add(newEnroll);
                db.SaveChanges();
                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }

            return(Json(new { success = false }));
        }
        public void buildRateCourseViewModelTest_NullCourse()
        {
            Enrolled            enrolled            = _context.Enrolled.Find(9);
            RateCourseViewModel rateCourseViewModel = _viewModelService.buildRateCourseViewModel(enrolled, null);

            Assert.Null(rateCourseViewModel);
        }
Example #4
0
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}.
        /// false if the student is already enrolled in the class, true otherwise.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            uint theID = uint.Parse(uid.Remove(0, 1));
            var  query =
                from d in db.Department
                where d.Abbrv == subject
                join co in db.Course on d.DepartmentId equals co.DepartmentId
                where co.Number == num
                join cl in db.Class on co.CourseId equals cl.CourseId
                where cl.Season == season && cl.Year == year
                select new
            {
                cl.ClassId
            };

            if (db.Enrolled.Where(en => en.UId == theID && en.ClassId == query.First().ClassId).Any())
            {
                return(Json(new { success = false }));
            }
            Enrolled e = new Enrolled();

            e.ClassId = query.First().ClassId;
            e.UId     = theID;
            e.Grade   = "--";

            db.Enrolled.Add(e);

            if (db.SaveChanges() > 0)
            {
                return(Json(new { success = true }));
            }

            return(Json(new { success = false }));
        }
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}.
        /// false if the student is already enrolled in the class, true otherwise.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid) //works
        {
            //sub , num --> catalogID
            // catalogID, season, year --> classid
            // classid, uied -- add to Enroll
            var flag = false;

            using (Team9LMSContext db = new Team9LMSContext())
            {
                var classIDQuery = from cid in (from c in db.Courses
                                                where c.Subject == subject && c.Num == num
                                                select new { CatalogId = c.CatalogId })
                                   join cl in db.Classes
                                   on cid.CatalogId equals cl.CatalogId
                                   where cl.Semester == year.ToString() + season
                                   select new { classID = cl.ClassId };
                Enrolled newEn = new Enrolled();
                newEn.UId     = uid;
                newEn.ClassId = (uint)Convert.ToInt32(classIDQuery.First().classID);

                db.Enrolled.Add(newEn);
                db.SaveChanges();

                flag = true;
            }
            return(Json(new { success = flag }));
        }
Example #6
0
        public async void UpdateEnrollTest_HappyPath()
        {
            int      enrollNum = 1;
            Enrolled enrolled  = await _enrollService.getEnrollAsync(enrollNum);

            Assert.NotNull(enrolled);
            //Make changes
            enrolled.courseId  = 99;
            enrolled.studentId = 99;
            enrolled.completed = true;
            enrolled.grade     = 99;
            enrolled.rating    = 99;
            enrolled.comment   = "";
            enrolled.course    = null;
            enrolled.student   = null;
            //Update the enrolled
            _enrollService.updateEnroll(enrolled);
            Enrolled enrolledTemp = await _enrollService.getEnrollAsync(enrollNum);

            Assert.NotNull(enrolledTemp);
            //Verify that the changes took place
            Assert.True(enrolledTemp.enrollId == 1);
            Assert.True(enrolledTemp.studentId == 99);
            Assert.True(enrolledTemp.completed);
            Assert.True(enrolledTemp.grade == 99);
            Assert.True(enrolledTemp.rating == 99);
            Assert.Equal("", enrolledTemp.comment);
            Assert.Null(enrolledTemp.course);
            Assert.Null(enrolledTemp.student);
        }
Example #7
0
        public async Task <ActionResult <Enrolled> > PostEnrolled(Enrolled enrolled)
        {
            _context.Enrolleds.Add(enrolled);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEnrolled", new { id = enrolled.Id }, enrolled));
        }
Example #8
0
        public async Task <IActionResult> PutEnrolled(int id, Enrolled enrolled)
        {
            if (id != enrolled.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public void GetGPAMultiple07()
        {
            var db = Utils.MakeMockDatabase();

            var    controller = MakeController(db);
            string uid        = AddOneStudent(db);

            for (int i = 0; i < 10; i++)
            {
                Enrolled newEnrolled = new Enrolled {
                    UId   = uid,
                    CId   = 101 + (uint)i,
                    Grade = "D-"
                };
                db.Enrolled.Add(newEnrolled);
            }

            db.SaveChanges();

            var jsonResults = controller.GetGPA(uid) as JsonResult;

            dynamic resultValues = jsonResults.Value;

            float gpa = Utils.GetValue <float>(resultValues, "gpa");

            Assert.True(MathF.Abs(0.7f - gpa) < 0.01f);
        }
Example #10
0
        /*
         * Stil trying to get this to work... 8/2/18
         *
         * /// <summary>
         * /// Calculates a student's GPA
         * /// A student's GPA is determined by the grade-point representation of the average grade in all their classes.
         * /// If a student does not have a grade in a class ("--"), that class is not counted in the average.
         * /// Otherwise, the point-value of a letter grade for the UofU is determined by the table on this page:
         * /// https://advising.utah.edu/academic-standards/gpa-calculator-new.php
         * /// </summary>
         * /// <param name="uid">The uid of the student</param>
         * /// <returns>A JSON object containing a single field called "gpa" with the number value</returns>
         * public IActionResult GetGPA(string uid)
         * {
         *  using (Team6Context db = new Team6Context())
         *  {
         *      var qcat =
         *          from stud in db.Enrolled
         *          where stud.Student.Equals(uid)
         *          join cl in db.Class
         *          on stud.ClassId equals cl.ClassId
         *          into classes
         *          from cs in classes
         *          join ass in db.Assignment
         *          on cs.ClassId equals ass.Class
         *          into final
         *          from f in final
         *          join cat in db.AssignmentCat
         *          on f.AssignmentCat equals cat.AcatId
         *          into finalfinal
         *          from ff in finalfinal
         *          join co in db.Course
         *          on ff.AcatId equals co.CatId
         *
         *          select new
         *          {
         *              category = co.CatId,
         *              season = cs.Semester,
         *              num = co.Number,
         *              subject = co.Department,
         *              year = cs.Year
         *          };
         *
         *      var allCats = 0;
         *      var numericGradeTotal = 0; //total weighted score for the class
         *
         *      var categories = qcat.ToArray();
         *
         *      foreach (var cat in categories) {
         *          var catTotalPoints = 0;
         *              // query to get assignments for that category
         *          var qasg = from cl in db.Class
         *                      where cl.Semester.Equals(cat.season) && cl.Year == cat.year && cl.CatID == cat.num
         *                      join co in db.Course
         *                      on cl.CatID equals co.CatId
         *                      into classes
         *                      from _cl in classes
         *                      where _cl.Department.Equals(cat.subject)
         *                      join ass_cat in db.AssignmentCat
         *                      on cl.CatID equals ass_cat.Class
         *                      into catset
         *                      from cats in catset
         *                      join asss in db.Assignment
         *                      on cats.AcatId equals asss.AssignmentCat
         *
         *                      select new
         *                      {
         *                          asgns = asss.AssId,
         *                          score = asss.Points
         *                      };
         *
         *              var asgns = qcat.ToArray();
         *              foreach (var asg in asgns) {
         *                  catTotalPoints += asg..Max(); //maximum points possible in the assignment
         *                  var qsub = query.ToArray(); //to get the submission to the specific assignment(gets either 0 or 1 things) for 1 student
         *
         *                  if (qsub.count() == 0)
         *                  {
         *                          catEarned += 0;
         *                  }
         *
         *                  else { catEarned += qsub.first().score }
         *              }
         *
         *              catPercent = (catEarned / catTotalPoints);//percentage of points the student earned in that category
         *              catScore = catPercent * cat.weight;
         *              numericGradeTotal += catScore;
         *              allCats += cat.weight;
         *      }
         *
         *      numericGradeTotal *= (100 / allCats); //rescale category weight into a percentage
         *      return null;
         *  }
         * }
         */

        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}. False if the student is already enrolled in the class.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            var query =
                from cl in db.Class
                where cl.Semester.Equals(season) && cl.Year == year && cl.CatId == num
                join co in db.Course
                on cl.CatId equals co.CatId
                join e in db.Enrolled
                on cl.ClassId equals e.ClassId
                into roll
                from student in roll
                where student.Equals(uid) && co.Department.Equals(subject)

                select new
            {
                Name  = student.StudentId,
                Class = cl.ClassId
            };

            if (query.ToArray().Count() != 0)
            {
                return(Json(new { success = false }));
            }
            else
            {
                // Create a new AssignmentCat object.
                Enrolled e = new Enrolled()
                {
                    StudentId = uid,
                    ClassId   = query.ToArray()[0].Class,
                };

                return(Json(query.ToArray()));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("EnrolledID,StudentID,ClassroomID")] Enrolled enrolled)
        {
            if (id != enrolled.EnrolledID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(enrolled);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EnrolledExists(enrolled.EnrolledID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            PopulateClassroomDropDownList(enrolled.ClassroomID);
            PopulateStudentDropDownList(enrolled.StudentID);
            return(View(enrolled));
        }
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}.
        /// false if the student is already enrolled in the class, true otherwise.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            var classId =
                from c in db.Classes
                where c.Catalog.Num == num
                where c.Catalog.Department == subject
                where c.Semester == (season + " " + year.ToString())
                select new
            {
                c.ClassId
            };

            try
            {
                Enrolled enroll = new Enrolled();
                enroll.UId     = uid;
                enroll.ClassId = classId.FirstOrDefault().ClassId;
                enroll.Grade   = "--";
                db.Enrolled.Add(enroll);
                db.SaveChanges();
                return(Json(new { success = true }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false }));
            }
        }
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}. False if the student is already enrolled in the class.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            using (Team9Context db = new Team9Context())
            {
                //var queryEnrolled =
                //    from s in db.Student
                //    join e in db.Enrolled on s.UId equals e.UId
                //    join cl in db.Class on e.ClassId equals cl.ClassId
                //    join cr in db.Course on cl.CatId equals cr.CatId
                //    where e.UId == uid && cr.CourseNum == num && cl.Season == season && cl.Year == year && cr.DId == subject
                //    select new { uid = e.UId, classID = cl.ClassId };

                var queryEnrolled =
                    from cr in db.Course
                    join cl in db.Class on cr.CatId equals cl.CatId into join1
                    from j1 in join1.DefaultIfEmpty()

                    join e in db.Enrolled on j1.ClassId equals e.ClassId into join3
                    from j3 in join3.DefaultIfEmpty()

                    where cr.CourseNum == num && j1.Season == season && j1.Year == year && cr.DId == subject
                    select new { uid = j3.UId ?? null, classID = j1.ClassId };

                bool uidEnrolled = false;

                for (int i = 0; i < queryEnrolled.Count(); i++)
                {
                    if (queryEnrolled.ToArray()[0].uid == uid)
                    {
                        uidEnrolled = true;
                    }
                }

                if (!uidEnrolled)
                {
                    //insert into enroll, grade, uid, classID
                    Enrolled enroll = new Enrolled();
                    enroll.UId     = uid;
                    enroll.ClassId = queryEnrolled.ToArray()[0].classID;
                    enroll.Grade   = "--";

                    db.Enrolled.Add(enroll);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Problem saving changes: " + e);
                    }

                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false }));
                }
            }
        }
Example #14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Enrolled enrolled = db.Enrolleds.Find(id);

            db.Enrolleds.Remove(enrolled);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #15
0
        /// <summary>
        /// Helper for configuring a database with no assignment categories
        /// </summary>
        /// <returns></returns>
        private Team55LMSContext MakeDatabaseWithOneAssignment()
        {
            var optionsBuilder = new DbContextOptionsBuilder <Team55LMSContext>();

            optionsBuilder.UseInMemoryDatabase("one_assignment").UseApplicationServiceProvider(NewServiceProvider());

            Team55LMSContext db = new Team55LMSContext(optionsBuilder.Options);

            Courses course = new Courses
            {
                CourseId     = 5,
                CourseNumber = 2210,
                Name         = "Calculus III",
                SubjectAbbr  = "MATH"
            };

            Classes calculusIII = new Classes
            {
                CourseId  = 2,
                Location  = "TBA",
                Semester  = "Summer 2020",
                Professor = "u0000010",
                Start     = TimeSpan.Parse("12:25:00"),
                End       = TimeSpan.Parse("13:10:00"),
            };

            Enrolled enr = new Enrolled
            {
                ClassId = calculusIII.ClassId,
                Grade   = "--",
                UId     = "u0000002",
            };

            AssignmentCategories category = new AssignmentCategories
            {
                ClassId = calculusIII.ClassId,
                Name    = "Assignments",
                Weight  = 50,
            };

            Assignments assignment = new Assignments
            {
                AssignCatId = category.AssignCatId,
                Contents    = "Just compute the indefinite integral on problem 2, page 303 :)",
                MaxPoints   = 10,
                Name        = "One Problem",
                DueDate     = DateTime.Parse("12/01/2020 11:59:59"),
            };

            db.Courses.Add(course);
            db.Classes.Add(calculusIII);
            db.Enrolled.Add(enr);
            db.AssignmentCategories.Add(category);
            db.Assignments.Add(assignment);
            db.SaveChanges();

            return(db);
        }
Example #16
0
        /// <summary>
        /// Creates a new assignment for the given class and category.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The new assignment name</param>
        /// <param name="asgpoints">The max point value for the new assignment</param>
        /// <param name="asgdue">The due DateTime for the new assignment</param>
        /// <param name="asgcontents">The contents of the new assignment</param>
        /// <returns>A JSON object containing success = true/false</returns>
        public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents)
        {
            var createAssign = from assignCat in db.AssignmentCategories
                               join classes in db.Classes on assignCat.ClassId equals classes.ClassId
                               join course in db.Courses on classes.CId equals course.CId
                               where course.Listing == subject &&
                               course.Number == num &&
                               classes.Semester.Equals(season + year) &&
                               assignCat.Name == category
                               select new
            {
                assignCat.AcId,
                classes.ClassId
            };
            uint        assignmentCatID = createAssign.First().AcId;
            uint        classesID       = createAssign.First().ClassId;
            Assignments newAssignment   = new Assignments
            {
                AcId     = assignmentCatID,
                Name     = asgname,
                Contents = asgcontents,
                Due      = asgdue,
                Points   = (uint)asgpoints
            };

            db.Assignments.Add(newAssignment);
            db.SaveChanges();

            //Change all student scores
            //Get all Students in that class
            var getAllStudents = (from student in db.Students
                                  join enroll in db.Enrolled on student.UId equals enroll.UId
                                  join classes in db.Classes on enroll.ClassId equals classes.ClassId
                                  where classes.ClassId == classesID
                                  select student).ToList();

            //For each student and knowing which class they are in
            foreach (Students s in getAllStudents)
            {
                //Get their assignmentCategories and compute
                string letterGrade = getStudentScore(s.UId, classesID);
                var    changeGrade = from enroll in db.Enrolled
                                     where enroll.ClassId == classesID &&
                                     s.UId == enroll.UId
                                     select enroll;
                Enrolled grade = changeGrade.SingleOrDefault();
                if (grade != null)
                {
                    grade.Grade = letterGrade;
                }

                db.SaveChanges();
            }

            return(Json(new { success = true }));
        }
 public ActionResult Edit([Bind(Include = "Id,StudentId,ClassId,Grade")] Enrolled enrolled)
 {
     if (ModelState.IsValid)
     {
         db.Entry(enrolled).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(enrolled));
 }
Example #18
0
        public async Task updateEnrollTest(int eid, int sid, int cid, bool c, int g, int r, string co)
        {
            Enrolled newEnroll = new Enrolled {
                enrollId = eid, studentId = sid, courseId = cid, completed = c, grade = g, rating = r, comment = co
            };
            var result = await _controller.updateEnroll(newEnroll);

            Assert.NotNull(result);
            Assert.IsType <OkResult>(result);
        }
Example #19
0
        public async Task <IActionResult> Rate(int eid)
        {
            Enrolled rate = await _enrollSerivce.getEnrollAsync(eid);

            Course course = await _courseService.getCourseAsync(rate.courseId);

            RateCourseViewModel vm = _viewModelSerivce.buildRateCourseViewModel(rate, course);

            return(View(vm));
        }
Example #20
0
        public async Task <IActionResult> Rate(RateCourseViewModel courseRate)
        {
            Enrolled newRating = await _enrollSerivce.getEnrollAsync(courseRate.EnrollId);

            newRating.rating  = courseRate.Rating;
            newRating.comment = courseRate.Comment;
            _enrollSerivce.updateEnroll(newRating);

            return(RedirectToAction("Index", "Home"));
        }
Example #21
0
        /// <summary>
        /// Set the score of an assignment submission
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The name of the assignment</param>
        /// <param name="uid">The uid of the student who's submission is being graded</param>
        /// <param name="score">The new score for the submission</param>
        /// <returns>A JSON object containing success = true/false</returns>
        public IActionResult GradeSubmission(string subject, int num, string season, int year, string category, string asgname, string uid, int score)
        {
            //Get the submission of the student
            var getSubmission = from submit in db.Submission
                                join assign in db.Assignments on submit.AId equals assign.AId
                                join assignCat in db.AssignmentCategories on assign.AcId equals assignCat.AcId
                                join classes in db.Classes on assignCat.ClassId equals classes.ClassId
                                join course in db.Courses on classes.CId equals course.CId
                                where course.Listing == subject &&
                                course.Number == num &&
                                assignCat.Name == category &&
                                classes.Semester.Equals(season + year) &&
                                assign.Name == asgname &&
                                submit.UId == uid
                                select submit;
            Submission changeScore = getSubmission.FirstOrDefault();

            //update the grade of that assignment then change total grade
            if (getSubmission != null)
            {
                changeScore.Score = (uint)score;
            }
            db.SaveChanges();
            //Get the classID
            var getClassID = (from submit in db.Submission
                              join assign in db.Assignments on submit.AId equals assign.AId
                              join assignCat in db.AssignmentCategories on assign.AcId equals assignCat.AcId
                              join classes in db.Classes on assignCat.ClassId equals classes.ClassId
                              join course in db.Courses on classes.CId equals course.CId
                              where course.Listing == subject &&
                              course.Number == num &&
                              assignCat.Name == category &&
                              classes.Semester.Equals(season + year) &&
                              assign.Name == asgname &&
                              submit.UId == uid
                              select new
            {
                assignCat.ClassId
            });
            string letterGrade = getStudentScore(uid, getClassID.First().ClassId);
            var    changeGrade = from enroll in db.Enrolled
                                 where enroll.ClassId == getClassID.First().ClassId&&
                                 uid == enroll.UId
                                 select enroll;
            Enrolled grade = changeGrade.SingleOrDefault();

            if (grade != null)
            {
                grade.Grade = letterGrade;
            }

            db.SaveChanges();

            return(Json(new { success = true }));
        }
Example #22
0
        public async Task <string> postCommentAsync(Enrolled e)
        {
            var data    = JsonConvert.SerializeObject(e);
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            var response = await _client.PostAsync(API_DOMAIN + "/enroll", content);

            var result = await response.Content.ReadAsStringAsync();

            return(result);
        }
Example #23
0
        public static void Enroll(string uid, uint cid, Team41LMSContext db)
        {
            Enrolled newEnrolled = new Enrolled {
                UId   = uid,
                CId   = cid,
                Grade = "--"
            };

            db.Enrolled.Add(newEnrolled);
            db.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "Id,StudentId,ClassId,Grade")] Enrolled enrolled)
        {
            if (ModelState.IsValid)
            {
                db.Enrolleds.Add(enrolled);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(enrolled));
        }
Example #25
0
        public Enrolled drop(int eid)
        {
            Enrolled thisEnroll = _context.Enrolled.Find(eid);

            if (thisEnroll != null)
            {
                _context.Enrolled.Remove(thisEnroll);
                _context.SaveChanges();
            }
            return(thisEnroll);
        }
Example #26
0
        public void validateModelForNULL()
        {
            Course            c     = null;
            Enrolled          e     = null;
            EnrolledViewModel model = new EnrolledViewModel(c, e);

            Assert.True(model.eid == 0);
            Assert.True(model.cid == 0);
            Assert.True(model.cour == null);
            Assert.True(model.enroll == null);
        }
        /// <summary>
        /// This Rejected Reject a Course
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Return Edit View</returns>
        // GET: Admin/Rejected/5
        public ActionResult Rejected(int id)
        {
            Enrolled enrolled = new Enrolled();

            enrolled                 = db.Enrolleds.Find(id);
            enrolled.Request         = "Rejected".ToString();
            db.Entry(enrolled).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Edit"));
        }
Example #28
0
        public async void UpdateEnrollTest_NullEnroll()
        {
            int      enrollNum = -1;
            Enrolled enrolled  = await _enrollService.getEnrollAsync(enrollNum);

            Assert.Null(enrolled);
            //Update the enrolled
            int outcome = _enrollService.updateEnroll(enrolled);

            Assert.True(outcome == 1);
        }
Example #29
0
        /// <summary>
        /// Creates a new assignment for the given class and category.
        /// </summary>
        /// <param name="subject">The course subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester for the class the assignment belongs to</param>
        /// <param name="year">The year part of the semester for the class the assignment belongs to</param>
        /// <param name="category">The name of the assignment category in the class</param>
        /// <param name="asgname">The new assignment name</param>
        /// <param name="asgpoints">The max point value for the new assignment</param>
        /// <param name="asgdue">The due DateTime for the new assignment</param>
        /// <param name="asgcontents">The contents of the new assignment</param>
        /// <returns>A JSON object containing success = true/false</returns>
        public IActionResult CreateAssignment(string subject, int num, string season, int year, string category, string asgname, int asgpoints, DateTime asgdue, string asgcontents)
        {
            var query = from asg in db.Assignments
                        where asgname == asg.Name
                        select asg;

            if (query.Count() > 0 && query.SingleOrDefault() != null)
            {
                return(Json(new { success = false }));
            }

            var query1 = from cr in db.Courses
                         join c in db.Classes on new { A = cr.CatalogId, B = cr.Listing, C = (int)cr.Number, D = season, E = year }
            equals new { A = c.CategoryId, B = subject, C = num, D = (string)splitSem(c.Semester, 0), E = (int)splitSem(c.Semester, 1) } into joined
            from j in joined
            select j;

            var query2 = from q in query1
                         join ac in db.AssignmentCategories on new { A = q.ClassId, B = category } equals new { A = ac.ClassId, B = ac.Name } into joined
            from j in joined.DefaultIfEmpty()
            select j.AssignCatId;

            Assignments a = new Assignments();

            a.AssignCatId = query2.SingleOrDefault();
            a.Name        = asgname;
            a.Points      = (uint)asgpoints;
            a.Due         = asgdue;
            a.Contents    = asgcontents;

            db.Assignments.Add(a);
            db.SaveChanges();


            //Update Grades for all students
            var updateGrades = from e in db.Enrolled
                               where query1.FirstOrDefault().ClassId == e.ClassId
                               select e.UId;

            foreach (string u in updateGrades)
            {
                //Requery for where the students grade is in the enrolled table
                var gradeQuery = from e in db.Enrolled
                                 where e.UId == u && query1.FirstOrDefault().ClassId == e.ClassId
                                 select e;

                Enrolled eObj = gradeQuery.SingleOrDefault();
                eObj.Grade = updateGrade(subject, num, season, year, u);
                db.SaveChanges();     //Resave changes with new grade
            }


            return(Json(new { success = true }));
        }
        /// <summary>
        /// Enrolls a student in a class.
        /// </summary>
        /// <param name="subject">The department subject abbreviation</param>
        /// <param name="num">The course number</param>
        /// <param name="season">The season part of the semester</param>
        /// <param name="year">The year part of the semester</param>
        /// <param name="uid">The uid of the student</param>
        /// <returns>A JSON object containing {success = {true/false}. False if the student is already enrolled in the class.</returns>
        public IActionResult Enroll(string subject, int num, string season, int year, string uid)
        {
            // Check to see if the student is already enrolled
            var query =
                from Co in db.Courses //COURSES to CLASSES
                join Cl in db.Classes on Co.CatalogId equals Cl.Offering into join1

                from j1 in join1 // CLASSES to ENROLLED
                join E in db.Enrolled on j1.ClassId equals E.Class into join2

                from j2 in join2
                where Co.Department == subject && // Ensure correct course department
                Co.Number == num && // Ensure correct course number
                j1.Season == season && // Ensure correct season
                j1.Year == year && // Ensure class year
                j2.Student == uid  // Ensure student is enrolled

                select j2.Student;

            // If the student's already enrolled, return a false success
            if (query.Count() == 1)
            {
                var alreadyRegistered = new { success = false };
                return(Json(alreadyRegistered));
            }

            // If we're here, then student is not currently enrolled in course
            Enrolled new_enr = new Enrolled();

            new_enr.Student = uid;
            var query2 =
                from Co in db.Courses
                where Co.Number == num && Co.Department == subject
                join Cl in db.Classes
                on Co.CatalogId equals Cl.Offering into join1
                from j1 in join1
                where j1.Season == season && j1.Year == year
                select j1.ClassId;

            new_enr.Class = query2.First();
            db.Enrolled.Add(new_enr);
            try
            {
                db.SaveChanges();
                // Registration complete, so return
                var successfullyRegistered = new { success = true };
                return(Json(successfullyRegistered));
            }
            catch // If the changes to the database fail
            {
                return(Json(new { success = false }));
            }
        }