Exemplo n.º 1
0
        public async Task <bool> PutRecipe(long id, Recipe recipe)
        {
            _context.Entry(recipe).State = EntityState.Modified;

            foreach (var recipeIngredientMeasurement in recipe.RecipeIngredientMeasurement)
            {
                _context.Entry(recipeIngredientMeasurement.Ingredient).State  = EntityState.Modified;
                _context.Entry(recipeIngredientMeasurement.Measurement).State = EntityState.Modified;
            }

            foreach (var recipeTool in recipe.RecipeTool)
            {
                _context.Entry(recipeTool.Tool).State = EntityState.Modified;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }

            return(true);
        }
        public async Task <IActionResult> PutRecipeIngredient(int id, RecipeIngredient recipeIngredient)
        {
            if (id != recipeIngredient.RecipeId)
            {
                return(BadRequest());
            }

            _context.Entry(recipeIngredient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeIngredientExists(id, recipeIngredient.IngredientId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
 public void Delete(TEntity entityToDelete)
 {
     if (_context.Entry(entityToDelete).State == EntityState.Detached)
     {
         _dbSet.Attach(entityToDelete);
     }
     _dbSet.Remove(entityToDelete);
 }
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.ID)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutKey([FromRoute] string id, [FromBody] Key key)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != key.Name)
            {
                return(BadRequest());
            }

            _context.Entry(key).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KeyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 6
0
        public IHttpActionResult PutCategory(long id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

            db.Entry(category).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> PutIngredient(long id, Ingredient ingredient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ingredient.IngredientId)
            {
                return(BadRequest());
            }

            db.Entry(ingredient).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IngredientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Put(UserShoppingList userIngredient)
        {
            _context.Entry(userIngredient).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PutReview(string userId, int recipeId, Review review)
        {
            if (userId != review.AppUserId || recipeId != review.RecipeId)
            {
                return(BadRequest());
            }

            if (!ReviewExists(userId, recipeId))
            {
                await PostReview(review);
            }
            else
            {
                _context.Entry(review).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException e)
                {
                    throw e;
                }
            }

            return(CreatedAtAction("GetReview", new { appUserId = review.AppUserId, recipeId = review.RecipeId }, review));
        }
Exemplo n.º 10
0
        public ActionResult EditRecipe(int?id, string[] selectedIngredients, string[] quantity, string[] quantityType)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Recipe recipeToUpdate = db.Recipes.Find(id);
            Recipe recipeToUpdate = db.Recipes
                                    .Include(i => i.RecipeIngredientXrefs)
                                    .Where(i => i.ID == id)
                                    .Single();

            if (TryUpdateModel(recipeToUpdate, "",
                               new string[] { "Name", "Category", "Description" }))
            {
                try
                {
                    recipeToUpdate.DateUpdated     = System.DateTime.Now;
                    db.Entry(recipeToUpdate).State = EntityState.Modified;

                    UpdateRecipeIngredients(selectedIngredients, recipeToUpdate, quantity, quantityType);

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException dex)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", dex.Message);
                }
            }
            PopulateAssignedIngredientsData(recipeToUpdate);
            return(View(recipeToUpdate));
        }
        public async Task <IActionResult> PutFavouriteRecipe(string userId, int recipeId, FavouriteRecipe favouriteRecipe)
        {
            if (userId != favouriteRecipe.AppUserId || recipeId != favouriteRecipe.RecipeId)
            {
                return(BadRequest());
            }

            _context.Entry(favouriteRecipe).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FavouriteRecipeExists(userId, recipeId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 12
0
        public IHttpActionResult PutRecipe(long id, RecipeDal.Recipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipe.RecipeId)
            {
                return(BadRequest());
            }

            db.Entry(recipe).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> PutItem(int id, Item item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Put(User user)
        {
            _context.Entry(user).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemplo n.º 15
0
        public async Task <StatusCodeResult> AddDownloadURL(Recipe r)
        {
            _context.recipe.Attach(r);
            _context.Entry(r).Property(x => x.ImagePath).IsModified = true;
            await _context.SaveChangesAsync();

            return(new StatusCodeResult(200));
        }
Exemplo n.º 16
0
        public void Editor(Recipe rec)
        {
            db.Entry(rec).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            string s = "~/Home/About/" + rec.Id.ToString();

            Response.Redirect(s);
        }
Exemplo n.º 17
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(recipe));
 }
Exemplo n.º 18
0
 public ActionResult Edit([Bind(Include = "IngedientID,IngredientName")] Ingredient ingredient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ingredient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ingredient));
 }
