Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "CourseId,CourseName,CourseDescription,IsActive")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses1.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(course));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,Company")] UserDetail userDetail)
        {
            if (ModelState.IsValid)
            {
                db.UserDetails.Add(userDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", userDetail.UserId);
            return(View(userDetail));
        }
        public ActionResult Create([Bind(Include = "CourseCompletionId,UserId,CourseId,DateCompleted")] CourseCompletion courseCompletion)
        {
            if (ModelState.IsValid)
            {
                db.CourseCompletions.Add(courseCompletion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId = new SelectList(db.Courses1, "CourseId", "CourseName", courseCompletion.CourseId);
            ViewBag.UserId   = new SelectList(db.UserDetails, "UserId", "FirstName", courseCompletion.UserId);
            return(View(courseCompletion));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //ViewBag.Link = callbackUrl;
                    //return View("DisplayEmail");

                    //Adding UserDetails record & sending user to Log in
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserId    = user.Id;//use ASPNet record's PK for our UserDetails PK
                    newUserDeets.FirstName = model.FirstName;
                    newUserDeets.LastName  = model.LastName;
                    UserManager.AddToRole(user.Id, "Employee");

                    TrinityLMSEntities db = new TrinityLMSEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();

                    return(View("Login"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo 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);

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

            #region Lesson Views
            UserDetail        currentUserId = db.UserDetails.Find(User.Identity.GetUserId());
            List <LessonView> thisUserViews = db.LessonViews.Where(lv => lv.UserId == currentUserId.UserId).ToList();
            int viewsForLesson = thisUserViews.Where(lv => lv.LessonId == lesson.LessonId).Count();

            if (viewsForLesson < 1)
            {
                LessonView lessonView = new LessonView();//Create a new lesson object when user lands on Details view
                lessonView.LessonId   = id;
                lessonView.UserId     = currentUserId.UserId;
                lessonView.DateViewed = DateTime.Now;

                db.LessonViews.Add(lessonView);//Save the new "Lesson View" object into database
                db.SaveChanges();


                int lessonPerCourse = db.Lessons.Where(l => l.CourseId == lesson.CourseId).Count();
                int lessonViewCount = db.LessonViews.Where(l => l.UserId == currentUserId.UserId && l.Lesson.CourseId == lesson.CourseId).Count();



                if (lessonPerCourse == lessonViewCount)
                {
                    CourseCompletion courseComplete = new CourseCompletion();
                    courseComplete.CourseId      = lesson.CourseId;
                    courseComplete.UserId        = currentUserId.UserId;
                    courseComplete.DateCompleted = DateTime.Now;
                    db.CourseCompletions.Add(courseComplete);
                    db.SaveChanges();

                    string body = string.Format($"A course has been completed by an employee.<br/> Employee I.D.: {courseComplete.UserId} </br> Course I.D.: {courseComplete.CourseId} </br> Completion Date: {courseComplete.DateCompleted} ");

                    MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "Course Completion", body);
                    msg.IsBodyHtml = true;
                    msg.Priority   = MailPriority.High;

                    SmtpClient client = new SmtpClient("mail.devinsprecker.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "Jesusroseday3");

                    client.Send(msg);
                }
            }
            ;



            #endregion



            return(View(lesson));
        }