public async Task <IActionResult> OnPostAsync() { if (User.Identity.IsAuthenticated) { if (ModelState.IsValid) { CourseResource addResource = new CourseResource(); addResource.ResourceTitle = newResource.ResourceTitle; addResource.CourseID = newResource.CourseID; var course = await courseDbContext.Courses.SingleOrDefaultAsync(m => m.ID == addResource.CourseID); addResource.CourseName = course.CourseCode + " - " + course.CourseSemester + " " + course.CourseYear; addResource.ResourceLink = String.Empty; await courseResourceDbContext.Resources.AddAsync(addResource); await courseResourceDbContext.SaveChangesAsync(); return(RedirectToPage("/UploadResourceAttachmentPage")); } else { return(Page()); } } else { return(RedirectToPage("/Error")); } }
public CourseResource Save(CourseResource item) { this.dbContext.CourseResources.Add(item); this.dbContext.SaveChanges(); return(item); }
public UploadResourceAttachmentPageModel(CourseResourceDbContext adb, ProfileDbContext pDbContext) { courseResourceDbContext = adb; CurrentResource = new CourseResource(); CurrentResource = adb.Resources.Last(); profileDbContext = pDbContext; CurrentProfile = new Profile(); }
public async Task CreateCourseResource(string lectureId, string resourceId, CancellationToken token) { var moduleIdCourseId = await _repo.GetLectureModuleIdAndCourseId(lectureId, token); var courseResource = new CourseResource(moduleIdCourseId.CourseId, moduleIdCourseId.ModuleId, lectureId, resourceId); await _repo.AddCourseResource(courseResource, token); }
public void ConstructorWithCourseIdModuleIdLectureIdResourceId_WhenCalled_SetRequiredPropertiesCorrectly() { _sut = new CourseResource("courseId", "moduleId", "lectureId", "resourceId"); Assert.That(_sut.CourseId, Is.EqualTo("courseId")); Assert.That(_sut.ModuleId, Is.EqualTo("moduleId")); Assert.That(_sut.LectureId, Is.EqualTo("lectureId")); Assert.That(_sut.ResourceId, Is.EqualTo("resourceId")); }
public AddNewResourceModel(CourseResourceDbContext adb, CourseDbContext cdb, ProfileDbContext pdb) { courseResourceDbContext = adb; courseDbContext = cdb; CoursesList = new List <Course>(); newResource = new CourseResource(); profileDbContext = pdb; CurrentProfile = new Profile(); }
public async Task <IActionResult> Create([FromBody] CourseResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Course course = _mapper.Map <CourseResource, Course>(model); var courseResponse = await _courseService.CreateAsync(course); if (!courseResponse.Success) { return(BadRequest(courseResponse.Message)); } return(Ok(courseResponse.Extra)); }
public async Task AddCourseResource(CourseResource courseResource, CancellationToken token) { await _context.CourseResources.AddAsync(courseResource, token); }
public CourseResource Update(int id, CourseResource item) { throw new NotImplementedException(); }