private void LoadAssignedIngredients()
        {
            var assignedIngredients = _formulationIngredientRepository.GetByFormulationId(_formulationBusinessModel.Id);

            AssignedIngredientBusinessModels.Clear();

            foreach (var ingredient in assignedIngredients)
            {
                var ingredientModel = _ingredientRepository.GetById(ingredient.IngredientId);
                AssignedIngredientBusinessModels.Add(new FormulationIngredientBusinessModel(ingredient, ingredientModel));
            }
        }
예제 #2
0
        public object Handle(OrderCommand command)
        {
            if (command.Snacks.Count > 0)
            {
                var order = new Order(Guid.Empty);

                foreach (var snackCommand in command.Snacks)
                {
                    var snackDb  = _snackRepository.GetById(snackCommand.Id);
                    var newSnack = new Snack(snackDb.Id, snackDb.Name);

                    if (snackDb != null)
                    {
                        if (snackCommand.Ingredients.Count != 0)
                        {
                            foreach (var item in snackCommand.Ingredients)
                            {
                                var ingredient = _ingredientRepository.GetById(item.IngredientId);
                                newSnack.AddIngredient(ingredient, item.Quantity);
                            }

                            newSnack.CalculatePrice();
                            order.AddSnack(newSnack);
                        }
                    }
                }

                _orderRepository.Save(order);
                return(order);
            }

            return(null);
        }
예제 #3
0
        //[Authorize(Policy = PermissionsList.PermissionsIngredientUpdate)]
        public Task UpdateIngredient(IngredientModel ingredientModel)
        {
            Guid ingredientId = Guid.Parse(ingredientModel.Id);



            Ingredient ingredient = _ingredientRepository.GetById(ingredientId).Result;

            ingredient.Name           = ingredientModel.Name;
            ingredient.Quantity       = ingredientModel.Quantity;
            ingredient.Price          = ingredientModel.Price;
            ingredient.ExpirationDate = ingredientModel.ExpirationDate;

            _ingredientRepository.Update(ingredient);

            var ingredients = _ingredientRepository.GetAll().Result;

            return(Clients.All.SendAsync("GetIngredients", ingredients));
        }
        private void IngredientSelected(SelectedMessage <IngredientWrapper> message)
        {
            var ingredientDetail = _ingredientRepository.GetById(message.Id);

            Model = new IngredientAmountDetailModel
            {
                IngredientId          = ingredientDetail.Id,
                IngredientName        = ingredientDetail.Name,
                IngredientDescription = ingredientDetail.Description
            };
        }
예제 #5
0
        //[Authorize(Policy = PermissionsList.PermissionsIngredientUpdate)]
        public async Task <IActionResult> UpdateIngredient(string id, [FromBody] IngredientModel ingredientModel)
        {
            Guid ingredientId = Guid.Parse(id);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Ingredient ingredient = await _ingredientRepository.GetById(ingredientId);

            ingredient.Name           = ingredientModel.Name;
            ingredient.Quantity       = ingredientModel.Quantity;
            ingredient.Price          = ingredientModel.Price;
            ingredient.ExpirationDate = ingredientModel.ExpirationDate;

            _ingredientRepository.Update(ingredient);

            return(Ok(new { ingredient }));
        }
예제 #6
0
        private void IngredientSelected(SelectedMessage <IngredientWrapper> message)
        {
            var ingredientDetail = _ingredientRepository.GetById(message.Id);

            Model = new IngredientAmountDetailModel
            {
                IngredientId          = ingredientDetail?.Id ?? Guid.Empty,
                IngredientName        = ingredientDetail?.Name ?? string.Empty,
                IngredientDescription = ingredientDetail?.Description ?? string.Empty
            };
        }
        public async Task <GetIngredientDto> Handle(GetIngredientByIdQuery request, CancellationToken cancellation)
        {
            var ingredient = await repository.GetById(request.Id);

            var getIngredientDto = new GetIngredientDto()
            {
                Id   = ingredient.Id,
                Name = ingredient.Name
            };

            return(getIngredientDto);
        }
        public async Task <Result> Handle(DeleteIngredientCommand command)
        {
            var ingredient = _ingredientRepository.GetById(command.Id);

            if (ingredient == null)
            {
                return(Result.Fail(ResultCode.NotFound, $"Ingredient with {command.Id}, does not exist"));
            }
            ingredient.Delete();
            _eventPublisher.Rise();
            return(Result.Ok());
        }
