Exemplo n.º 1
0
        public IHttpActionResult PostCustomIngredient(CustomIngredientModel customIngredientModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customIngredient = new CustomIngredient(); //CustomIngredientRepository.CreateInstanceList();

            customIngredient = ObjectFactory.Parse(customIngredientModel, customIngredient);

            _customIngredientService.Add(customIngredient);
            db.SaveChanges();

            var newCustomIngredient        = _customIngredientService.GetCustomIngredientById(customIngredient.Id);
            var newCustomIngredientsModels = ModelFactory.Create(newCustomIngredient);

            return(CreatedAtRoute("DefaultApi", new { id = newCustomIngredient.Id }, newCustomIngredient));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostRecipeIngredient(int recipeId, IEnumerable <RecipeIngredientModel> recipeIngredientModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var recipeIngredients = new List <RecipeIngredient>();

            recipeIngredients = ObjectFactory.Parse(recipeIngredientModels, recipeIngredients).ToList();

            _recipeIngredientService.AddList(recipeId, recipeIngredients);

            db.SaveChanges();

            var newRecipes = _recipeIngredientService.GetRecipeIngredients(recipeIngredients);
            var newRecipeIngredientModels = ModelFactory.Create(newRecipes);

            return(Ok(newRecipeIngredientModels));
        }
        public IHttpActionResult PostDirection(IEnumerable <DirectionModel> directionModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var directions = new List <Direction>();

            directions = ObjectFactory.Parse(directionModels, directions).ToList();

            _directionService.AddList(directions);

            db.SaveChanges();

            var newDirections       = _directionService.GetDirections(directions);
            var newDirectionsModels = ModelFactory.Create(newDirections);

            return(Ok(newDirectionsModels));
        }
Exemplo n.º 4
0
        public IHttpActionResult PutIngredient(int id, IngredientModel ingredientModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ingredientModel.Id)
            {
                return(BadRequest());
            }

            var ingredient = _ingredientService.GetIngredientById(id);

            ObjectFactory.Parse(ingredientModel, ingredient);

            _ingredientService.Update(ingredient);
            db.SaveChanges();

            return(Ok());
            //return CreatedAtRoute("DefaultApi", new { id = ingredient.Id }, ingredient);
        }
Exemplo n.º 5
0
        public IHttpActionResult PutRecipe(int id, RecipeModel recipeModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipeModel.Id)
            {
                return(StatusCode(HttpStatusCode.NotAcceptable));
            }

            //var recipe = new Recipe();
            var recipe = _recipeService.GetRecipeById(id);

            ObjectFactory.Parse(recipeModel, recipe);

            _recipeService.Update(recipe);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = recipe.Id }, recipe));
        }
        public IHttpActionResult PostGroceryCategory(IngredientCategoryModel ingredientCategoryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ingredientCategory = new IngredientCategory();

            ObjectFactory.Parse(ingredientCategoryModel, ingredientCategory);

            _ingredientCategoryService.Add(ingredientCategory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = ingredientCategory.Id }, ingredientCategory));
        }
 public void Update(CustomIngredient customIngredient)
 {
     _db.Entry(customIngredient).State = EntityState.Modified;
     _db.SaveChanges();
 }