public async Task <ActionResult <OfferingDTO> > GetOffering(string id) { var offering = await _context.Offerings.FindAsync(id); if (offering == null) { return(NotFound()); } OfferingDTO offeringDTO = new OfferingDTO { Offering = offering, Courses = offering.CourseOfferings .Select(co => new CourseDTO { CourseId = co.Course.Id, CourseNumber = co.Course.CourseNumber, DepartmentId = co.Course.DepartmentId, DepartmentAcronym = co.Course.Department.Acronym }).ToList(), Term = offering.Term, InstructorIds = offering.OfferingUsers .Where(uo => uo.IdentityRole.Name == Globals.ROLE_INSTRUCTOR) .Select(uo => new ApplicationUser { Id = uo.ApplicationUser.Id, Email = uo.ApplicationUser.Email, FirstName = uo.ApplicationUser.FirstName, LastName = uo.ApplicationUser.LastName }).ToList() }; return(offeringDTO); }
private void AssertOfferingDTO(OfferingDTO offeringDTO, Offering offering, string courseId, string departmentId) { Assert.Equal(offering, offeringDTO.Offering); Assert.Single(offeringDTO.Courses); Assert.Equal(courseId, offeringDTO.Courses[0].CourseId); Assert.Equal(departmentId, offeringDTO.Courses[0].DepartmentId); Assert.Equal(departmentId, offeringDTO.Courses[0].DepartmentAcronym); Assert.Single(offeringDTO.InstructorIds); Assert.Equal(TestGlobals.TEST_USER_ID, offeringDTO.InstructorIds[0].Id); Assert.Equal(offering.TermId, offeringDTO.Term.Id); }
public Offering Post([FromBody] OfferingDTO offering) { var postObject = new Offering() { Title = offering.Title, Description = offering.Description, Location = offering.Location, PostDate = offering.PostDate, ImageURL = offering.ImageURL, UserID = offering.UserID }; try { _context.offering.Add(postObject); _context.SaveChanges(); } catch (Exception ex) { throw ex; } return(_context.offering.Last()); }