public int Add(AddRequest model, string userId) { var id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Courses_Insert_V4", inputParamMapper: delegate(SqlParameterCollection parameterCollection) { parameterCollection.AddWithValue("@CourseName", model.CourseName); parameterCollection.AddWithValue("@Length", model.Length); parameterCollection.AddWithValue("@Description", model.Description); parameterCollection.AddWithValue("@CourseStart", model.Start); parameterCollection.AddWithValue("@CourseEnd", model.End); parameterCollection.AddWithValue("@UserId", userId); parameterCollection.AddWithValue("@LearningObjectives", model.LearningObjectives); parameterCollection.AddWithValue("@ExpectedOutcome", model.ExpectedOutcome); parameterCollection.AddWithValue("@EvaluationCriteria", model.EvaluationCriteria); parameterCollection.AddWithValue("@Format", model.Format); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int) { Direction = System.Data.ParameterDirection.Output }; parameterCollection.Add(p); }, returnParameters: delegate(SqlParameterCollection para) { int.TryParse(para["@Id"].Value.ToString(), out id); } ); foreach (var PrereqId in model.Prereqs) DataProvider.ExecuteNonQuery(GetConnection, "dbo.CoursePrereqs_Insert", inputParamMapper: delegate(SqlParameterCollection param) { param.AddWithValue("@CourseId", id); param.AddWithValue("@PrereqId", PrereqId); }); foreach (var TagId in model.Tags) DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseTags_Insert", inputParamMapper: delegate(SqlParameterCollection param) { param.AddWithValue("@CourseId", id); param.AddWithValue("@TagId", TagId); }); foreach (var Id in model.Instructors) DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseInstructors_Insert", inputParamMapper: delegate(SqlParameterCollection param) { param.AddWithValue("@CourseId", id); param.AddWithValue("@InstructorId", Id); }); return id; }
public HttpResponseMessage CoursesValidation(AddRequest model) { // if the Model does not pass validation, there will be an Error response returned with errors if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } ItemResponse<int> response = new ItemResponse<int>(); string userId = UserService.GetCurrentUserId(); response.Item = _coursesService.Add(model, userId); return Request.CreateResponse(response); }