public Course create(Course entity)
 {
     if (entity != null)
     {
         context.Courses.Add(entity);
         context.SaveChanges();
         return(entity);
     }
     return(entity);
 }
Пример #2
0
 public AreaOfInterest create(AreaOfInterest entity)
 {
     if (entity != null)
     {
         context.AreaOfInterests.Add(entity);
         context.SaveChanges();
         return(entity);
     }
     return(entity);
 }
 public Trainer create(Trainer entity)
 {
     if (entity != null)
     {
         context.Trainers.Add(entity);
         context.SaveChanges();
         return(entity);
     }
     return(entity);
 }
 public Student create(Student entity)
 {
     if (entity != null)
     {
         context.Students.Add(entity);
         context.SaveChanges();
         return(entity);
     }
     return(entity);
 }
Пример #5
0
        public ActionResult EnrollIntoCourse(int course_id, int student_id)
        {
            //prepare object for making an entry in database
            StudentCourse cs = new StudentCourse();

            cs.CourseId    = context.Courses.Where(e => e.CourseRowId == course_id).FirstOrDefault();
            cs.StudentId   = context.Students.Where(e => e.StudentRowId == student_id).FirstOrDefault();
            cs.isCompleted = false;

            //check if student has already enrolled in the same course
            List <StudentCourse> temp  = context.StudentCourses.Where(e => e.StudentId.StudentRowId == student_id).ToList();
            StudentCourse        temp2 = temp.Where(e => e.CourseId.CourseRowId == course_id).FirstOrDefault();

            if (temp2 == null)
            {
                //create row in database
                //studentCourseRepo.create(cs);
                context.StudentCourses.Add(cs);
                context.SaveChanges();
            }


            return(RedirectToAction("Index", "Home"));
        }
Пример #6
0
        public async Task <ActionResult> Index()
        {
            //Check for initial RUN
            if (appdbContext.Users.Count() == 0)
            {
                //make new roles for Administrator, Trainer, Student
                IdentityRole adminrole = new IdentityRole()
                {
                    Name = "Administrator"
                };
                IdentityRole trainerrole = new IdentityRole()
                {
                    Name = "Trainer"
                };
                IdentityRole studentrole = new IdentityRole()
                {
                    Name = "Student"
                };

                appdbContext.Roles.Add(adminrole);
                appdbContext.Roles.Add(trainerrole);
                appdbContext.Roles.Add(studentrole);
                appdbContext.SaveChanges();

                //make Default Area of interest entry as "Computer Science"
                AreaOfInterest aoi = new AreaOfInterest()
                {
                    Name = "Computer Science"
                };
                context.AreaOfInterests.Add(aoi);
                context.SaveChanges();

                //register new user Administrator
                RegisterViewModel model = new RegisterViewModel();
                model.Email           = "*****@*****.**";
                model.Password        = "******";
                model.ConfirmPassword = "******";
                string Role = "Administrator";

                ApplicationUser user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                var res = await UserManager.CreateAsync(user, model.Password);

                //assign administrator user to Administrator role
                UserManager.AddToRole(user.Id, Role);
            }



            //get all courses and show courses
            var result = courseRepo.getData();

            //store logged in user data in viewbag
            if (User != null && User.IsInRole("Student"))
            {
                string  userId = User.Identity.GetUserId();
                Student user   = context.Students.Where(e => e.UserId == userId).FirstOrDefault();
                ViewBag.loggedInUser = user.StudentRowId;
            }

            return(View(result));
        }