예제 #9
0
        public async Task <int> Handle(DeleteIngredientCommand request, CancellationToken cancellationToken)
        {
            var ingredient = repository.GetById(request.Id).Result;

            if (ingredient == null)
            {
                throw new Exception("Product doesn't exist");
            }

            await repository.DeleteAsync(ingredient);

            return(ingredient.Id);
        }
        public async Task <ActionResult> GetById(int id)
        {
            var ingredient = await _ingredientRepository.GetById(id);

            if (ingredient == null)
            {
                return(StatusCode(403, new ErrorModel {
                    ErrorMessage = String.Format(ERROR_MESSAGE, id)
                }));
            }

            return(StatusCode(200, ingredient));
        }
예제 #11
0
        public RegisterAndUpdateOutput Update(IngredientInput ingredientInput)
        {
            var ingredient = _ingredientRepository.GetById(ingredientInput.Id);

            if (ingredient == null)
            {
                return(null);
            }

            ingredient.Update(ingredientInput.Name, ingredientInput.Price);

            _ingredientRepository.Update(ingredient);

            return(new RegisterAndUpdateOutput
            {
                Success = true,
                Message = "Ingredient updated with success.",
                Data = ingredient
            });
        }
예제 #12
0
        public async Task <int> Handle(DeleteIngredientCommand request, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                await Task.Delay(1000, cancellationToken);
            }
            catch (Exception ex) when(ex is TaskCanceledException)
            {
                throw new TaskCanceledException("The user has cancelled the task!");
            }
            var ingredient = repository.GetById(request.Id).Result;

            if (ingredient == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            await repository.DeleteAsync(ingredient);

            return(ingredient.Id);
        }
        public async Task <Result> Handle(UpdateIngredientCommand command)
        {
            foreach (var validator in _validators)
            {
                var validationResult = validator.Validate(command);
                if (validationResult.IsFailure)
                {
                    return(validationResult);
                }
            }

            var ingredient = _ingredientRepository.GetById(command.Id);

            if (ingredient == null)
            {
                return(Result.Fail(ResultCode.NotFound, FailMessages.DoesNotExist(nameof(Ingredient),
                                                                                  nameof(UpdateIngredientCommand.Id), command.Id.ToString())));
            }

            ingredient.Update(command.Name, command.Allergens, command.Requirements, command.Shares);
            _eventPublisher.Rise();
            return(Result.Ok());
        }
예제 #14
0
        private void CreateXBacon()
        {
            var ingredient1 = _ingredientRepository.GetById(Guid.Parse("34d71f7b-7ad6-4bb1-8689-4a4fed5b3a7a"));
            var ingredient2 = _ingredientRepository.GetById(Guid.Parse("5d77453a-d4a8-4d15-8acc-a71a897da811"));
            var ingredient3 = _ingredientRepository.GetById(Guid.Parse("914fbbb3-985a-43ee-a17f-fd5fbc40499d"));
            var ingredient4 = _ingredientRepository.GetById(Guid.Parse("b00c92d0-9708-4c0b-8b53-0420516c69f8"));
            var ingredient5 = _ingredientRepository.GetById(Guid.Parse("40b0764c-ec61-4d1a-8b1e-51160ec50d7c"));
            var snack       = new Snack(Guid.Parse("4b1fb2e1-8e31-44d8-b2da-a3d32d89c3d1"), "X-BACON");

            snack.AddIngredient(ingredient1, 0);
            snack.AddIngredient(ingredient2, 1);
            snack.AddIngredient(ingredient3, 1);
            snack.AddIngredient(ingredient4, 0);
            snack.AddIngredient(ingredient5, 1);
            Snacks.Add(snack);
        }
예제 #15
0
 public void Load(Guid id)
 {
     Model = repository.GetById(id);
 }
예제 #16
0
 public Ingredient GetById(int Id)
 {
     return(_ingredientRepository.GetById(Id));
 }
예제 #17
0
 public void Load(Guid id)
 {
     Model = _ingredientRepository.GetById(id) ?? new IngredientDetailModel();
 }
예제 #18
0
 private void IngredientSelected(IngredientSelectedMessage ingredientSelectedMessage)
 => Model = _ingredientRepository.GetById(ingredientSelectedMessage.Id);