Exemplo n.º 19
0
 public ActionResult Edit([Bind(Include = "ID,Name,EngName,CookingTime,MainImageUrl,PortionMinWeight,Weight,AudioStartUrl")] Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(recipe));
 }
Exemplo n.º 20
0
 public ActionResult Edit([Bind(Include = "Id,ToolCode,ToolName,MachineId,WerkzeughoeheA1,WerkzeughoeheA2,HeizelementhoeheObenA3,HeizelementhoeheUntenA3,WarmpositionA3,BestueckungspositionA1,BestueckungspositionA2,PruefpositionA1,PruefpositionA2,IRKameraTriggerpositionA3")] DatMWerkzeug datMWerkzeug)
 {
     if (ModelState.IsValid)
     {
         db.Entry(datMWerkzeug).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(datMWerkzeug));
 }
Exemplo n.º 21
0
 public ActionResult Edit([Bind(Include = "ID,Name,EngName")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "Id,HK01,HK02,HK03,HK04,HK05,HK06,HK07,HK08,HK09,HK10,HK11,HK12,HK13,HK14,HK15,HK16,HK17,HK18,HK19,HK20,HK21,HK22,HK23,HK24")] DatHE datHE)
 {
     if (ModelState.IsValid)
     {
         db.Entry(datHE).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(datHE));
 }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "Id,ToolCode,ToolName,Propventil01,Propventil02,Propventil03,Propventil04,Propventil05,Propventil06,Propventil07,Propventil08,Propventil09,Propventil10,Propventil11,Propventil12,Propventil13,Propventil14,Propventil15,Propventil16,Propventil17,Propventil18,Propventil19,Propventil20,Propventil21,Propventil22,Propventil23,Propventil24,Propventil25,Propventil26,Propventil27,Propventil28,Propventil29,Propventil30,Propventil31,Propventil32,Propventil33,Propventil34,Propventil35,Propventil36,Propventil37,Propventil38,Propventil39,Propventil40,Propventil41,Propventil42,Propventil43,Propventil44,Propventil45,Propventil46,Propventil47,Propventil48,Propventil49,Propventil50,Propventil51,Propventil52,Propventil53,Propventil54,Propventil55,Propventil56,Propventil57,Propventil58,Propventil59,Propventil60")] DatN2 datN2)
 {
     if (ModelState.IsValid)
     {
         db.Entry(datN2).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(datN2));
 }
 public ActionResult Edit([Bind(Include = "Id,ToolCode,ToolName")] DatWerkzeug datWerkzeug)
 {
     if (ModelState.IsValid)
     {
         db.Entry(datWerkzeug).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(datWerkzeug));
 }
Exemplo n.º 25
0
 public ActionResult Edit([Bind(Include = "UserID,Username,Password,Email")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemplo n.º 26
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Calories,TotalIngrediance,TotalCookTime")] Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(recipe));
 }
Exemplo n.º 27
0
 public ActionResult Edit([Bind(Include = "RecipeID,RecipeTitle,Steps,PrepTime,CookTime,Servings,MealType")] Recipe recipe)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recipe).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(recipe));
 }
Exemplo n.º 28
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Type,Ingridient,Cooking")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                db.Entry(recipe).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(recipe));
        }
Exemplo n.º 29
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,Name,EngName,Pieces,NamePieces,EngNamePieces,Teaspoon,Tablespoon")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ingredient).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(ingredient));
        }
Exemplo n.º 30
0
 public ActionResult Edit([Bind(Include = "ID,Title,Body")] Post post)
 {
     if (ModelState.IsValid)
     {
         //post.DateUpdated = System.DateTime.Now;
         db.Entry(post).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(post));
 }