示例#1
0
        public LessonPresenter(LessonModel model, LessonView view)
        {
            this.lesson = model;
            this.view   = view;

            view.presenter = this;
        }
示例#2
0
        public IHttpActionResult AddView(LikeViewRequest userInput)
        {
            Device device = _unitOfWork.Devices.GetSingle(x => x.DeviceToken == userInput.DeviceToken);

            LessonView view = _unitOfWork.Views.GetSingle(x => x.LessonId == userInput.LessonId && x.DeviceId == device.Id);

            if (view == null)
            {
                var addingView = LessonViewServices.AddView(userInput.LessonId, device.Id);
                _unitOfWork.Views.Add(addingView);
                _unitOfWork.Complete();
            }
            else
            {
                DateTime recentTime = DateTime.Now;
                DateTime lastTime   = view.LastView;

                if (recentTime.Subtract(lastTime).TotalMinutes > 120)
                {
                    view.LastView  = recentTime;
                    view.TotalView = view.TotalView + 1;

                    _unitOfWork.Complete();
                }
            }

            return(Ok());
        }
示例#3
0
        // GET: LessonViews/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string     currentUserID = User.Identity.GetUserId();
            LessonView lessonView    = db.LessonViews.Find(id);

            if (lessonView == null)
            {
                return(HttpNotFound());
            }
            else
            {
                if (User.IsInRole("Parent") || User.IsInRole("Admin") || lessonView.UserID == currentUserID)
                {
                    return(View(lessonView));
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
            }
        }
示例#4
0
        public ActionResult DeleteConfirmed(int id)
        {
            LessonView lessonView = db.LessonViews.Find(id);

            db.LessonViews.Remove(lessonView);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 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);
     return(View(lessonView));
 }
 public ActionResult Edit([Bind(Include = "LessonViewId,EmpId,LessonId,DateViewed")] LessonView lessonView)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lessonView).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EmpId    = new SelectList(db.EmpDetails, "EmpId", "FirstName", lessonView.EmpId);
     ViewBag.LessonId = new SelectList(db.Lessons, "LessonId", "LessonTitle", lessonView.LessonId);
     return(View(lessonView));
 }
        public ActionResult Create([Bind(Include = "LessonViewID,UserID,LessonID,DateViewed")] LessonView lessonView)
        {
            if (ModelState.IsValid)
            {
                db.LessonViews.Add(lessonView);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", lessonView.LessonID);
            return(View(lessonView));
        }
        /// <summary>
        /// Loads the plant node and links the I/O Table
        /// </summary>
        private ProcessingData InitialisePlant(ILessonEntity openedLesson)
        {
            _lessonView = GetNode <LessonView>("HscRelative/LessonView");
            _lessonView.LoadAndShowInfo(openedLesson);
            _loadedSimulationNode = _lessonView.PlantView.LoadedSimulationNode;
            ProcessingData data = new ProcessingData
            {
                InputRegisters  = new StateTable(_loadedSimulationNode.SimulationOutput),
                OutputRegisters = new StateTable(_loadedSimulationNode.SimulationInput)
            };

            return(data);
        }
示例#9
0
        public ActionResult Create([Bind(Include = "LessonViewId,UserId,LessonId,DateViewed")] LessonView lessonView)
        {
            if (ModelState.IsValid)
            {
                db.LessonViews.Add(lessonView);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LessonId = new SelectList(db.Lessons, "LessonId", "LessonTitle", lessonView.LessonId);
            ViewBag.UserId   = new SelectList(db.UserDetails, "UserId", "FirstName", lessonView.UserId);
            return(View(lessonView));
        }
示例#10
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LessonView lessonView = db.LessonViews.Find(id);

            if (lessonView == null)
            {
                return(HttpNotFound());
            }
            return(View(lessonView));
        }
        // GET: LessonViews/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LessonView lessonView = db.LessonViews.Find(id);

            if (lessonView == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", lessonView.LessonID);
            return(View(lessonView));
        }
示例#12
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            /**model**/
            LessonModel modellesson = new LessonModel();


            /**view***/
            LessonView viewlesson = new LessonView();
            WordView   word       = new WordView();
            /**presenter**/
            LessonPresenter presenterlesson = new LessonPresenter(modellesson, viewlesson);

            Application.Run(viewlesson);
        }
        /// <summary>
        /// Initializes the whole page. Called before the node is added to the tree by the lesson controller.
        /// </summary>
        public override void InitialiseWith(IMainNode mainNode, ILessonEntity openedLesson)
        {
            MainNode     = mainNode;
            OpenedLesson = openedLesson;
            LessonView   = GetNode <LessonView>(LessonViewPath);
            LessonView.LoadAndShowInfo(openedLesson);
            Sfc2dEditorNode = GetNode <Sfc2dEditorNode>(Sfc2dEditorPath);
            HelpPage        = GetNode <HelpPage>(EditorHelpPath);
            ProcessingData data = new ProcessingData
            {
                InputRegisters  = new StateTable(LessonView.PlantView.LoadedSimulationNode.SimulationOutput),
                OutputRegisters = new StateTable(LessonView.PlantView.LoadedSimulationNode.SimulationInput)
            };

            Sfc2dEditorNode.InitializeEditor(data, true);
            TryLoadDiagram();
        }
