public IActionResult Post([FromBody] Player player) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Player.Add(player); try { _context.SaveChanges(); } catch (DbUpdateException) { if (PlayerExists(player.PlayerId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtRoute("GetPlayer", new { id = player.PlayerId }, player)); }
public ActionResult Create([Bind(Include = "Id,DrinkId,Value")] Rating rating) { if (ModelState.IsValid) { db.Ratings.Add(rating); db.SaveChanges(); double count = 0; double result = 0; IQueryable <Rating> ratings = db.Ratings; ratings = ratings.Where(p => p.DrinkId == rating.DrinkId); foreach (var item in ratings) { count++; result += item.Value; } Drink drink = db.Drinks.Find(rating.DrinkId); double ready = Math.Round(result / count, 1); drink.Rating = ready; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DrinkId = new SelectList(db.Drinks, "Id", "Name", rating.DrinkId); return(View(rating)); }
public ActionResult Create([Bind(Include = "Id,Name")] Type type) { if (ModelState.IsValid) { db.Types.Add(type); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(type)); }
public ActionResult Create([Bind(Include = "Id,Name,TypeId")] Ingredient ingredient) { if (ModelState.IsValid) { db.Ingredients.Add(ingredient); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TypeId = new SelectList(db.Types, "Id", "Name", ingredient.TypeId); return(View(ingredient)); }
public ActionResult Create([Bind(Include = "Id,DrinkId,IngredientId,Amount")] Recipe recipe) { if (ModelState.IsValid) { db.Recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DrinkId = new SelectList(db.Drinks, "Id", "Name", recipe.DrinkId); ViewBag.IngredientId = new SelectList(db.Ingredients, "Id", "Name", recipe.IngredientId); return(View(recipe)); }
public ActionResult Create([Bind(Include = "Id,IngredientId,AttributeId,Value")] AttributeValue attributeValue) { if (ModelState.IsValid) { db.AttributeValues.Add(attributeValue); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AttributeId = new SelectList(db.Attributes, "Id", "Name", attributeValue.AttributeId); ViewBag.IngredientId = new SelectList(db.Ingredients, "Id", "Name", attributeValue.IngredientId); return(View(attributeValue)); }
public ActionResult Create([Bind(Include = "Id,TypeId,AttributeId")] TypeAttribute typeAttribute) { if (ModelState.IsValid) { db.TypeAttributes.Add(typeAttribute); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AttributeId = new SelectList(db.Attributes, "Id", "Name", typeAttribute.AttributeId); ViewBag.TypeId = new SelectList(db.Types, "Id", "Name", typeAttribute.TypeId); return(View(typeAttribute)); }
public ActionResult Create([Bind(Include = "Id,Name,Rating")] Drink drink, HttpPostedFileBase uploadImage) { if (ModelState.IsValid) { if (uploadImage != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } // установка массива байтов drink.Image = imageData; } db.Drinks.Add(drink); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(drink)); }