Ejemplo n.º 1
0
        public HttpResponseMessage Add(TrackAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            ItemResponse<int> response = new ItemResponse<int>();
            //grabbing the ID that is currently assgined to UserService (current user)
            //this is where you get the current userId

            response.Item = _trackService.Add(model);

            return Request.CreateResponse(response);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Add(TrackAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();

            //grabbing the ID that is currently assgined to UserService (current user)
            //this is where you get the current userId

            response.Item = _trackService.Add(model);

            return(Request.CreateResponse(response));
        }
Ejemplo n.º 3
0
        public int Add(TrackAddRequest model)
        {
            var id = 0;

            //connecting to SQL server, which will call the database and the stored procedure
            //1 database call = get connection with stored procedure below "CourseTrack_Insert"

            //ADO is a library of code that is used to communicate wiht the database
            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Tracks_Insert",
                //(SQLparam)suitcase of data that the .NET will populate and send to the server
                //inline function in .NET(delegate)
                //Delegate x = fx()} delegate points to a function.
                //type                  //Name
                inputParamMapper: delegate(SqlParameterCollection parameterCollection)
                {
                    parameterCollection.AddWithValue("@Name", model.Name);
                    parameterCollection.AddWithValue("@Format", model.Format);
                    parameterCollection.AddWithValue("@ExpectedOutcome", model.ExpectedOutCome);
                    parameterCollection.AddWithValue("@Cost", model.Cost);
                    parameterCollection.AddWithValue("@Description", model.Description);

                    SqlParameter s = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                    s.Direction = System.Data.ParameterDirection.Output;
                    parameterCollection.Add(s);

                },

                returnParameters: delegate(SqlParameterCollection para)
                {                   //this will come from the database server
                    int.TryParse(para["@Id"].Value.ToString(), out id);
                }
                //when using the insert method in REST Client the intent is to see that Id will return a value to the user.
                );

            foreach (var courseId in model.CourseIds)
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.TrackCourses_Insert",
                    delegate(SqlParameterCollection para)
                    {
                        para.AddWithValue("@TracksId", id);
                        para.AddWithValue("@CourseId", courseId);

                    });
            }
            return id;
        }
Ejemplo n.º 4
0
        public int Add(TrackAddRequest model)
        {
            var id = 0;

            //connecting to SQL server, which will call the database and the stored procedure
            //1 database call = get connection with stored procedure below "CourseTrack_Insert"

            //ADO is a library of code that is used to communicate wiht the database
            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Tracks_Insert",
                                         //(SQLparam)suitcase of data that the .NET will populate and send to the server
                                         //inline function in .NET(delegate)
                                         //Delegate x = fx()} delegate points to a function.
                                         //type                  //Name
                                         inputParamMapper : delegate(SqlParameterCollection parameterCollection)
            {
                parameterCollection.AddWithValue("@Name", model.Name);
                parameterCollection.AddWithValue("@Format", model.Format);
                parameterCollection.AddWithValue("@ExpectedOutcome", model.ExpectedOutCome);
                parameterCollection.AddWithValue("@Cost", model.Cost);
                parameterCollection.AddWithValue("@Description", model.Description);

                SqlParameter s = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                s.Direction    = System.Data.ParameterDirection.Output;
                parameterCollection.Add(s);
            },

                                         returnParameters : delegate(SqlParameterCollection para)
            {                       //this will come from the database server
                int.TryParse(para["@Id"].Value.ToString(), out id);
            }
                                         //when using the insert method in REST Client the intent is to see that Id will return a value to the user.
                                         );

            foreach (var courseId in model.CourseIds)
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.TrackCourses_Insert",
                                             delegate(SqlParameterCollection para)
                {
                    para.AddWithValue("@TracksId", id);
                    para.AddWithValue("@CourseId", courseId);
                });
            }
            return(id);
        }