示例#14
0
        public ActionResult SystemCreate(int lessonId, string userId)
        {
            LessonView newLV = new LessonView();

            newLV.LessonId   = lessonId;
            newLV.UserId     = userId;
            newLV.DateViewed = DateTime.Now;
            string lessonName = db.Lessons.Where(l => l.LessonId == lessonId).Select(l => l.LessonTitle).FirstOrDefault();

            db.LessionViews.Add(newLV);
            db.SaveChanges();
            db.Entry(newLV).GetDatabaseValues();
            TempData["Confirmation"] = $"{lessonName} has been Completed!";
            int courseId            = db.Lessons.Where(l => l.LessonId == lessonId).Select(l => l.CourseId).FirstOrDefault();
            int lessonCompleteCount = db.LessionViews.Where(lv => lv.Lesson.CourseId == courseId).Count();

            if (lessonCompleteCount == 6)
            {
                CourseCompletion newComplete = new CourseCompletion();
                newComplete.UserId        = userId;
                newComplete.CourseId      = courseId;
                newComplete.DateCompleted = DateTime.Now;
                db.CourseCompletions.Add(newComplete);
                db.SaveChanges();
                string courseName = db.Courses.Where(c => c.CourseId == courseId).Select(c => c.CourseName).FirstOrDefault();
                TempData["CourseConfirmation"] = $"{courseName} has been Completed!";
                string      name         = db.UserDetails.Where(u => u.UserId == userId).FirstOrDefault().FullName;
                string      message      = $"Your employee {name} has completed {courseName} on {newComplete.DateCompleted:d}";
                string      managerEmail = "*****@*****.**";
                string      admin        = "*****@*****.**";
                MailMessage mm           = new MailMessage(admin, managerEmail, $"Course Completed - {name}", message);
                SmtpClient  client       = new SmtpClient("mail.ryanmichaelmartin.com");
                client.Credentials = new NetworkCredential(admin, "Snake19(");
                try
                {
                    client.Send(mm);
                }
                catch (Exception e)
                {
                    TempData["CourseConfirmation"] = $"Completion email failed to send. Please contact your administrator. <br /> Error Message: <br /> {e.StackTrace}";
                    return(RedirectToAction("Index", "Courses"));
                }
            }
            return(RedirectToAction("Index", "Courses"));
        }
示例#15
0
        // GET: Lesson/Details/5
        public ActionResult Details(string token, string courseId, string lessonName)
        {
            string username = AuthLogic.CheckToken(token);

            if (username == "")
            {
                throw new Exception("NotAuthorized");
            }
            ViewData["token"] = token;

            var course = Course.GetCourse(courseId);

            if (username == course.ModelCourse.Author)
            {
                ViewData["isAuthor"] = true;
            }
            else
            {
                ViewData["isAuthor"] = false;
            }

            var lessonView = new LessonView();

            foreach (var courseLesson in course.ModelCourse.Lessons)
            {
                if (courseLesson.Name == lessonName)
                {
                    lessonView = LessonView.CastFromLesson(courseLesson, courseId);
                    break;
                }
            }
            if (lessonView.Words == null)
            {
                lessonView.Words = new List <WordView>();
            }

            // For now there are only generic tests; later there might be lesson-specific tests,
            // so those will be included here as well...)
            var bllQuizzes = Quiz.GetAllGenericQuizzes();

            lessonView.Quiz = QuizView.CastFromBllQuiz(bllQuizzes);

            return(View(lessonView));
        }
示例#16
0
        public async Task <IActionResult> Post([FromBody] LessonView item)
        {
            //Console.WriteLine("Запрос добавления урока: " + item.lesson.Name + " п " + item.nameClass);
            if (ModelState.IsValid)
            {
                Class bufferClass = await _timeTable.GetClassAsync(item.nameClass);

                Teacher bufferTeacher = await _timeTable.GetTeacherAsync(item.nameTeacher);

                Lesson buffer = new Lesson
                {
                    Name    = item.lesson.Name,
                    Day     = item.lesson.Day,
                    Number  = item.lesson.Number,
                    Class   = bufferClass,
                    Teacher = bufferTeacher
                };
                await _timeTable.AddLessonAsync(buffer);

                return(Json(buffer));
            }
            return(BadRequest("Ошибка валидации!"));
        }
