Пример #1
0
        /// <summary>
        /// The onPostAsync method checks to see if the model state is valid and creates a new resource with a link
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync()
        {
            //checks to see if the modelstate is valid
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            //Sets the resource courseid for the resource being created to the CourseID above
            this.Resource.CourseID = CourseID;

            //Sets the resource Date Added for the resource being created to the DateTime right now
            this.Resource.DateAdded = DateTime.Now;

            //Sets the resource Type for the resource being created to link
            this.Resource.Type = "Link";

            if (this.Resource.Link.Substring(0, 4) != "http")
            {
                string Link = "https://" + this.Resource.Link;
                this.Resource.Link = Link;
            }

            //Adds the resource to the database
            var success = await _context.CreateResourceAsync(this.Resource);

            if (success)
            {
                //Redirects the mentor to the specified course
                return(RedirectToPage("../Mentor/Course/Index", new { id = CourseID }));
            }
            else
            {
                return(RedirectToPage("/Error"));
            }
        }