Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "CourseID,CourseName,CourseDescription,IsActive")] Cours cours)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(cours);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cours));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "LessonViewID,UserID,LessonID,DateViewed")] LessonView lessonView)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lessonView).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", lessonView.LessonID);
     ViewBag.UserID   = new SelectList(db.UserDets, "UserID", "FirstName", lessonView.UserID);
     return(View(lessonView));
 }
 public ActionResult Edit([Bind(Include = "CourseCompletionID,UserID,CourseID,DateCompleted")] CourseCompletion courseCompletion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseCompletion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", courseCompletion.CourseID);
     ViewBag.UserID   = new SelectList(db.UserDets, "UserID", "FirstName", courseCompletion.UserID);
     return(View(courseCompletion));
 }
Exemplo n.º 4
0
        public async Task <ActionResult> Create(RegisterViewModel userViewModel, params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = userViewModel.Email, Email = userViewModel.Email
                };
                var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);

                //Add User to the selected Roles
                if (adminresult.Succeeded)
                {
                    #region Dealing with custom user details
                    UserDet newUserDeets = new UserDet();
                    newUserDeets.UserID              = user.Id;
                    newUserDeets.FirstName           = userViewModel.FirstName;
                    newUserDeets.LastName            = userViewModel.LastName;
                    newUserDeets.DateStarted         = userViewModel.DateStarted;
                    newUserDeets.IsEmployedCurrently = userViewModel.IsEmployedCurrently;


                    CoffeeShopLMSEntities db = new CoffeeShopLMSEntities();
                    db.UserDets.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion

                    if (selectedRoles != null)
                    {
                        var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);

                        if (!result.Succeeded)
                        {
                            ModelState.AddModelError("", result.Errors.First());
                            ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
                            return(View());
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
                    return(View());
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
            return(View());
        }
Exemplo n.º 5
0
        // GET: Lessons/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Lesson     lesson     = db.Lessons.Find(id);
            LessonView lessonView = new LessonView();

            lessonView.LessonID = (int)id;
            lessonView.UserID   = User.Identity.GetUserId();
            DateTime today = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

            lessonView.DateViewed = today;

            LessonView entryHasBeenEnteredBefore = db.LessonViews
                                                   .Where(x => x.LessonID == lessonView.LessonID && x.UserID == lessonView.UserID)
                                                   .FirstOrDefault();

            if (entryHasBeenEnteredBefore == null)
            {
                db.LessonViews.Add(lessonView);
                db.SaveChanges();
            }


            //if the rest of the course is done
            Lesson        lessonThatWasViewed        = db.Lessons.Where(x => x.LessonID == lessonView.LessonID).FirstOrDefault();
            int           numberOfLessonsInTheCourse = db.Lessons.Where(x => x.CourseID == lessonThatWasViewed.CourseID).Count();
            var           lessonsInTheCourse         = db.Lessons.Where(x => x.CourseID == lessonThatWasViewed.CourseID);
            List <Lesson> lessonsInLessonViews       = new List <Lesson>();

            foreach (var l in db.LessonViews.Where(x => x.UserID == lessonView.UserID))
            {
                var lessonViewedInThisLessonView = db.Lessons.Where(x => x.LessonID == l.LessonID).FirstOrDefault();
                if (lessonsInTheCourse.Where(x => x.LessonID == l.LessonID).FirstOrDefault() != null)
                {
                    lessonsInLessonViews.Add(lessonViewedInThisLessonView);
                }
            }

            UserDet employeeViewing     = db.UserDets.Where(x => x.UserID == lessonView.UserID).FirstOrDefault();
            Cours   courseViewed        = db.Courses.Where(x => x.CourseID == lessonThatWasViewed.CourseID).FirstOrDefault();
            string  confirmationMessage = $"{employeeViewing.FirstName} {employeeViewing.LastName} has finished course {courseViewed.CourseName}";

            if (numberOfLessonsInTheCourse == lessonsInLessonViews.Count)
            {
                //string courseFinishMessage = $"Employee {lessonView.UserID} has finished a course.";

                CourseCompletion courseCompletion = new CourseCompletion();
                courseCompletion.CourseID      = courseViewed.CourseID;
                courseCompletion.UserID        = User.Identity.GetUserId();
                courseCompletion.DateCompleted = today;



                CourseCompletion courseHasBeenCompletedBefore = db.CourseCompletions.Where(x => x.CourseID == courseCompletion.CourseID).Where(x => x.UserID == courseCompletion.UserID).FirstOrDefault();
                if (courseHasBeenCompletedBefore == null)
                {
                    db.CourseCompletions.Add(courseCompletion);
                    db.SaveChanges();

                    MailMessage m = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "Course Completion",
                        confirmationMessage);
                    m.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient("mail.abigaylewillis.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "@1001w");
                    client.Port        = 8889;
                    client.Send(m);
                }
            }

            if (lesson == null)
            {
                return(HttpNotFound());
            }
            return(View(lesson));
        }