示例#17
0
        public ActionResult Completed(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Lesson lesson = db.Lessons.Find(id);

            if (lesson == null)
            {
                return(HttpNotFound());
            }
            string userId = User.Identity.GetUserId();

            if (lesson.LessonViews.Where(x => x.LessonId == lesson.LessonId && userId == x.UserId).Count() > 0)
            {
                TempData["AlreadyCompletedMessage"] = "This lesson has already been completed, please do not attempt to resubmit!";
                return(RedirectToAction("Details", new { id }));
            }


            LessonView lessonView = new LessonView
            {
                UserId     = User.Identity.GetUserId(),
                LessonId   = lesson.LessonId,
                DateViewed = DateTime.Now
            };

            db.LessonViews.Add(lessonView);
            db.SaveChanges();

            var howManyLessonsinCourse = (from howManyLesson in db.Lessons
                                          where howManyLesson.CourseId == lesson.CourseId
                                          select howManyLesson).ToList();

            var howManyLessonsinCourseCount = howManyLessonsinCourse.Count();

            var howManyCompletedLessonsInCourseForUser = (from completed in db.LessonViews
                                                          where completed.LessonId == completed.Lesson.LessonId && completed.Lesson.CourseId == lesson.CourseId && userId == completed.UserId
                                                          select completed).ToList();

            var howManyCompletedLessonsInCourseForUserCount = howManyCompletedLessonsInCourseForUser.Count();


            if (howManyLessonsinCourseCount == howManyCompletedLessonsInCourseForUserCount)
            {
                CourseCompletion courseCompletion = new CourseCompletion
                {
                    UserId        = userId,
                    CourseId      = lesson.CourseId,
                    DateCompleted = DateTime.Now
                };

                db.CourseCompletions.Add(courseCompletion);
                db.SaveChanges();

                UserDetail employeeThatCompleted = db.UserDetails.Find(userId);

                if (employeeThatCompleted.ReportsTo != null)
                {
                    var manager = db.AspNetUsers.Find(employeeThatCompleted.ReportsTo);

                    //Message to send to me
                    string message = $"<strong>{employeeThatCompleted.FirstName} {employeeThatCompleted.LastName}</strong> has completed <strong>{lesson.Course.CourseName}</strong> on <strong>{courseCompletion.DateCompleted:f}</strong>";

                    #region setup mail message
                    //Setup Mail Message
                    MailMessage mm = new MailMessage(
                        "XXXX",
                        manager.Email,    //the email is dynamic to the manager details, I added my email as the managers in the DB so that I can check it.
                        "Course Completed Alert",
                        message
                        );

                    mm.IsBodyHtml = true;
                    mm.Priority   = MailPriority.High;
                    mm.ReplyToList.Add(User.Identity.GetUserName());
                    SmtpClient client = new SmtpClient("XXXX");
                    client.Credentials = new NetworkCredential("XXXX", "XXXX");
                    client.Port        = 8889;
                    #endregion

                    //Try to send email
                    try
                    {
                        client.Send(mm);
                    }
                    catch (Exception ex)
                    {
                        return(RedirectToAction("Index", "Course"));
                    }
                }

                return(RedirectToAction("Index", "Course"));//TODO: Maybe make a congrats course finished page?
            }

            List <int> allLessonsInCourseId  = new List <int>();
            List <int> numCompletedforUserId = new List <int>();

            foreach (var allLessonsInCourse in howManyLessonsinCourse)
            {
                allLessonsInCourseId.Add(allLessonsInCourse.LessonId);
            }
            foreach (var numCompletedforUser in howManyCompletedLessonsInCourseForUser)
            {
                numCompletedforUserId.Add(numCompletedforUser.LessonId);
            }

            var nextLessonId = allLessonsInCourseId.Where(x => numCompletedforUserId.All(y => x != y));

            return(RedirectToAction("Details", new { id = nextLessonId.FirstOrDefault() }));
        }
示例#18
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());
            }

            string userid = User.Identity.GetUserId();

            if (User.IsInRole("Employee"))
            {
                if (db.LessonViews.Where(lv => lv.UserID == userid && lv.LessonID == id).Count() == 0)
                {
                    LessonView newLessonView = new LessonView();
                    newLessonView.DateViewed = DateTime.Now;
                    newLessonView.UserID     = User.Identity.GetUserId();
                    newLessonView.LessonID   = (int)id;

                    db.LessonViews.Add(newLessonView);
                }
                else
                {
                    LessonView updateLessonView = db.LessonViews.Where(lv => lv.UserID == userid && lv.LessonID == id).Single();
                    updateLessonView.DateViewed = DateTime.Now;

                    db.Entry(updateLessonView).State = EntityState.Modified;
                }
                db.SaveChanges();
                if (db.Lessons.Where(l => l.CourseID == lesson.CourseID).Count() == db.LessonViews.Include(lv => lv.Lesson).Where(lv => lv.UserID == userid && lv.Lesson.CourseID == lesson.CourseID).Count())
                {
                    if (db.CourseCompletions.Where(cc => cc.UserID == userid && cc.CourseID == lesson.CourseID).Count() == 0)
                    {
                        CourseCompletion newCourseCompletion = new CourseCompletion();
                        newCourseCompletion.UserID        = User.Identity.GetUserId();
                        newCourseCompletion.CourseID      = lesson.CourseID;
                        newCourseCompletion.DateCompleted = DateTime.Now;

                        db.CourseCompletions.Add(newCourseCompletion);
                    }
                    else
                    {
                        CourseCompletion updateCourseCompletion = db.CourseCompletions.Where(cc => cc.UserID == userid && cc.CourseID == lesson.CourseID).Single();
                        Course           course = db.Courses.Find(lesson.CourseID);
                        DateTime         exp    = updateCourseCompletion.DateCompleted.AddYears(course.ValidFor).AddMonths(-1);
                        if (db.LessonViews.Where(lv => lv.DateViewed >= exp &&
                                                 lv.UserID == userid && lv.Lesson.CourseID == lesson.CourseID).Count() == db.Lessons.Where(l => l.CourseID == lesson.CourseID).Count())
                        {
                            updateCourseCompletion.DateCompleted   = DateTime.Now;
                            db.Entry(updateCourseCompletion).State = EntityState.Modified;
                        }
                    }

                    Employee e = db.Employees.Find(userid);

                    var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    var user        = UserManager.FindById(e.ManagerID);

                    string body = $"{e.FirstName} {e.LastName} has completed the course {lesson.Course.CourseName} as of {DateTime.Now:MM/dd/yyyy}.";

                    MailMessage msg = new MailMessage("*****@*****.**",
                                                      user.Email,
                                                      "Email from Agency - " + e.FirstName + " " + e.LastName + " completed a course.",
                                                      body);

                    SmtpClient client = new SmtpClient("mail.jdbaker.net");
                    client.Credentials = new NetworkCredential("*****@*****.**", "EMAIL PASSWORD HERE");

                    using (client)
                    {
                        client.Send(msg);
                    }
                    db.SaveChanges();
                }
            }

            return(View(lesson));
        }
