public async Task <IActionResult> CreateCourseOfferingRegistration([FromBody] CourseOfferingRegistrationViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var created = await courseOfferingRegistrationService.CreateCourseOfferingRegistrationAsync(model); return(CreatedAtAction(nameof(GetCourseOfferingRegistrationById), new { courseOfferingRegistrationId = created.Id }, created)); } catch (Exception e) { return(await HandleControllerException(e)); } }
public async Task CanAddALocation() { var toAdd = new CourseOfferingRegistrationViewModel { CourseOfferingId = "1", UserId = "3" }; courseOfferingRegistrationService.Setup(repo => repo.CreateCourseOfferingRegistrationAsync(toAdd)).ReturnsAsync(CreateTestCourseOfferingRegistration(toAdd)); courseOfferingRegistrationService.Setup(repo => repo.GetCourseOfferingRegistrationsAsync()).ReturnsAsync(GetTestCourseOfferingRegistrations()); var result = await controller.GetCourseOfferingRegistrations(); // Assertions Assert.IsInstanceOf <ActionResult <IList <Entities.CourseOfferingRegistration> > >(result); var resultObject = GetObjectResultContent(result); Assert.AreEqual(3, resultObject.Count); }
public async Task <CourseOfferingRegistration> CreateCourseOfferingRegistrationAsync(CourseOfferingRegistrationViewModel model) { try { var courseOfferingRegistration = mapper.Map <CourseOfferingRegistration>(model); var created = await repository.CreateCourseOfferingRegistrationAsync(courseOfferingRegistration); return(await SaveAndReturn(created)); } catch (Exception e) { throw e; } }
private Entities.CourseOfferingRegistration CreateTestCourseOfferingRegistration(CourseOfferingRegistrationViewModel model) { var created = new Entities.CourseOfferingRegistration { Id = "2", CourseOfferingId = model.CourseOfferingId, UserId = model.UserId }; courseOfferingRegistrations.Add(created); return(created); }