public async Task <IActionResult> Update([FromRoute] string id, [FromBody] TypeOfIngredient ingredient) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var item = unitOfWork.TypeOfIngredientRepository.GetItemByID(id); if (item == null) { return(NotFound()); } item.Name = ingredient.Name; item.Price = ingredient.Price; item.IsDeleted = ingredient.IsDeleted; unitOfWork.TypeOfIngredientRepository.UpdateItem(item); unitOfWork.Save(); return(NoContent()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public TypeOfIngredient Add(TypeOfIngredient item) { var newTypeOfIngredient = (TypeOfIngredient)item.Clone(); newTypeOfIngredient.Id = !_types.Any() ? 1 : _types.Max(rate => rate.Id) + 1; _types.Add(newTypeOfIngredient); return((TypeOfIngredient)newTypeOfIngredient.Clone()); }
public TypeOfIngredient UseFood() { TypeOfIngredient foodToUse = TypeOfIngredient.EMPTY; if (inventory.Count > 0) { foodToUse = inventory[0]; inventory.RemoveAt(0); } return(foodToUse); }
public TypeOfIngredient Update(TypeOfIngredient item) { var existTypeOfIngredient = _types.SingleOrDefault(type => type.Id == item.Id); if (existTypeOfIngredient == null) { throw new NullReferenceException(); } existTypeOfIngredient.Name = item.Name; return((TypeOfIngredient)existTypeOfIngredient.Clone()); }
public bool AddFood(TypeOfIngredient foodToAdd) { if (inventory.Count < 3) { inventory.Add(foodToAdd); } else { return(false); } return(true); }
public void AddTest() { var name = Guid.NewGuid().ToString(); var newTypeOfIngredient = new TypeOfIngredient { Name = name }; var AddedTypeOfIngredient = service.Add(newTypeOfIngredient); Assert.IsNotNull(AddedTypeOfIngredient); Assert.IsTrue(AddedTypeOfIngredient.Id > 0); Assert.AreEqual(AddedTypeOfIngredient.Name, name); }
private void FireFood() { TypeOfIngredient foodToFire = inventory.UseFood(); if (foodToFire != TypeOfIngredient.EMPTY) { GameObject firedFood = Instantiate(foodPrefab, Camera.main.transform.position + Camera.main.transform.forward * 3.0f, Camera.main.transform.rotation); firedFood.GetComponentInChildren <SpriteRenderer>().sprite = FoodSpriteData.GetSprite((int)foodToFire); firedFood.GetComponent <IngredientIdentifier>().SetFoodType(foodToFire); firedFood.GetComponent <Rigidbody>().AddForce(Camera.main.transform.forward * firingPower, ForceMode.Impulse); } }
public async Task <IActionResult> Create([FromBody] TypeOfIngredient ingredient) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } unitOfWork.TypeOfIngredientRepository.InsertItem(ingredient); unitOfWork.Save(); return(CreatedAtAction("GetPizza", new { id = ingredient.Id }, ingredient)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Create(CreatePizzaViewModel pizzaResponse, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { string pic = Path.GetFileName(file.FileName); string path = Path.Combine( Server.MapPath("~/Content/Images"), pic); // file is uploaded file.SaveAs(path); // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } pizzaResponse.ImgUrl = "/Content/Images/" + pic; } else { pizzaResponse.ImgUrl = "/Content/Images/CustomPizza.png"; } repository.CreatePizzaForUser(pizzaResponse, User.Identity.GetUserId()); if (User.IsInRole(UserRoles.User)) { ViewBag.Title = "These are your custom pizzas"; return(RedirectToAction("MyPizzas")); } ViewBag.Title = "Barka 5's Menu"; return(RedirectToAction("Index")); } foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType))) { pizzaResponse.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient)); } return(View(pizzaResponse)); }
private CreatePizzaViewModel setupCreateOrEditViewModel(Guid?id) { CreatePizzaViewModel viewModel = new CreatePizzaViewModel(); if (id != null) { var a = id; var pizzaToEdit = repository.GetPizza(id); viewModel.PizzaId = id; foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType))) { viewModel.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient)); } viewModel.selectedIngredients = repository.GetIngredientsForPizza(id) .Select(x => x.IngredientId.ToString()) .ToList(); viewModel.Name = pizzaToEdit.Name; viewModel.IncomeCoef = pizzaToEdit.incomeCoeficient; viewModel.Size = pizzaToEdit.Size; viewModel.ImgUrl = pizzaToEdit.ImgUrl; } else { foreach (var TypeOfIngredient in Enum.GetValues(typeof(IngredientType))) { viewModel.TypeIngredientListPairs.Add(TypeOfIngredient.ToString(), repository.GetIngredientsByType((IngredientType)TypeOfIngredient)); } } return(viewModel); }
public void SetFoodType(TypeOfIngredient type) { ingredientType = type; }