Example #1
0
        public async Task<ActionResult> Content(CourseViewModel model, UserProfile user)
        {
            if (this.ModelState.IsValid)
            {
                HttpServerUtility server = System.Web.HttpContext.Current.Server;
                string clientId = user.ClientId.ToString(CultureInfo.InvariantCulture);
                string courseId = model.CourseId.ToString(CultureInfo.InvariantCulture);

                // check folders exist - UPLOADS FOLDER
                if (!Directory.Exists(server.MapPath("~/uploads")))
                {
                    Directory.CreateDirectory(server.MapPath("~/uploads"));
                }

                // CLIENT FOLDER
                if (!Directory.Exists(server.MapPath("~/uploads/" + clientId)))
                {
                    Directory.CreateDirectory(server.MapPath("~/uploads/" + clientId));
                }

                // COURSE FOLDER
                if (!Directory.Exists(server.MapPath("~/uploads/" + clientId + "/" + courseId)))
                {
                    Directory.CreateDirectory(server.MapPath("~/uploads/" + "/" + clientId + "/" + courseId));
                }

                string targetFolder = server.MapPath("~/uploads/" + clientId + "/" + courseId + "/");
                string targetPath = Path.Combine(targetFolder, model.Content.FileName);
                string linkToFile = "/uploads/" + clientId + "/" + courseId + "/" + model.Content.FileName;

                // save file to disk
                model.Content.SaveAs(targetPath);

                // update record
                bool fileUploadSuccess = await this.AddContentToDb(model.Content.FileName, linkToFile, courseId);

                if (fileUploadSuccess)
                {
                    this.ViewBag.AlertStatus = "success";
                    this.ViewBag.AlertMessage = "File: " + model.Content.FileName + " successfully uploaded.";
                }
                else
                {
                    this.ViewBag.AlertStatus = "danger";
                    this.ViewBag.AlertMessage = "File: " + model.Content.FileName + " could not be saved.";
                }
            }
            else
            {
                this.ViewBag.AlertStatus = "danger";
                this.ViewBag.AlertMessage = "Please check the form for errors and try again.";
            }

            model.CourseTypeList = await this.GetCourseTypeList();

            return this.View("Edit", model);
        }
Example #2
0
        /// <summary>
        /// The session.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task<ActionResult> Session(int id)
        {
            var model = new CourseViewModel
                            {
                                CourseId = id
                            };

            return this.View(model);
        }
Example #3
0
        /// <summary>
        /// The edit.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task<ActionResult> Edit(int id)
        {
            var model = new CourseViewModel
                            {
                                CourseId = id, CourseTypeList = await this.GetCourseTypeList()
                            };

            return this.View(model);
        }