示例#1
0
        public static int Add(WikiAddRequest model, string userId)
        {
            int Id = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.WikiPages_Insert"
                , inputParamMapper: delegate (SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@UserId", userId);
                    paramCollection.AddWithValue("@Name", model.Title);
                    paramCollection.AddWithValue("@URL", model.URL);
                    paramCollection.AddWithValue("@PublishDate", model.PublishDate);
                    paramCollection.AddWithValue("@Language", model.Language);
                    paramCollection.AddWithValue("@LastModifiedByUserId", userId);

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

                    paramCollection.Add(p);

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

            //foreach (var wikiSpaceId in model.WikiSpaceIds)
            //    DataProvider.ExecuteNonQuery(GetConnection, "dbo.WikiPageSpaces_Insert"
            //        , inputParamMapper: delegate (SqlParameterCollection param)
            //        {
            //            param.AddWithValue("@WikiPageId", Id);
            //            param.AddWithValue("@WikiSpaceId", wikiSpaceId);
            //        });
            return Id;
        }
        public HttpResponseMessage Add(WikiAddRequest 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 = WikiService.Add(model, userId);
            return Request.CreateResponse(response);
        }