Exemplo n.º 1
0
        /// <summary>
        /// Updates <see cref="Food"/> info in database, if food doesn't exist creates new one
        /// </summary>
        /// <param name="restaurant">Restaurant object</param>
        /// <param name="sheetFoods">List of foods to add and update</param>
        private void AddAndUpdateFood(Restaurant restaurant, List <Food> sheetFoods)
        {
            foreach (var food in sheetFoods)
            {
                var dbFood = restaurant.Foods.SingleOrDefault(f => f.Name == food.Name);
                if (dbFood != null)
                {
                    var d = _mapper.Map <FoodUpdateModel>(dbFood);
                    d.Price       = food.Price;
                    d.Description = food.Description;
                    _foodCommandRepository.Update(dbFood.Id, d);
                }
                else
                {
                    var d = _mapper.Map <FoodInsertModel>(food);
                    d.RestaurantId = restaurant.Id;
                    _foodCommandRepository.Insert(d);
                }
            }

            foreach (var food in restaurant.Foods)
            {
                var sheetFood = sheetFoods.SingleOrDefault(f => f.Name == food.Name);
                if (sheetFood == null)
                {
                    var udpateModel = _mapper.Map <FoodUpdateModel>(food);
                    udpateModel.IsInactive = true;
                    _foodCommandRepository.Update(food.Id, udpateModel);
                }
            }
        }
Exemplo n.º 2
0
        private void SeedFoods()
        {
            // Lipa
            _foodCommandRepository.Insert(new FoodInsertModel()
            {
                Name         = "Supa",
                Price        = 100,
                RestaurantId = 1,
                Type         = FoodType.SOUP
            });

            // lipa
            _foodCommandRepository.Insert(new FoodInsertModel()
            {
                Name         = "Kaubojska pasta",
                Price        = 100,
                RestaurantId = 1,
                Type         = FoodType.MAIN_COURSE
            });

            // Hedone
            _foodCommandRepository.Insert(new FoodInsertModel()
            {
                Name         = "Ramstek",
                Price        = 400,
                RestaurantId = 2,
                Type         = FoodType.MAIN_COURSE
            });

            // Hedone
            _foodCommandRepository.Insert(new FoodInsertModel()
            {
                Name         = "Princes krofna",
                Price        = 100,
                RestaurantId = 2,
                Type         = FoodType.DESERT
            });
        }