private Meal AddGenMaiMeal() { Meal genMaiMeal = new Meal { Type = MealType.Genmai }; Food genmai = _foodRepository.GetFirstOrDefaultByCondition(f => f.Name.ToLower() == "genmai"); if (genmai == null) { genmai = new Food { Name = "genmai", Description = "Riz and vegetable soap", Commentary = "" }; _foodRepository.AddAsync(genmai); } if (genmai != null) { if (genMaiMeal.MealFoods == null) { genMaiMeal.MealFoods = new List <MealFood>(); } genMaiMeal.MealFoods.Add(new MealFood { Meal = genMaiMeal, Food = genmai }); } return(genMaiMeal); }
public override async Task <FoodResponse> CreateFood(FoodRequest request, ServerCallContext context) { List <string> items = new List <string>(); _logger.LogInformation("Begin grpc call from method {Method} for Foody Restaurant {RestaurantName}", context.Method, request.Foods.RestaurantName); request.Foods.FoodItems.ToList().ForEach(a => items.Add(a.Name)); var foodData = new FoodData(items, request.Foods.RestaurantName, request.Foods.Description); if (foodData != null) { await _repository.AddAsync(foodData); context.Status = new Status(StatusCode.OK, "Food created successfulyl."); _logger.LogInformation("Grpc call created successfully for Restaurant {RestaurantName}", request.Foods.RestaurantName); return(new FoodResponse { Message = "Food Created" }); } else { context.Status = new Status(StatusCode.NotFound, "Error creating food."); } return(new FoodResponse { Message = "Food Error." }); }
public async Task CreateAsync(string name, string description) { var @food = await _foodRepository.GetAsync(name); if (@food != null) { throw new Exception($"Food named: {name} already exists."); } @food = new Food(name, description); await _foodRepository.AddAsync(@food); }
public async Task <IResult <long> > AddAsync(FoodModel model) { var validation = await new AddFoodModelValidator().ValidateAsync(model); if (validation.Failed) { return(Result <long> .Fail(validation.Message)); } var food = FoodFactory.CreateFood(model); await _foodRepository.AddAsync(food); await _unitOfWork.SaveChangesAsync(); return(Result <long> .Success(food.Id)); }
public async Task <BaseResponse <Food> > Handle(CreateFoodCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Food> { ReponseName = nameof(CreateFoodCommand), Content = new List <Food> () { } }; var entity = _mapper.Map <Food> (request); var newentity = await _foodRepository.AddAsync(entity); if (newentity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Food)} could not be created."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Food)} created successfully."; response.Content.Add(newentity); } return(response); }
public async Task CreateFoodAsync(Food food) { await _foodRepository.AddAsync(food); await _unitOfWork.CommitAsync(); }
public async Task AddFoodItems(FoodData foodData) { await _repository.AddAsync(foodData); }