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));
        }
Ejemplo n.º 2
0
        //[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 }));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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));
        }