示例#19
0
        // GET: Lessons/Details/5
        public ActionResult Details(int?id, bool?completed)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Lesson lesson = db.Lessons.Find(id);

            if (lesson == null)
            {
                return(HttpNotFound());
            }
            if (lesson.VideoURL != null)
            {
                var    v   = lesson.VideoURL.IndexOf("v=");
                var    amp = lesson.VideoURL.IndexOf("&", v);
                string vid;
                //if the video id is the last value in the url
                if (amp == -1)
                {
                    vid = lesson.VideoURL.Substring(v + 2);
                    // if there are other parameters after the video id in the url
                }
                else
                {
                    vid = lesson.VideoURL.Substring(v + 2, amp - (v + 2));
                }
                ViewBag.VideoID = vid;
            }

            if (User.IsInRole("Employee") && completed == true)
            {
                LessonView viewed = new LessonView
                {
                    UserID     = User.Identity.GetUserId(),
                    DateViewed = DateTime.Now,
                    LessonID   = (int)id
                };
                db.LessonViews.Add(viewed);
                db.SaveChanges();
                //if(db.LessonViews.Where(l => l.UserID == viewed.UserID && l.Lesson.CourseID == lesson.CourseID).Count() == db.Lessons.Where(l => l.CourseID == lesson.CourseID).Count())
                //{
                //    CourseCompletion comp = new CourseCompletion
                //    {
                //        Userid = User.Identity.GetUserId(),
                //        DateCompleted = DateTime.Now,
                //        CourseID = lesson.CourseID
                //    };

                //    db.CourseCompletions.Add(comp);
                //    db.SaveChanges();
                //}
                if (db.LessonViews.Where(l => l.UserID == viewed.UserID && l.Lesson.CourseID == lesson.CourseID).Count() == db.Lessons.Where(l => l.CourseID == lesson.CourseID).Count())
                {
                    CourseCompletion comp = new CourseCompletion
                    {
                        Userid        = User.Identity.GetUserId(),
                        DateCompleted = DateTime.Now,
                        CourseID      = lesson.CourseID
                    };
                    db.CourseCompletions.Add(comp);
                    db.SaveChanges();

                    // 1) Build the email message body (content for the email)
                    string message = $"A course has been completed, check course completion page for updated information.<br>" +
                                     $"";

                    // 2) Create the MailMessage object, and customize
                    MailMessage msg = new MailMessage(
                        //FROM - your domain email ([email protected])
                        "*****@*****.**",
                        //TO - where the email lands (should be sent to your personal email)
                        "*****@*****.**",
                        //subject
                        "Completed Course",
                        //Body
                        message
                        );

                    //allow HTML formatting
                    msg.IsBodyHtml = true;
                    msg.Priority   = MailPriority.Normal; //cna change priority
                                                          //CC  or BCC other recipients


                    // 3) Create the SmtpClient that will send the email.
                    //the client will need info from the host to route the email
                    SmtpClient client = new SmtpClient("mail.TheWongpage.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "Smokes#1");


                    // 4) Attempt sending email.
                    try
                    {
                        client.Send(msg);
                    }
                    catch (Exception ex)
                    {
                        ViewBag.ErrorMessage = $"Sorry, something went wrong. Pelase try again later or review the stacktrace <br>{ex.StackTrace}";
                        return(View());
                    }

                    //if the email gets send, we will send the user to a confirmation view.
                    return(RedirectToAction("TileView", "Cours"));
                }
                ;

                return(RedirectToAction("Index", new { id = lesson.CourseID }));
            }

            return(View(lesson));
        }
