public IHttpActionResult Post(EnrollmentCreate enrollments) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateEnrollmentService(); if (!service.CreateEnrollment(enrollments)) { return(InternalServerError()); } return(Ok()); }
public bool CreateEnrollment(EnrollmentCreate model) { var entity = new Enrollment() { UserID = model.UserID, ActivityID = model.ActivityID, }; using (var ctx = new ApplicationDbContext()) { ctx.Enrollments.Add(entity); return(ctx.SaveChanges() == 1); } }