public ActionResult Edit([Bind(Include = "CourseId,CourseName,CourseDescription,IsActive")] Course course)
 {
     if (ModelState.IsValid)
     {
         bool isActive = db.Courses.Where(c => c.CourseId == course.CourseId).Select(c => c.IsActive).FirstOrDefault();
         if (course.IsActive != isActive)
         {
             List <Lesson> allLessons = db.Lessons.Where(l => l.CourseId == course.CourseId).ToList();
             if (course.IsActive == false)
             {
                 foreach (var lesson in allLessons)
                 {
                     if (lesson.isActive == true)
                     {
                         lesson.isActive = !lesson.isActive;
                     }
                 }
             }
             else
             {
                 db.Entry(course).State = EntityState.Modified;
                 db.SaveChanges();
                 ViewBag.CourseId = course.CourseId;
                 return(View("LessonsSelection"));
             }
         }
         db.Entry(course).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(course));
 }
Beispiel #2
0
        public ActionResult Edit([Bind(Include = "LessonID,LessonTitle,CourseID,Introduction,VideoURL,PdfFilename,IsActive")] Lesson lesson, HttpPostedFileBase lessonFile)
        {
            if (ModelState.IsValid)
            {
                #region File Upload
                if (lessonFile != null)
                {
                    string   file     = lessonFile.FileName;
                    string[] goodExts = new string[] { ".jpg", ".jpeg", ".png", ".gif", ".pdf" };
                    //check that the uploaded file ext is in our list of good file extensions && check file size <= 4mb (max by default from ASP.NET)
                    if (goodExts.Contains(file.Substring(file.LastIndexOf("."))) && lessonFile.ContentLength <= 4194304)
                    {
                        if (lesson.PdfFilename != null && lesson.PdfFilename != "JustinLKennedyResume.pdf") //Delete the old file of the record that is being edited
                        {
                            string path = Server.MapPath("~/Content/images/lessons/");
                            UploadUtility.Delete(path, lesson.PdfFilename);
                        }
                        lessonFile.SaveAs(Server.MapPath("~/Content/images/lessons/" + file));
                    }
                    lesson.PdfFilename = file;
                }
                #endregion

                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", lesson.CourseID);
            return(View(lesson));
        }
        public IHttpActionResult PutOrderTable(int id, OrderTable orderTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderTable.OrderId)
            {
                return(BadRequest());
            }

            db.Entry(orderTable).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutWishlist(int id, Wishlist wishlist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != wishlist.WishListId)
            {
                return(BadRequest());
            }

            db.Entry(wishlist).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WishlistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "LessonId,LessonTitle,CourseId,Introduction,VideoURL,PdfFilename,IsActive")] Lesson lesson, HttpPostedFileBase lessonVideoURl, HttpPostedFileBase lessonPDFFile)
 {
     if (ModelState.IsValid)
     {
         if (lessonPDFFile != null)
         {
             string newPdfName = lessonPDFFile.FileName;
             string ext        = newPdfName.Substring(newPdfName.LastIndexOf(".")).ToLower();
             if (ext == ".pdf")
             {
                 newPdfName = Guid.NewGuid() + ext;
                 lessonPDFFile.SaveAs(Server.MapPath("~/Content/LessonLinks/" + newPdfName));
                 if (lesson.PdfFilename != null && lesson.PdfFilename != "noPDF.pdf")
                 {
                     System.IO.File.Delete(Server.MapPath("~/Content/LessonLinks/" + Session["currentImage"].ToString()));
                 }
                 lesson.PdfFilename = newPdfName;
             }
         }
         db.Entry(lesson).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", lesson.CourseId);
     return(View(lesson));
 }
Beispiel #6
0
        public ActionResult Edit([Bind(Include = "LessonId,LessonTitle,CourseId,Introduction,VideoURL,PdfFilename,IsActive")] Lesson lesson, HttpPostedFileBase pdfFile)
        {
            if (ModelState.IsValid)
            {
                #region File Upload
                if (pdfFile != null)
                {
                    string fileName = pdfFile.FileName;

                    string fileExtension = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                    if (allowedExts.Contains(fileExtension.ToLower()) && (pdfFile.ContentLength <= 4194304))
                    {
                        fileName = Guid.NewGuid() + fileExtension;
                        pdfFile.SaveAs(Server.MapPath("~/Content/lessonPdf/" + fileName));

                        if (lesson.PdfFilename != null)
                        {
                            System.IO.File.Delete(Server.MapPath("~/Content/lessonPdf/" + lesson.PdfFilename));
                        }

                        lesson.PdfFilename = fileName;
                    }
                }
                #endregion

                db.Entry(lesson).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("../Reports/Admin"));
            }
            ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", lesson.CourseId);
            return(RedirectToAction("../Reports/Admin"));
        }
 public virtual T Update(T record)
 {
     Records.Attach(record);
     _context.Entry(record).State = EntityState.Modified;
     _context.SaveChanges();
     return(record);
 }