示例#20
0
 public JsonResult LessonViewsCreate(LessonView lessonview)
 {
     db.LessonViews.Add(lessonview);
     db.SaveChanges();
     return(Json(lessonview));
 }
示例#21
0
        public ActionResult Create([Bind(Include = "LessonViewID,UserID,LessonID,DateViewed")] LessonView lessonView)
        {
            lessonView.UserID = User.Identity.GetUserId();
            if (ModelState.IsValid)
            {   //the current lessonviews courseID
                var currentCourseID = (from l in db.Lessons
                                       join c in db.Courses on l.CourseID equals c.CourseID
                                       where l.LessonID == lessonView.LessonID
                                       select c.CourseID).FirstOrDefault();
                //list of lession views for the current user
                var curUser = User.Identity.GetUserId();
                var userLVs = (from LV in db.LessonViews
                               where LV.UserID == curUser
                               select LV).ToList();

                db.LessonViews.Add(lessonView);
                db.SaveChanges();
                //count the number of lessonviews with this current courseID
                var countLVsInCourse = userLVs.Where(x => x.Lesson.CourseID == currentCourseID).Count();
                if (countLVsInCourse >= 2)
                {
                    //this is where we create the CourseCompletion
                    //based on that courseID and the current userID
                    CourseCompletion courseCompletion = new CourseCompletion();
                    courseCompletion.UserID        = curUser;
                    courseCompletion.CourseID      = currentCourseID;
                    courseCompletion.DateCompleted = DateTime.Now;
                    db.CourseCompletions.Add(courseCompletion);
                    db.SaveChanges();
                    //send an email to that persons manager..
                    var curUserNameFirst = db.Employees.Where(x => x.UserID == curUser).Select(x => x.FirstName).ToString();
                    var curUserNameLast  = db.Employees.Where(x => x.UserID == curUser).Select(x => x.LastName).ToString();
                    var curEmp           = db.Employees.Where(x => x.UserID == curUser).FirstOrDefault();

                    string      body = string.Format($"Name:{curEmp.FullName} , <br />Has Completed Course {currentCourseID}<br /> Completion Time: {courseCompletion.DateCompleted} <br />");
                    MailMessage msg  = new MailMessage("*****@*****.**",
                                                       "*****@*****.**",
                                                       "Course Completion Alert",
                                                       body);

                    msg.IsBodyHtml = true; //body of the message is HTML
                                           //msg.cc.Add("*****@*****.**");  sends a carbon copy
                                           //msg.Bcc.Add("*****@*****.**"); //send a blind carbon copy so that no one knows that you got a CC
                    msg.Priority = MailPriority.High;
                    //create and configure the SMTP client  ... Standard Mail Transfer Protocol (mail carrier)
                    SmtpClient client = new SmtpClient("mail.scottiez.com");  //mail person
                    client.Credentials = new NetworkCredential("*****@*****.**", "P@ssw0rd");
                    client.Port        = 8889;
                    //the original is 25, but in case that port is being blocked, you can change the port number here
                    using (client)
                    {
                        try
                        {
                            client.Send(msg); //sending the MailMessage object
                        }
                        catch
                        {
                            ViewBag.ErrorMessage = "There was an error sending your message, please email [email protected]";
                            return(View());
                        }
                    }
                    return(RedirectToAction("Index"));
                }

                ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", lessonView.LessonID);
                return(View("Index"));
            }
            return(View());
        }
示例#22
0
        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 View DateTime
            string currentUserID = User.Identity.GetUserId();
            if (User.IsInRole("Talent"))
            {
                LessonView lessonView = new LessonView();
                lessonView.UserID     = currentUserID;
                lessonView.LessonID   = id;
                lessonView.DateViewed = DateTime.Now;

                var viewDate = db.LessonViews.Where(lv => lv.LessonID == id && lv.UserID == currentUserID).FirstOrDefault();
                if (viewDate == null)
                {
                    db.LessonViews.Add(lessonView);
                    db.SaveChanges();
                }
            }
            #endregion

            #region Course Completion DateTime
            if (User.IsInRole("Talent"))
            {
                int totalLessons  = db.Lessons.Where(l => l.CourseID == lesson.CourseID && l.IsActive == true).Count();
                int viewedLessons = db.LessonViews.Where(lv => lv.Lesson.CourseID == lesson.CourseID && lv.Lesson.IsActive == true && lv.UserID == currentUserID).Count();
                if (viewedLessons == totalLessons)
                {
                    CourseCompletion courseCompletion = new CourseCompletion();
                    courseCompletion.UserID        = currentUserID;
                    courseCompletion.CourseID      = lesson.CourseID;
                    courseCompletion.DateCompleted = DateTime.Now;

                    var completionDate = db.CourseCompletions.Where(cc => cc.CourseID == lesson.CourseID && cc.UserID == currentUserID).FirstOrDefault();
                    if (completionDate == null)
                    {
                        db.CourseCompletions.Add(courseCompletion);
                        db.SaveChanges();

                        #region Course Completion Email
                        courseCompletion = db.CourseCompletions.Where(cc => cc.UserID == currentUserID && cc.CourseID == lesson.CourseID).Include(l => l.UserDetail).Include(l => l.Course).FirstOrDefault();
                        string      emailBody     = $"{courseCompletion.UserDetail.FullName} completed the {courseCompletion.Course.CourseName} course on {courseCompletion.DateCompleted:d}.";
                        MailMessage completionMsg = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "Just Act! Course Completion",
                            emailBody);
                        completionMsg.IsBodyHtml = true;
                        completionMsg.Priority   = MailPriority.High;
                        SmtpClient client = new SmtpClient("mail.justinlkennedy.com");
                        client.Credentials = new NetworkCredential("*****@*****.**", "C3ntr!q");
                        try
                        {
                            client.Send(completionMsg);
                        }
                        catch (Exception ex)
                        {
                            ViewBag.ErrorMessage = $"Sorry, something went wrong. Error message: {ex.Message}<br />{ex.StackTrace}";
                        }
                        #endregion
                    }
                }
            }
            #endregion

            #region Get Lesson Views By Current User
            if (User.IsInRole("Talent"))
            {
                var lessons     = db.Lessons.Include(l => l.Course).Where(l => l.CourseID == id);
                var lessonViews = db.LessonViews.Where(lv => lv.UserID == currentUserID);
                foreach (var item in lessons)
                {
                    foreach (var view in lessonViews)
                    {
                        if (view.LessonID == item.LessonID)
                        {
                            item.HasViewed  = true;
                            item.DateViewed = view.DateViewed;
                        }
                    }
                }
            }
            #endregion

            return(View(lesson));
        }
