/// <summary> /// Manages the resources. /// </summary> private async void ManageResources() { ManageResourcesContentDialog.DataContext = CourseResources; var result = await ManageResourcesContentDialog.ShowAsync(); var selectedCourse = (Course)CoursesListView.SelectedItem; if (result != ContentDialogResult.Primary) { if (result == ContentDialogResult.Secondary) { UpdateCourseResources(selectedCourse); } } else { if (selectedCourse == null) { return; } foreach (var selectedCourseResource in selectedCourse.Resources.ToArray()) { if (CourseResources.All(r => r.ResourceId != selectedCourseResource.ResourceId)) { await DeleteCourseResource(selectedCourseResource, selectedCourse); } } foreach (var courseResource in CourseResources) { if (courseResource.ResourceId == 0) { await AddCourseResource(courseResource, selectedCourse); } else { var originalResource = selectedCourse.Resources.Find(r => r.ResourceId == courseResource.ResourceId); if (originalResource.Name == courseResource.Name && originalResource.Link == courseResource.Link) { continue; } await UpdateCourseResource(courseResource); originalResource.Name = courseResource.Name; originalResource.Link = courseResource.Link; } } } }
/// <summary> /// Updates the course resources. /// </summary> /// <param name="course">The course.</param> private void UpdateCourseResources(Course course) { if (course == null) { return; } CourseResources.Clear(); foreach (var r in course.Resources) { CourseResources.Add(new Resource { ResourceId = r.ResourceId, Name = r.Name, Link = r.Link }); } }
public async Task <IActionResult> Upload(List <IFormFile> files, int course_id, int lecture_id) { long size = files.Sum(f => f.Length); var filePaths = new List <string>(); foreach (var formFile in files) { if (formFile.Length > 0) { //Create the new filename var new_filename = course_id.ToString() + "_" + lecture_id.ToString() + "_" + formFile.FileName; var course_resource = new CourseResources { Original_Name = formFile.FileName, Generated_Name = new_filename, Course_Id = course_id, Lecture_Id = lecture_id }; _context.CourseResources.Add(course_resource); _context.SaveChanges(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\Course_Resources", new_filename); filePaths.Add(filePath); using var stream = new FileStream(filePath, FileMode.Create); await formFile.CopyToAsync(stream); } } // process uploaded files // Don't rely on or trust the FileName property without validation. return(RedirectToAction("Details", "Trainings", new { id = course_id })); }
public async Task <IActionResult> OnGetAsync(int?id) { int ID = (int)id; CurrentCourse = await courseDbContext.Courses.SingleOrDefaultAsync(m => m.ID == ID); if (CurrentCourse != null) { var tempList = await courseResourceDbContext.Resources.ToListAsync(); foreach (var resource in tempList) { if (resource.CourseID == ID) { CourseResources.Add(resource); } } return(Page()); } else { return(RedirectToPage("/NotFound")); } }
/// <summary> /// Removes the resource. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> private void RemoveResource(object sender, RoutedEventArgs e) => CourseResources.Remove((Resource)ManageResourcesListView.SelectedItem);
/// <summary> /// Adds the resource. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> private void AddResource(object sender, RoutedEventArgs e) => CourseResources.Add(new Resource { Name = "New Resource" });