예제 #1
0
        public int Add(BlogPageAddRequest model, string UserID)
        {
            int ID = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Blogs_Insert_v2", inputParamMapper: (Action<SqlParameterCollection>)delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Title", model.Title);
                paramCollection.AddWithValue("@Content", model.Content);
                paramCollection.AddWithValue("@MetaData", model.MetaData);
                paramCollection.AddWithValue("@PathName", model.PathName);
                paramCollection.AddWithValue("@LiveDate", model.LiveDate);
                paramCollection.AddWithValue("@Status", model.Status);
                paramCollection.AddWithValue("@UserID", UserID);
                paramCollection.AddWithValue("@Preview", model.Preview);

                AddTags(model.Tags, paramCollection);

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

                paramCollection.Add(b);

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

            }
            );

            return ID;
        }
        public HttpResponseMessage AddBlogPost(BlogPageAddRequest model)
        {
            List<int> newTags = null;
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            string userId = _userService.GetCurrentUserId();

            if (model.NewTags != null && model.NewTags.Any())
            {
                newTags = new List<int>();
                newTags = TagsService.AddMultiple(model.NewTags, true);

                if (model.Tags == null)
                {
                    model.Tags = new List<int>();
                }

                foreach (var item in newTags)
                {
                    model.Tags.Add(item);
                }
            }

            ItemResponse<Int32> response = new ItemResponse<Int32>();
            response.Item = _blogService.Add(model, userId);

            return Request.CreateResponse(response);
        }