示例#23
0
        // GET: Lessons/Details/5
        public ActionResult Details(int id)
        {
            #region logic for recording lessons eompleted once employee views details page

            string userId = User.Identity.GetUserId();

            LessonView lessonView = new LessonView();
            lessonView.UserId     = userId;
            lessonView.LessonId   = id;
            lessonView.DateViewed = DateTime.Now;

            //prevent duplicate records
            var firstView = db.LessonViews.Where(x => x.LessonId == id && x.UserId == userId).FirstOrDefault();
            if (User.IsInRole("employee") && firstView == null)
            {
                db.LessonViews.Add(lessonView);
                db.SaveChanges();
            }

            #endregion

            #region logic for coursecompletion
            Lesson lesson               = db.Lessons.Find(id);
            int    courseLessonCount    = db.Lessons.Where(x => x.CourseId == lesson.CourseId && x.IsActive == true).Count();
            int    completedLessonCount = db.LessonViews.Where(x => x.Lesson.CourseId == lesson.CourseId && x.UserId == userId && x.Lesson.IsActive == true).Count();

            if (User.IsInRole("employee") && courseLessonCount == completedLessonCount)
            {
                CourseCompletion completion = new CourseCompletion();
                completion.UserId        = userId;
                completion.CourseId      = lesson.CourseId;
                completion.DateCompleted = DateTime.Now;

                //prevent duplicates
                var firstCompletion = db.CourseCompletions.Where(x => x.UserId == userId && x.CourseId == lesson.CourseId).FirstOrDefault();
                if (firstCompletion == null)
                {
                    db.CourseCompletions.Add(completion);
                    db.SaveChanges();

                    string courseuser      = db.UserDetails.Where(x => x.UserId == userId).FirstOrDefault().FullName;
                    string completedCourse = db.Courses.Where(x => x.CourseId == lesson.CourseId).FirstOrDefault().CourseName;
                    var    completedDate   = completion.DateCompleted;

                    string courseFinishMessage = $"{courseuser} completed the {completedCourse} course on {completedDate}";

                    MailMessage m = new MailMessage("*****@*****.**", "*****@*****.**", "Course Completion", courseFinishMessage);
                    m.IsBodyHtml = true;
                    m.Priority   = MailPriority.High;
                    SmtpClient client = new SmtpClient("mail.jamesgriffithdev.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "!James9601");
                    client.Port        = 8889;
                    client.Send(m);
                }
            }

            #endregion

            if (lesson.VideoUrl != null)
            {
                var    v   = lesson.VideoUrl.IndexOf("v=");
                var    amp = lesson.VideoUrl.IndexOf("&", v);
                string vid;
                if (amp == -1)
                {
                    vid = lesson.VideoUrl.Substring(v + 2);
                }
                else
                {
                    vid = lesson.VideoUrl.Substring(v + 2, amp - (v + 2));
                }
                ViewBag.VideoID = vid;
            }
            return(View(lesson));
        }
示例#24
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 Viewed
            int      lessonID   = id.Value;
            DateTime viewedDate = DateTime.Now;
            string   userID     = User.Identity.GetUserId();
            int      lessID     = lesson.LessonID;

            var currentLessons = db.LessonViews.Where(lv => lv.LessonID == id && lv.UserID == userID);

            if (currentLessons.Count() == 0)
            {
                LessonView lvCred = new LessonView();
                lvCred.LessonID   = lessID;
                lvCred.DateViewed = viewedDate;
                lvCred.UserID     = userID;
                db.LessonViews.Add(lvCred);
                db.SaveChanges();
            }

            Courses tCourse   = lesson.Course;
            int     tcID      = lesson.CourseID;
            int     thisCount = tCourse.Lessons.Count();
            //tCourse.Lessons.Count();

            int thisCourseCount = (from x in db.LessonViews
                                   where x.UserID == userID &&
                                   x.Lessons.CourseID == tcID
                                   select x).Count();

            bool userCompletedAlready = db.CourseCompletions.Where(uc => uc.UserID == userID && uc.CourseID == tcID).Count() > 0;

            if (!userCompletedAlready && thisCourseCount >= thisCount)
            {
                CourseCompletion cc = new CourseCompletion();
                cc.UserID        = userID;
                cc.CourseID      = tcID;
                cc.DateCompleted = DateTime.Now;

                db.CourseCompletions.Add(cc);
                db.SaveChanges();

                //current user details

                var currentUserDeets = db.UserDetails.Where(ud => ud.UserID == userID).Single();;

                //CourseCompletion cce = db.CourseCompletions.Where(x => x.CourseCompletionID == completeID).Single();
                string      body = $"{currentUserDeets.FirstName} {currentUserDeets.LastName} has completed course {cc.Course.CourseName} as of {cc.DateCompleted}.";
                MailMessage mm   = new MailMessage("*****@*****.**", "*****@*****.**", currentUserDeets.FirstName + " " + currentUserDeets.LastName + " has completed a course!", body);


                SmtpClient client = new SmtpClient("mail.devmeister.net");
                client.Credentials = new NetworkCredential("*****@*****.**", "Be@r8918$");
                using (client)
                {
                    client.Send(mm);
                }

                return(View(lesson));
            }
            //Be@r8918$
            #endregion
            return(View(lesson));
        }
        // 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));
        }
