Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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));
            }
        }