Example #1
0
        public async Task<ActionResult> Login(LoginViewModel model, UserProfile user)
        {
            if (this.ModelState.IsValid)
            {
                this.token = await this.GetToken(model);

                // check for a valid token
                if (this.token.access_token != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Username, false);

                    // create a cookie based on the token
                    var tokenCookie = new HttpCookie("AvemtecLMS", this.token.access_token);
                    tokenCookie.Expires.AddDays(1);
                    this.HttpContext.Response.Cookies.Add(tokenCookie);

                    // initialise the user profile
                    this.Session.SetUserProfile(await this.InitializeUserProfile(model.Username));

                    return this.RedirectToAction("Welcome", "Home");
                }

                this.ModelState.AddModelError("Username", "There was an error logging you in, please try again.");
                return this.View("../Home/Index", model);
            }

            this.ModelState.AddModelError("Username", "There was an error logging you in, please try again.");
            return this.View("../Home/Index", model);
        }
Example #2
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);
        }
 /// <summary>
 /// The set user profile.
 /// </summary>
 /// <param name="session">
 /// The session.
 /// </param>
 /// <param name="userProfile">
 /// The user profile.
 /// </param>
 public static void SetUserProfile(this HttpSessionStateBase session, UserProfile userProfile)
 {
     session["UserInfo"] = userProfile;
 }