Beispiel #8
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"));
        }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "Category_Id,Category_Name,Category_Description")] category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Beispiel #10
0
 public ActionResult Edit([Bind(Include = "CourseID,CourseName,Description,IsActive")] Course course)
 {
     if (ModelState.IsValid)
     {
         db.Entry(course).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(course));
 }
Beispiel #11
0
 public ActionResult Edit([Bind(Include = "id,name,password,enrollment,email,contact,address")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
Beispiel #12
0
 public ActionResult Edit([Bind(Include = "BookID,ISBN,Title,DateofPublication")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Beispiel #13
0
 public ActionResult Edit([Bind(Include = "JobID,JobName")] Job job)
 {
     if (ModelState.IsValid)
     {
         db.Entry(job).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(job));
 }
 public ActionResult Edit([Bind(Include = "Username,password,ID")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "EmpId,FirstName,LastName")] EmpDetail empDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(empDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(empDetail));
 }
 public ActionResult Edit([Bind(Include = "Role_Id,Role_Name,Descriptions")] Role role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(role));
 }
 public ActionResult Edit([Bind(Include = "Author_Id,Author_Name,Author_Description")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
Beispiel #18
0
 public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,UserName,Email,Phone")] LibUser libUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(libUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(libUser));
 }
Beispiel #19
0
 public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,IsManager,Email,JobID,ReportsToID")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Beispiel #20
0
 public ActionResult Edit([Bind(Include = "Staff_Id,First_Name,Last_Name,Phone_No,Email,Username,Pass,Role_Id")] Staff staff)
 {
     if (ModelState.IsValid)
     {
         db.Entry(staff).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Role_Id = new SelectList(db.Roles, "Role_Id", "Role_Name", staff.Role_Id);
     return(View(staff));
 }
 public ActionResult Edit([Bind(Include = "Member_Id,First_Name,Last_Name,Phone_No,Email,User_No,Pass,Role_Id")] Member_Details member_Details)
 {
     if (ModelState.IsValid)
     {
         db.Entry(member_Details).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Role_Id = new SelectList(db.Roles, "Role_Id", "Role_Name", member_Details.Role_Id);
     return(View(member_Details));
 }
 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);
     return(View(courseCompletion));
 }
 public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName")] UserDetail userDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", userDetail.UserId);
     return(View(userDetail));
 }
Beispiel #24
0
 public ActionResult Edit([Bind(Include = "UserID,FirstName,LastName,JobID,ManagerID,Email")] Manager manager)
 {
     if (ModelState.IsValid)
     {
         db.Entry(manager).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserID = new SelectList(db.AspNetUsers, "Id", "Email", manager.UserID);
     return(View(manager));
 }
 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));
 }
Beispiel #26
0
 public ActionResult Edit([Bind(Include = "LessonID,LessonTitle,CourseID,Introduction,VideoUrl,PdfFileName,IsActive")] Lesson lesson)
 {
     if (ModelState.IsValid)
     {
         db.Entry(lesson).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "CourseName", lesson.CourseID);
     return(View(lesson));
 }
Beispiel #27
0
 public ActionResult Edit([Bind(Include = "Stock_Id,Book_Name,Qty,Available")] stock stock)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stock).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Book_Name = new SelectList(db.Books, "Book_Id", "Book_Name", stock.Book_Name);
     return(View(stock));
 }
 public ActionResult Edit([Bind(Include = "Book_Id,Book_Name,Category_Id,Author_Id,Publication_Year")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Author_Id   = new SelectList(db.Authors, "Author_Id", "Author_Name", book.Author_Id);
     ViewBag.Category_Id = new SelectList(db.categories, "Category_Id", "Category_Name", book.Category_Id);
     return(View(book));
 }
 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));
 }
Beispiel #30
0
 public ActionResult Edit([Bind(Include = "Borrower_Id,Book_Id,Borrower_From,Borrower_To,Issue_By")] Borrower_Details borrower_Details)
 {
     if (ModelState.IsValid)
     {
         db.Entry(borrower_Details).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Book_Id  = new SelectList(db.Books, "Book_Id", "Book_Name", borrower_Details.Book_Id);
     ViewBag.Issue_By = new SelectList(db.Staffs, "Staff_Id", "First_Name", borrower_Details.Issue_By);
     return(View(borrower_Details));
 }