Exemplo n.º 1
0
        public PartialViewResult GetCourseDetails(int courseId)
        {
            var dalHelper              = new DalHelper();
            var courseDetails          = dalHelper.GetCourseDetails(courseId);
            var courseDetailsViewModel = new CoursesDetailsViewModel
            {
                CourseTitle   = courseDetails.Course.CourseName,
                StartTime     = courseDetails.Course.CourseStartTime.ToString(),
                EndTime       = courseDetails.Course.CourseEndTime.ToString(),
                BeforeCheckIn = courseDetails.Course.CheckInStartTime,
                AfterCheckIn  = courseDetails.Course.CheckInEndTime
            };

            var students = new List <Student>();

            courseDetails.TotalUsers.ForEach(c => students.Add(new Student
            {
                Id       = c.Id,
                Name     = $"{c.FirstName} {c.LastName}",
                Selected = false
            }));

            foreach (var user in courseDetails.CourseUsers)
            {
                var firstOrDefault = students.FirstOrDefault(c => c.Id == user.Id);
                if (firstOrDefault != null)
                {
                    firstOrDefault.Selected = true;
                }
            }

            courseDetailsViewModel.Students = students;

            return(PartialView("CourseDetails", courseDetailsViewModel));
        }
Exemplo n.º 2
0
        public JsonResult SaveCourseDetails(CoursesDetailsViewModel model)
        {
            var dalHelper = new DalHelper();
            var result    = dalHelper.UpdateCourseDetals(model);

            return(result.HasError
                ? Json(new { Message = "Save Failed" }, JsonRequestBehavior.AllowGet)
                : Json(new { Message = "Saved" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public Result UpdateCourseDetals(CoursesDetailsViewModel model)
        {
            try
            {
                using (var context = new AttendanceDataContext())
                {
                    var course = context.Courses.FirstOrDefault(c => c.Id == model.CourseId);
                    if (course == null)
                    {
                        throw new InvalidOperationException("Course is not found");
                    }

                    course.CheckInStartTime = model.BeforeCheckIn;
                    course.CheckInEndTime   = model.AfterCheckIn;

                    foreach (var student in model.Students)
                    {
                        var currentUserCourse =
                            context.UserCourses.FirstOrDefault(
                                c => c.CourseId == model.CourseId && c.UserId == student.Id);
                        if (student.Selected)
                        {
                            if (currentUserCourse == null)
                            {
                                context.UserCourses.InsertOnSubmit(new UserCourse
                                {
                                    CourseId = model.CourseId,
                                    UserId   = student.Id,
                                    Created  = DateTime.Now
                                });
                            }
                        }
                        else
                        {
                            if (currentUserCourse != null)
                            {
                                context.UserCourses.DeleteOnSubmit(currentUserCourse);
                            }
                        }
                    }

                    context.SubmitChanges();

                    return(new Result());
                }
            }
            catch (Exception)
            {
                return(new Result(HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Details(int courseId)
        {
            var course = await this.courseService.GetCourseByIdAsync(courseId);

            var model = new CoursesDetailsViewModel
            {
                Course = course
            };

            if (model.Course == null)
            {
                return(NotFound());
            }

            if (User.Identity.IsAuthenticated)
            {
                var studentUserId = this.userManager.GetUserId(User);

                model.UserIsEnrolledCourse = await this.enrolledService.StudentIsEnrolledInCourseAsync(studentUserId, courseId);
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public IActionResult Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CoursesDetailsViewModel vm = new CoursesDetailsViewModel();

            Course course = coursesClient.Get(id);

            vm.Course = course;

            vm.Modules = new List <Module>();

            foreach (int modelID in course.Modules)
            {
                Module temp = moduleClient.Get(modelID.ToString());
                vm.Modules.Add(temp);
            }

            return(View(vm));
        }