Exemplo n.º 1
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var ingredient =
                new Ingredient()
            {
                OwnerId        = _userId,
                RecipeId       = model.RecipeId,
                IngredientName = model.IngredientName,
                Directions     = model.Directions,
                Quantity       = model.Quantity,
                CreatedUtc     = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                var addedIngredient = ctx.Ingredients.Add(ingredient);
                ctx.SaveChanges();
                RecipeListService Rls = new RecipeListService(_userId);
                RecipeListCreate  Rlc = new RecipeListCreate
                {
                    RecipeID     = model.RecipeId,
                    IngredientID = addedIngredient.IngredientId
                };

                return(Rls.CreateRecipeList(Rlc));
            }
        }
Exemplo n.º 2
0
        public bool CreateIngredient(IngredientCreate model)
        {
            //ApplicationUser currentUser = new ApplicationUser();

            var entity =
                new Ingredient()
            {
                IngredientOwner    = _userId,
                IngredientName     = model.IngredientName,
                IngredientShared   = model.IngredientShared,
                IngredientQuantity = model.IngredientQuantity,
                IngredientQuantityUnitOfMeasurement = model.IngredientQuantityUnitOfMeasurement,
                Protein       = model.Protein,
                Carbohydrates = model.Carbohydrates,
                Fat           = model.Fat,
                Calories      = model.Calories,
                DietaryFiber  = model.DietaryFiber
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ingredients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity =
                new Ingredient()
            {
                IngredientName = model.IngredientName,
                Description    = model.Description,
                HasGluten      = model.HasGluten,
                HasNuts        = model.HasNuts,
                HasEggs        = model.HasEggs,
                HasSoy         = model.HasSoy,
                HasDairy       = model.HasDairy,
                IsVegan        = model.IsVegan,
                IsVegetarian   = model.IsVegetarian,
                IsPescatarian  = model.IsPescatarian,
                IsKetoFriendly = model.IsKetoFriendly,
                Category       = model.Category
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ingredients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 4
0
        // GET /Ingredient/Create
        // Display CreateView for first, and...
        public ActionResult Create(int id)
        {
            var model = new IngredientCreate()
            {
                LarderId = id
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Create(IngredientCreate model)
        {
            if ((!ModelState.IsValid) ||
                (SaveCreate(model) == false))
            {
                return(View(model));
            }

            return(RedirectToAction("Create", new { id = model.LarderId }));
        }
Exemplo n.º 6
0
        public ActionResult Create(int id)
        {
            var model =
                new IngredientCreate
            {
                RecipeId       = id,
                IngredientName = "",
            };

            return(View(model));
        }
        //ADD INGREDIENT TO GLAZE--------------------------------------------------------------------------------------

        public ActionResult AddIngredientToList(int id)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new MaterialService(userId);
            var model   = new IngredientCreate();

            model.GlazeID     = id;
            model.OwnerId     = userId;
            model.MaterialID  = 1;
            ViewBag.Materials = new SelectList(service.GetMaterial().ToList(), "MaterialID", "MaterialName");
            return(View(model));
        }
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity =
                new Ingredient()
            {
                Name  = model.Name,
                Type  = model.Type,
                Price = model.Price
            };

            _context.Ingredients.Add(entity);
            return(_context.SaveChanges() == 1);
        }
Exemplo n.º 9
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity = new Ingredient()
            {
                IngredientName = model.IngredientName,
                IngredientType = model.IngredientType
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ingredients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 10
0
        public IHttpActionResult Post(IngredientCreate ingredient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!ingredientService.CreateIngredient(ingredient))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemplo n.º 11
0
        private bool SaveCreate(IngredientCreate model)
        {
            var service = CreateIngredientService();

            if (service.CreateIngredient(model))
            {
                TempData["SaveResult"] = "Your ingredient was created.";
                return(true);
            }
            else
            {
                ModelState.AddModelError("", "Ingredient could not be created.");
                return(false);
            }
        }
Exemplo n.º 12
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity =
                new Ingredients()
            {
                Name     = model.Name,
                Quantity = model.Quantity,
                Price    = model.Price,
                UPC      = model.UPC
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ingredients.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        //CREATE method
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity =
                new Ingredient()
            {
                OwnerId     = _userId,
                GlazeID     = model.GlazeID,
                MaterialID  = model.MaterialID,
                Quantity    = model.Quantity,
                CreatedDate = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Ingredient.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 14
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity = new Ingredient()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
                Amount      = model.Amount,
                Unit        = model.Unit,
                LarderId    = model.LarderId,
            };

            using (var context = new CookbookContext())
            {
                context.Ingredients.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Exemplo n.º 15
0
        public ActionResult Create(IngredientCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateIngredientService();


            if (service.CreateIngredient(model))
            {
                TempData["SaveResult"] = "Your ingredient was created.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Ingredient could not be created.");
            return(View(model));
        }
        public ActionResult AddIngredientToList(int id, IngredientCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(ModelState));
            }

            var service = CreateIngredientService();

            if (service.CreateIngredient(model))
            {
                TempData["SaveResult"] = "Your Ingredient was created.";
                return(RedirectToAction("Index"));
            }
            ;

            //RUN SERVICE----------------------------------
            //service.CreateGlazeIngredientList(id, model);

            ////SUBMIT-----------------------------------------
            //if (Request.Form["Add aother ingredient"] != null)
            //{
            //    _db.SaveChanges();

            //    TempData["SaveResult"] = "Your ingredient(s) have been created.";
            //    return RedirectToAction("AddIngredientToList", new { glazeID = model.GlazeIngredientList });

            //}
            ////ADD ANOTHER INGREDIENT----------------------------------
            //if (Request.Form["AddIngredientToList"] != null)
            //{
            //    _db.SaveChanges();

            //    TempData["SaveResult"] = "Your ingredient list has been created.";
            //    return RedirectToAction("Index", new { glazeID = model.GlazeIngredientList });
            //}

            ModelState.AddModelError("", "Ingredients could not be created.");

            return(View(model));
        }