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

            return(View(course));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "ReservationID,ReservationDate,UserID,LessonID")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                db.Reservations.Add(reservation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserID   = new SelectList(db.UserDetails, "UserID", "FirstName", reservation.UserID);
            ViewBag.LessonID = new SelectList(db.Lessons, "LessonID", "LessonTitle", reservation.LessonID);
            return(View(reservation));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
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));
        }
        public ActionResult Create([Bind(Include = "UserID,FirstName,LastName,AvatarImage")] UserDetail userDetail)
        {
            if (db.UserDetails.Where(u => u.UserID == userDetail.UserID).Count() > 0)
            {
                ViewBag.alreadyExists = true;
                ViewBag.UserID        = userDetail.UserID;
                return(View());
            }

            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));
        }
        // GET: Lessons/Details/5
        public ActionResult Details(int?id) //id = lesson id
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Lesson lesson = db.Lessons.Find(id);

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

            #region lesson view record creation (coder: hjkang)
            string currentUserID = User.Identity.GetUserId();
            if (currentUserID != null)
            {
                //LessonView lessonview = new LessonView() {LessonID=lesson.LessonID, UserID=currentUserID, DateViewed=DateTime.Now };

                //lessonview.LessonID = lesson.LessonID;
                //lessonview.UserID = currentUserID;
                //lessonview.DateViewed = DateTime.Now;
                db.LessonViews.Add(new LessonView()
                {
                    LessonID = lesson.LessonID, UserID = currentUserID, DateViewed = DateTime.Now
                });
                db.SaveChanges();

                #endregion

                #region record creation of course completion  (coder: hjkang)
                // if # of lessons in the course == # of lesson views by the user, then the course of the user is completed.

                //# of lessons in the course

                //# of lesson views for the course
                var nbrLessonsViewed = 0;
                //var lessonViews = db.LessonViews.
                //                 Where(x => (x.Lesson.CourseID == lesson.CourseID)
                //                       && (x.UserID == currentUserID));
                var fc = db.LessonViews.Where(x => (x.Lesson.CourseID == lesson.CourseID) &&
                                              (x.UserID == currentUserID)).OrderBy(x => x.LessonID).ToList();

                if (fc.Count() == 1)
                {
                    nbrLessonsViewed = 1;
                }
                else
                {
                    for (int i = 0; i < (fc.Count() - 1); i++)
                    {
                        var elementA = fc.ElementAt(i);
                        var elementB = fc.ElementAt(i + 1);
                        if (elementA.LessonID != elementB.LessonID)
                        {
                            nbrLessonsViewed++;
                        }
                    }
                    nbrLessonsViewed += 1;
                }
                //var nbrLessons = db.Lessons.Where(x => x.CourseID == lesson.CourseID).Count();

                if (nbrLessonsViewed == db.Lessons.Where(x => x.CourseID == lesson.CourseID).Count())
                {
                    //courseComplete.UserID = currentUserID;
                    //courseComplete.CourseID = lesson.CourseID;
                    //courseComplete.DateCompleted = DateTime.Now;

                    //CourseCompletion courseComplete = new CourseCompletion() { UserID = currentUserID, CourseID = lesson.CourseID, DateCompleted = DateTime.Now };

                    db.CourseCompletions.Add(new CourseCompletion()
                    {
                        UserID = currentUserID, CourseID = lesson.CourseID, DateCompleted = DateTime.Now
                    });
                    db.SaveChanges();

                    //send email to the parent(a manager) to notify when a child completes a course
                    //var user = db.UserDetails.Where(u => u.UserID == currentUserID).SingleOrDefault();

                    string body = string.Format($"{db.UserDetails.Where(u => u.UserID == currentUserID).SingleOrDefault().FirstName}"
                                                + " has completed " + $"the course of {lesson.Cours.CourseName}" + $" on {DateTime.Now}.");

                    MailMessage msg = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "Your child completed a course.",
                        body);

                    msg.IsBodyHtml = true;
                    msg.CC.Add("*****@*****.**");

                    SmtpClient client = new SmtpClient("mail.hjkangweb.com");

                    client.Credentials = new NetworkCredential("*****@*****.**", "kang1226@@");
                    client.EnableSsl   = false;
                    client.Port        = 25;

                    using (client)
                    {
                        try
                        {
                            client.Send(msg);
                        }
                        catch
                        {
                            ViewBag.ErrorMessage = "There was an error sending complete notification. \n" + "Please notify your parent you have completed the course.";
                        }
                    }
                }

                #endregion
            }

            return(View(lesson));
        }
Esempio n. 7
0
        public async Task <ActionResult> Create(RegisterViewModel userViewModel, HttpPostedFileBase avatarImage, 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)
                {
                    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());
                        }
                    }

                    #region Dealing with custom user details (added by jin)
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID    = user.Id;
                    newUserDeets.FirstName = userViewModel.FirstName;
                    newUserDeets.LastName  = userViewModel.LastName;

                    // handle file upload
                    string image = "noImage.jpg";
                    if (avatarImage != null)
                    {
                        image = avatarImage.FileName;
                        string   ext      = image.Substring(image.LastIndexOf("."));
                        string[] goodExts = new string[] { ".jpg", ".jpeg", ".gif", ".png" };

                        if (goodExts.Contains(ext.ToLower()))
                        {
                            image = Guid.NewGuid() + ext;
                            //avatarImage.SaveAs(Server.MapPath("~/Content/Images/Users/" + image));
                            //after resizing the above saving is not needed.

                            //resizing an image file.

                            string savePath       = Server.MapPath("~/Content/Images/Users/");
                            Image  convertedImage = Image.FromStream(avatarImage.InputStream);
                            ImageUtilities.ResizeImage(savePath, image, convertedImage, 500, 100);
                        }
                        else
                        {
                            image = "noImage.jpg";
                        }
                    }
                    newUserDeets.AvatarImage = image;
                    //end image upload

                    FamilySiteEntities db = new FamilySiteEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion
                }
                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());
        }
Esempio n. 8
0
        public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase avatarImage)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "User"); //added by jin to make default role as User when a person registers.

                    #region Dealing with custom user details (added by jin)
                    UserDetail newUserDeets = new UserDetail();
                    newUserDeets.UserID    = user.Id;
                    newUserDeets.FirstName = model.FirstName;
                    newUserDeets.LastName  = model.LastName;

                    // handle file upload
                    string image = "noImage.jpg";
                    if (avatarImage != null)
                    {
                        image = avatarImage.FileName;
                        string   ext      = image.Substring(image.LastIndexOf("."));
                        string[] goodExts = new string[] { ".jpg", ".jpeg", ".gif", ".png" };

                        if (goodExts.Contains(ext.ToLower()))
                        {
                            image = Guid.NewGuid() + ext;
                            //avatarImage.SaveAs(Server.MapPath("~/Content/Images/Users/" + image));
                            //after resizing the above saving is not needed.

                            //resizing an image file.

                            string savePath       = Server.MapPath("~/Content/Images/Users/");
                            Image  convertedImage = Image.FromStream(avatarImage.InputStream);
                            ImageUtilities.ResizeImage(savePath, image, convertedImage, 500, 100);
                        }
                        else
                        {
                            image = "noImage.jpg";
                        }
                    }
                    newUserDeets.AvatarImage = image;
                    //end image upload

                    FamilySiteEntities db = new FamilySiteEntities();
                    db.UserDetails.Add(newUserDeets);
                    db.SaveChanges();
                    #endregion

                    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"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }