예제 #1
0
        public Dish FromPOCO(DishDto dish)
        {
            Dish d = new DAL.Entities.Dish()
            {
                ID          = dish.DishID,
                CreatedOn   = dish.CreatedOn,
                Description = dish.Description,
                IsActive    = dish.IsActive,
                TypeID      = dish.DishType,
                Name        = dish.Name,
                Price       = (decimal)dish.Price,
                Orders      = new List <Order>(),
                Ingredients = new List <Ingredient>(),
                Images      = new List <Image>()
            };

            if (dish.Ingredients.Count > 0)
            {
                foreach (var v in dish.Ingredients)
                {
                    if (v == null)
                    {
                        continue;
                    }
                    var ing = unitOfWork.IngredientsRepository.GetByID(v.ID);
                    if (ing != null)
                    {
                        d.Ingredients.Add(ing);
                    }
                }
            }
            if (dish.ImagesId.Count > 0)
            {
                dish.ImagesId.ForEach(x => {
                    var img = unitOfWork.ImagesRepository.GetByID(x);
                    if (img != null)
                    {
                        d.Images.Add(img);
                    }
                });
            }
            return(d);
        }
예제 #2
0
 public void Update(Dish dish)
 {
     _context.Entry(dish).State = EntityState.Modified;
 }
예제 #3
0
 public void Create(Dish item)
 {
     _context.Set <Dish>().Add(item
                               ?? throw new ArgumentNullException("Dish must be not null!"));
 }