public int Insert(AmenitiesAddRequest model) //comes from FAQApiController route. we instantiate new userId before running insertFAQ in FAQApiController. { int uid = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.Amenities_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Amenity", model.AmenityName); paramCollection.AddWithValue("@TypeId", model.TypeId); paramCollection.AddWithValue("@Description", model.Description); paramCollection.AddWithValue("@UserId", _userService.GetCurrentUserId()); 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 uid); } ); return(uid); }
public HttpResponseMessage Insert(AmenitiesAddRequest model) { string userId = _userService.GetCurrentUserId(); //this is where the userId is. if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ItemResponse <int> response = new ItemResponse <int>(); response.Item = _service.Insert(model); return(Request.CreateResponse(response)); }