Example #1
0
        public ActionResult Create(CourseAssets courseassets, HttpPostedFileBase file, int Courseid)
        {
            var          guidFileName = string.Empty;
            var          videoSize    = string.Empty;
            var          loggedUserID = string.Empty;
            var          tmpGuid      = string.Empty;
            VideoEncoder objEncoder;

            if (ModelState.IsValid)
            {
                courseassets.CourseID = Courseid;
                try
                {
                    loggedUserID        = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();
                    courseassets.userID = Convert.ToInt32(loggedUserID);
                }
                catch (Exception ex)
                {
                    courseassets.userID = 0;
                }

                if (file != null)
                {
                    if (file.ContentLength > 0)
                    {
                        objEncoder = new VideoEncoder();
                        var fileInfoObj = new FileInfo(file.FileName);
                        tmpGuid      = Guid.NewGuid().ToString().ToUpper();
                        guidFileName = tmpGuid + fileInfoObj.Extension.ToLower();
                        videoSize    = file.ContentLength.ToString();
                        var path = Path.Combine(Server.MapPath("~/tempVideoFiles/"), guidFileName);
                        if (!Directory.Exists(Server.MapPath("~/tempVideoFiles/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/tempVideoFiles/"));
                        }
                        file.SaveAs(path);
                        if (!Directory.Exists(Server.MapPath("~/VideoFiles/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/VideoFiles/"));
                        }
                        objEncoder.EncodeVideo(guidFileName, file.FileName);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                    courseassets.AssetGUid = tmpGuid;
                    courseassets.AssetSize = Convert.ToInt32(videoSize);
                }

                db.CourseAssets.Add(courseassets);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(courseassets));
        }
        public ActionResult Register(RegisterModel model)
        {
            var db = new CourseLearnerContext();

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    var objCourseUser = new CourseUserDetail();
                    objCourseUser.UserID         = Convert.ToInt32(Membership.GetUser(model.UserName).ProviderUserKey);
                    objCourseUser.FirstName      = model.FirstName;
                    objCourseUser.LastName       = model.LastName;
                    objCourseUser.ContactAddress = model.AboutMe;
                    objCourseUser.dateOfBirth    = DateTime.UtcNow;
                    objCourseUser.userType       = model.isStudent;
                    db.CourseUser.Add(objCourseUser);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Create(FormCollection objForm, Course course, HttpPostedFileBase file)
        {
            var courseName   = string.Empty;
            var loggedUserID = string.Empty;
            var guidFileName = string.Empty;

            if (ModelState.IsValid)
            {
                loggedUserID = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();

                if (!string.IsNullOrEmpty(objForm["coursecategory"]))
                {
                    courseName = objForm["coursecategory"];
                    CourseCategory objcategory = new CourseCategory();
                    objcategory.CategoryName = courseName;
                    db.Course_Category.Add(objcategory);
                    db.SaveChanges();

                    course.CourseCategoryId = objcategory;
                    course.Userid           = Convert.ToInt32(loggedUserID);
                }
                if (file != null)
                {
                    if (file.ContentLength > 0)
                    {
                        var fileInfoObj = new FileInfo(file.FileName);
                        var guid        = Guid.NewGuid().ToString().ToUpper();
                        guidFileName = guid + fileInfoObj.Extension.ToLower();
                        var path = Path.Combine(Server.MapPath("~/UploadedImages/"), guidFileName);
                        if (!Directory.Exists(Server.MapPath("~/UploadedImages/")))
                        {
                            Directory.CreateDirectory(Server.MapPath("~/UploadedImages/"));
                        }
                        file.SaveAs(path);
                    }
                }

                //temporary code
                course.CourseImgURl = guidFileName;
                db.Courses.Add(course);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(course));
        }