コード例 #1
0
        public Int32 Add(EventFormAddRequest model, string userId)
        {
            Int32 id = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Events_Insert"
               , inputParamMapper: delegate (SqlParameterCollection paramCollection)
               {
                   paramCollection.AddWithValue("@Title", model.Title);
                   paramCollection.AddWithValue("@Description", model.Description);
                   paramCollection.AddWithValue("@EventTime", model.EventTime);
                   paramCollection.AddWithValue("@VenueName", model.VenueName);
                   paramCollection.AddWithValue("@Url", model.Url);
                   paramCollection.AddWithValue("@Type", model.Type);
                   paramCollection.AddWithValue("@Tags", model.Tags);
                   paramCollection.AddWithValue("@Userid", userId);

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

                   paramCollection.Add(p);

               }, returnParameters: delegate (SqlParameterCollection param)
               {
                   Int32.TryParse(param["@Id"].Value.ToString(), out id);
               }
               );

            return id;
        }
コード例 #2
0
        public HttpResponseMessage AddEvent(EventFormAddRequest 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);
            }

            string userId = _userService.GetCurrentUserId();
            ItemResponse<Int32> response = new ItemResponse<Int32>();

            response.Item = _eventsService.Add(model, userId);

            return Request.CreateResponse(response);
        }