public ActionResult <IngredientDto> GetIngredient(int ingredientId) { var ingredientFromRepo = _ingredientRepository.GetIngredient(ingredientId); if (ingredientFromRepo == null) { return(NotFound()); } var ingredientDto = _mapper.Map <IngredientDto>(ingredientFromRepo); return(Ok(ingredientDto)); }
//[Authorize(Policy = PermissionsList.PermissionsIngredientAdd)] public IActionResult AddIngredient([FromBody] IngredientModel ingredientModel) { Guid ingredientId = Guid.NewGuid(); var ingredientExist = _ingredientRepository.GetIngredient(ingredientModel.Name); if (!ModelState.IsValid || ingredientExist.Result != null) { return(BadRequest()); } Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientModel.Name, Quantity = ingredientModel.Quantity, Price = ingredientModel.Price, ExpirationDate = ingredientModel.ExpirationDate }; _ingredientRepository.Create(ingredient); return(Ok(new { ingredient })); }
public Task AddIngredient(IngredientModel ingredientModel) { Guid ingredientId = Guid.NewGuid(); var ingredientExist = _ingredientRepository.GetIngredient(ingredientModel.Name).Result; var ingredientsOld = _ingredientRepository.GetAll().Result; if (ingredientExist != null) { return(Clients.All.SendAsync("GetIngredients", ingredientsOld)); } Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientModel.Name, Quantity = ingredientModel.Quantity, Price = ingredientModel.Price, ExpirationDate = ingredientModel.ExpirationDate }; _ingredientRepository.Create(ingredient); var ingredients = _ingredientRepository.GetAll().Result; return(Clients.All.SendAsync("GetIngredients", ingredients)); }
public ActionResult <Ingredient> Get(int id) { var ingredient = _ingredientRepository.GetIngredient(id); _log.Info("Getting a ingredient by id."); return(ingredient); }
public IActionResult GetIngredientById(int ingredientId) { var ingredient = _ingredientRepository.GetIngredient(ingredientId); if (ingredient == null) { ModelState.AddModelError("", "Error getting a category"); ViewBag.Message = $"There was a problem retrieving ingredient with id {ingredientId} " + $"from the database or no ingredient with that id exists"; ingredient = new IngredientDto(); } return(View(ingredient)); }
public int CopyIngredient(int ingredientId) { var model = _ingredientRepository.GetIngredient(ingredientId); var newIngredient = new Ingredient() { ItemId = model.ItemId, //Unit = model.Unit, Measure = null }; int newid = _ingredientRepository.Add(newIngredient); return(newid); }
public IActionResult GetIngredient(int ingredientId) { if (!_ingredientRepository.IngredientExists(ingredientId)) { return(NotFound()); } var ingredient = _ingredientRepository.GetIngredient(ingredientId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ingredientDto = new IngredientDto() { Id = ingredient.Id, Name = ingredient.Name, Quantity = ingredient.Quantity }; return(Ok(ingredientDto)); }
public async Task <IActionResult> Details(Guid guid) { try { var result = await _iIngredientRepository.GetIngredient(guid); if (result == null) { return(NotFound()); } return(Ok(result)); } catch (Exception) { return(BadRequest()); } }
public Ingredient GetIngredient(int id) { return(_potionRepo.GetIngredient(id)); }
public IActionResult Edit(int Id) { var model = _ingredientRepository.GetIngredient(Id); return(View(model)); }