Example #1
0
        public async Task <AddResult> AddMenuItem(MenuAddModel model)
        {
            if (model.Price < 1)
            {
                throw new RestaurantBadRequestException("Az ár nem lehet kisebb 1-nél!");
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                throw new RestaurantBadRequestException("Az étel/ital neve nem lehet üres!");
            }

            var existingMenuItem = await DbContext.MenuItems.Where(mi => mi.Name == model.Name && mi.IsActive).SingleOrDefaultAsync();

            if (existingMenuItem != null)
            {
                throw new RestaurantBadRequestException("Már létezik étel/ital ezzel a névvel!");
            }

            var category = await DbContext.MenuItemCategories.FindAsync(model.CategoryId);

            if (category == null)
            {
                throw new RestaurantNotFoundException("A megadott kategória nem létezik!");
            }

            var menuItem = DbContext.MenuItems.Add(new MenuItem()
            {
                Name       = model.Name,
                Price      = model.Price,
                CategoryId = model.CategoryId
            });

            await DbContext.SaveChangesAsync();

            return(new AddResult(menuItem.Entity.Id));
        }
Example #2
0
 public async Task <AddResult> AddMenuItem(MenuAddModel item)
 => await MenuService.AddMenuItem(item);