public RecipeImageBase SelectById(int id) { RecipeImageBase model = new RecipeImageBase(); string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection conn = new SqlConnection(sqlConnectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("dbo.Recipe_SelectById_Create", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", id); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { model = Mapper(reader); } } conn.Close(); } return(model); }
private RecipeImageBase Mapper(SqlDataReader reader) { RecipeImageBase model = new RecipeImageBase(); int index = 0; model.Name = reader.GetString(index++); model.FileId = reader.GetInt32(index++); model.SystemFileName = reader.GetString(index++); return(model); }
public HttpResponseMessage GetBase(int id) { RecipeImageBase model = new RecipeImageBase(); RecipeService svc = new RecipeService(); try { model = svc.SelectById(id); return(Request.CreateResponse(HttpStatusCode.OK, model)); } catch (System.Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }