public HttpResponseMessage EditCourses(CourseUpdateRequest model, int id)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SucessResponse response = new SucessResponse();
            _coursesService.Update(model);
            return Request.CreateResponse(response);
        }
Esempio n. 2
0
        public void Update(CourseUpdateRequest model)
        {
            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Courses_Update2",
                inputParamMapper: delegate(SqlParameterCollection updateCourse)
                {
                    updateCourse.AddWithValue("@Id", model.Id);
                    updateCourse.AddWithValue("@CourseName", model.CourseName);
                    updateCourse.AddWithValue("@Length", model.Length);
                    updateCourse.AddWithValue("@Description", model.Description);
                    updateCourse.AddWithValue("@CourseStart", model.Start);
                    updateCourse.AddWithValue("@CourseEnd", model.End);
                    updateCourse.AddWithValue("@LearningObjectives", model.LearningObjectives);
                    updateCourse.AddWithValue("@ExpectedOutcome", model.ExpectedOutcome);
                    updateCourse.AddWithValue("@EvaluationCriteria", model.EvaluationCriteria);
                    updateCourse.AddWithValue("@Format", model.Format);

                });

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CoursePrereqs_DeleteByCourseId",
                inputParamMapper: delegate(SqlParameterCollection parameterCollection)
                {
                    parameterCollection.AddWithValue("@CourseId", model.Id);
                });
            foreach (var PrereqId in model.Prereqs)
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CoursePrereqs_Insert",
                    inputParamMapper: delegate(SqlParameterCollection param)
                    {
                        param.AddWithValue("@CourseId", model.Id);
                        param.AddWithValue("@PrereqId", PrereqId);
                    });

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseTags_DeleteByCourseId",
                inputParamMapper: delegate(SqlParameterCollection parameterCollection)
                {
                    parameterCollection.AddWithValue("@CourseId", model.Id);
                });
            foreach (var TagId in model.Tags)
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseTags_Insert",
                    inputParamMapper: delegate(SqlParameterCollection param)
                    {
                        param.AddWithValue("@CourseId", model.Id);
                        param.AddWithValue("@TagId", TagId);
                });

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseInstructors_DeleteByCourseId",
                inputParamMapper: delegate(SqlParameterCollection parameterCollection)
                {
                    parameterCollection.AddWithValue("@CourseId", model.Id);
                });
            foreach (var instructorId in model.Instructors)
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.CourseInstructors_Insert",
                    inputParamMapper: delegate(SqlParameterCollection param)
                    {
                        param.AddWithValue("@CourseId", model.Id);
                        param.AddWithValue("@InstructorId", instructorId);
                    });
        }