public HttpResponseMessage AddPlan(PlansAddRequest model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (model.Tag != null) { TagsAddRequest tagRequest = new TagsAddRequest(model.Tag); int tagId = _tagsService.Add(tagRequest); model.TagId = tagId; } string UserId = _userService.GetCurrentUserId(); ItemResponse<int> response = new ItemResponse<int>(); response.Item = _plansService.Insert(model, UserId); return Request.CreateResponse(response); }
public int Insert(PlansAddRequest model, string UserId) { int id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Plans_Insert_v2" , inputParamMapper: delegate (SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Name", model.Name); paramCollection.AddWithValue("@Description", model.Description); paramCollection.AddWithValue("@Types", model.Types); paramCollection.AddWithValue("@Cost", model.Cost); paramCollection.AddWithValue("@GoLiveDate", model.GoLiveDate); paramCollection.AddWithValue("@Tag", model.Tag); paramCollection.AddWithValue("@TagId", model.TagId); 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); } ); return id; }