示例#1
0
        /// <summary>
        /// The onPostSync method takes in the id for a resource and deletes the specified resource and any documents related to it.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            //checks to see if the id is null
            if (id == null)
            {
                return(NotFound());
            }

            //Uses the GetResourceAsync function from the applicationdbcontext file to query the database for the resource based off of the id passed in.
            Resource = await _context.Resource.FindAsync(id);

            //Gets the course id related to the resource
            var CourseID = Resource.CourseID;

            //passes the resource ID to the Delete resource function in applicationDbContext file to delete the resource
            var success = await _context.DeleteResource(Resource.ResourceID);

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