Example #1
0
        public RecipeDomain GetRecipeByRecipeId(int RecipeId)
        {
            RecipeDomain     RecipeDomain     = null;
            MediaDomain      MediaDomain      = null;
            IngredientDomain IngredientDomain = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Recipes_GetByRecipeId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramcollection)
            {
                paramcollection.AddWithValue("@Id", RecipeId);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    int startingIndex = 0;

                    RecipeDomain = new RecipeDomain();

                    RecipeDomain.Id               = reader.GetSafeInt32(startingIndex++);
                    RecipeDomain.CreatedDate      = reader.GetSafeDateTime(startingIndex++);
                    RecipeDomain.Name             = reader.GetSafeString(startingIndex++);
                    RecipeDomain.Description      = reader.GetSafeString(startingIndex++);
                    RecipeDomain.Directions       = reader.GetSafeString(startingIndex++);
                    RecipeDomain.Preptime         = reader.GetSafeInt32(startingIndex++);
                    RecipeDomain.Totaltime        = reader.GetSafeInt32(startingIndex++);
                    RecipeDomain.NumberOfServings = reader.GetSafeInt32(startingIndex++);
                    RecipeDomain.UserId           = reader.GetSafeString(startingIndex++);

                    MediaDomain = new MediaDomain();

                    MediaDomain.Id       = reader.GetSafeInt32(startingIndex++);
                    MediaDomain.DataType = reader.GetSafeString(startingIndex++);
                    MediaDomain.Url      = reader.GetSafeString(startingIndex++);
                    MediaDomain.Created  = reader.GetSafeDateTime(startingIndex++);

                    RecipeDomain.Media = MediaDomain;

                    if (RecipeDomain == null)
                    {
                        RecipeDomain = new RecipeDomain();
                    }
                }
                else if (set == 1)
                {
                    IngredientDomain = new IngredientDomain();

                    int startingIndex                = 0;
                    IngredientDomain.Id              = reader.GetSafeInt32(startingIndex++);
                    IngredientDomain.RecipeId        = reader.GetSafeInt32(startingIndex++);
                    IngredientDomain.Name            = reader.GetSafeString(startingIndex++);
                    IngredientDomain.MeasurementType = reader.GetSafeEnum <IngredientMeasurementType>(startingIndex++);
                    IngredientDomain.Quantity        = reader.GetSafeInt32(startingIndex++);

                    RecipeDomain.Ingredients.Add(IngredientDomain);
                }
            });

            return(RecipeDomain);
        }
        private void btnFind_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Enter the Recipe Id in the textbox and click Find button", "Find Recipe", MessageBoxButtons.OK, MessageBoxIcon.Information);

            currentRecipeDomain      = RecipeService.GetEntityById(int.Parse(txtRecipeId.Text));
            txtRecipeId.Text         = currentRecipeDomain?.RecipeId.ToString();
            txtRecipeName.Text       = currentRecipeDomain?.RecipeName;
            txtRecipeCategoryId.Text = currentRecipeDomain?.CategoryId.ToString();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            RecipeDomain recipe = new RecipeDomain()
            {
                RecipeName = textBox1.Text,
                CategoryId = Convert.ToInt32(numericUpDown1.Value)
            };

            RecipeService.Insert(recipe);
            RecipeService.Save();
        }
Example #4
0
        public HttpResponseMessage GetRecipeByRecipeId(int recipeid)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            RecipeDomain Recipe = _RecipesService.GetRecipeByRecipeId(recipeid);

            ItemResponse <RecipeDomain> Response = new ItemResponse <RecipeDomain>();

            Response.Item = Recipe;

            return(Request.CreateResponse(HttpStatusCode.OK, Response));
        }
Example #5
0
        //Get
        public List <RecipeDomain> GetRecipesByUserId(string UserId)
        {
            List <RecipeDomain> ListRecipeDomain = null;
            MediaDomain         MediaDomain      = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Recipes_GetAllRecipesByUserId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramcollection)
            {
                paramcollection.AddWithValue("@userid", UserId);
            }, map : delegate(IDataReader reader, short set)
            {
                RecipeDomain p    = new RecipeDomain();
                int startingIndex = 0;
                p.Id               = reader.GetSafeInt32(startingIndex++);
                p.CreatedDate      = reader.GetSafeDateTime(startingIndex++);
                p.Name             = reader.GetSafeString(startingIndex++);
                p.Directions       = reader.GetSafeString(startingIndex++);
                p.Preptime         = reader.GetSafeInt32(startingIndex++);
                p.Totaltime        = reader.GetSafeInt32(startingIndex++);
                p.NumberOfServings = reader.GetSafeInt32(startingIndex++);
                p.Description      = reader.GetSafeString(startingIndex++);

                MediaDomain = new MediaDomain();

                MediaDomain.Id       = reader.GetSafeInt32(startingIndex++);
                MediaDomain.DataType = reader.GetSafeString(startingIndex++);
                MediaDomain.Url      = reader.GetSafeString(startingIndex++);
                MediaDomain.Created  = reader.GetSafeDateTime(startingIndex++);

                p.Media = MediaDomain;

                if (ListRecipeDomain == null)
                {
                    ListRecipeDomain = new List <RecipeDomain>();
                }
                ListRecipeDomain.Add(p);
            });

            return(ListRecipeDomain);
        }