示例#26
0
        // GET: Lessons/Details/5
        public ActionResult Details(int id)
        {
            var    user   = User.Identity.GetUserId();
            Lesson lesson = db.Lessons.Find(id);

            if (lesson == null)
            {
                return(HttpNotFound());
            }
            var lessonsView = db.LessonViews.Where(x => x.UserID == user && x.LessonID == id).Count();

            if (lessonsView == 0)
            {
                LessonView lessonComplete = new LessonView();
                lessonComplete.UserID     = User.Identity.GetUserId();
                lessonComplete.LessonID   = id;
                lessonComplete.DateViewed = DateTime.Now;

                db.LessonViews.Add(lessonComplete);
                db.SaveChanges();
                var nbrLessons = db.Lessons.Where(x => x.CourseID == lesson.CourseID).Count();

                int nbrLessonsViewed = 0;
                var filteredCol      = db.Lessons.Where(x => x.CourseID == lesson.CourseID);
                foreach (var lv in db.LessonViews)
                {
                    foreach (var fc in filteredCol)
                    {
                        if (fc.LessonID == lv.LessonID && lv.UserID == User.Identity.GetUserId())
                        {
                            nbrLessonsViewed++;
                        }
                    }
                }
                if (nbrLessonsViewed == nbrLessons)
                {
                    CourseCompletion cc = new CourseCompletion();
                    cc.UserID        = User.Identity.GetUserId();
                    cc.CourseID      = lesson.CourseID;
                    cc.DateCompleted = lessonComplete.DateViewed;
                    db.CourseCompletions.Add(cc);
                    db.SaveChanges();

                    UserDetail guy        = db.UserDetails.Where(x => x.UserID == cc.UserID).Single();
                    Cours      courseName = db.Courses.Where(x => x.CourseID == cc.CourseID).Single();
                    string     body       = string.Format(
                        $"First: {guy.FirstName}<br/>"
                        + $"Last: {guy.LastName}<br />"
                        + $"Subject:  Completed <br />"
                        + $"Message: {courseName.CourseName} <br/>");
                    MailMessage msg = new MailMessage("*****@*****.**",         //from address
                                                      "*****@*****.**", //to address
                                                      "Courses completed",             //subject of email
                                                      body);                           //email body
                    msg.IsBodyHtml = true;
                    msg.CC.Add("*****@*****.**");
                    SmtpClient client = new SmtpClient("mail.jshdevco.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "COopers21@!");
                    client.EnableSsl   = false;
                    client.Port        = 8889;
                    using (client)
                    {
                        try
                        {
                            client.Send(msg);
                        }
                        catch
                        {
                            ViewBag.ErrorMessage = "An error occurred!\nPlease try again.";
                            return(View(lesson));
                        } //end catch
                    }     //end using
                    return(View(lesson));
                }
            }
            return(View(lesson));
        }
示例#27
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 Youtube


            if (lesson.VideoURL != null)
            {
                var    v   = lesson.VideoURL.IndexOf("v=");
                var    amp = lesson.VideoURL.IndexOf("&", v);
                string vid;
                // if the video id is the last value in the url
                if (amp == -1)
                {
                    vid = lesson.VideoURL.Substring(v + 2);
                    // if there are other parameters after the video id in the url
                }
                else
                {
                    vid = lesson.VideoURL.Substring(v + 2, amp - (v + 2));
                }
                ViewBag.VideoID = vid;
            }



            #endregion

            #region Lesson view
            string     userid     = User.Identity.GetUserId();
            UserDetail ud         = db.UserDetails.Find(userid);
            LessonView lessonView = new LessonView();
            lessonView.LessonId   = id;
            lessonView.UserId     = userid;
            lessonView.DateViewed = DateTime.Now;
            db.LessonViews.Add(lessonView);
            db.SaveChanges();

            //var lessonView = db.LessonViews.Include(c => c.DateViewed).Include(c => c.LessonId);
            //return View(lessonView.ToList());
            #endregion

            #region Coursecompletion and email
            int nbrLs  = db.Lessons.Where(x => x.CourseId == lesson.CourseId).Count();
            int nbrLvs = db.LessonViews.Where(x => x.UserId == userid && x.Lesson.CourseId == lesson.CourseId).Count();
            if (nbrLs == nbrLvs)
            {
                CourseCompletion courseCompletion = new CourseCompletion();
                courseCompletion.CourseId      = lesson.CourseId;
                courseCompletion.UserId        = userid;
                courseCompletion.DateCompleted = DateTime.Now;
                db.CourseCompletions.Add(courseCompletion);
                db.SaveChanges();

                string body = string.Format($"User: {courseCompletion.UserId})<br/>" +
                                            $"Email: {courseCompletion.UserId}</br> Subject: Course Completion<br/>" +
                                            $"Message:<br/> {courseCompletion.UserId} completed Course {courseCompletion.CourseId} on {courseCompletion.DateCompleted}.");

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

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

                using (client)
                {
                    try
                    {
                        client.Send(msg);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMessage = "The email did not send properly. Try again.";
                    }
                }
            }

            #endregion



            return(View(lesson));
        }
示例#28
0
        public ActionResult Details(int?id, bool?cl)
        {
            string userId = User.Identity.GetUserId();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Lesson lesson = db.Lessons.Find(id);

            if (lesson == null)
            {
                return(HttpNotFound());
            }
            if (lesson.VideoURL != null)
            {
                var    v   = lesson.VideoURL.IndexOf("v=");
                var    amp = lesson.VideoURL.IndexOf("&", v);
                string vid;
                if (amp == -1)
                {
                    vid = lesson.VideoURL.Substring(v + 2);
                }
                else
                {
                    vid = lesson.VideoURL.Substring(v + 2, amp - (v - 2));
                }
                ViewBag.VideoID = vid;
            }
            if (User.IsInRole("HR"))
            {
                return(View(lesson));
            }
            if (cl != true)
            {
                lesson.CompletedLesson = true;
                LessonView lessonViewed = new LessonView();
                lessonViewed.EmpId      = userId;
                lessonViewed.LessonId   = lesson.LessonId;
                lessonViewed.DateViewed = DateTime.Now.Date;
                db.LessonViews.Add(lessonViewed);
                db.SaveChanges();
            }
            var courseCheck   = db.Courses.Where(c => c.CourseId == lesson.CourseId).FirstOrDefault();
            var lessonsViewed = db.LessonViews.Where(l => l.EmpId == userId);

            if (lessonsViewed.Where(lv => lv.Lesson.CourseId == courseCheck.CourseId).Count() + db.Lessons.Where(l => l.CourseId == courseCheck.CourseId).Where(l => l.IsActive == false).Count() == db.Lessons.Where(l => l.CourseId == courseCheck.CourseId).Count())
            {
                var coursesCompleted = db.CourseCompletions.Where(cc => cc.EmpId == userId);
                if (coursesCompleted.Where(cc => cc.CourseId == courseCheck.CourseId).Count() == 0)
                {
                    //    courseCheck.CompletedCourse = true;
                    //}
                    //if (courseCheck.CompletedCourse != true)
                    CourseCompletion courseCompleted = new CourseCompletion();
                    courseCompleted.EmpId         = userId;
                    courseCompleted.CourseId      = courseCheck.CourseId;
                    courseCompleted.DateCompleted = DateTime.Now.Date;
                    db.CourseCompletions.Add(courseCompleted);
                    db.SaveChanges();
                    #region Email to manager
                    var    emp    = db.EmpDetails.Where(e => e.EmpId == courseCompleted.EmpId).FirstOrDefault();
                    var    course = db.Courses.Where(c => c.CourseId == courseCompleted.CourseId).FirstOrDefault();
                    string body   = $"{emp.EmpName} has completed the following course {course.CourseName}";

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

                    SmtpClient client = new SmtpClient("mail.loganrothrock.com");
                    client.Credentials = new NetworkCredential("*****@*****.**", "WorstUrchin7539!");
                    try
                    {
                        client.Send(m);
                    }
                    catch (Exception e)
                    {
                        ViewBag.Message = e.StackTrace;
                    }
                    #endregion
                }
            }
            return(View(lesson));
        }
示例#29
0
 public override void _Ready()
 {
     _landingPageNode = GetNode <LandingPageNode>(_landingPagePath);
     _lessonView      = GetNode <LessonView>(_lessonViewPath);
 }
示例#30
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));
        }