Ejemplo n.º 1
0
        public override async Task <bool> Delete(int id)
        {
            if (id <= 0)
            {
                throw new InvalidOperationException();
            }

            IReadOnlyCollection <RestaurantCuisineType> toDelete =
                new RestaurantCuisineType[0];

            using (var cp = ContextProviderFactory.Create())
            {
                toDelete =
                    await cp.GetTable <RestaurantCuisineType>()
                    .Where(t => t.RestaurantId == id)
                    .ToArrayAsync();
            }

            foreach (var restaurantCuisineTypes in toDelete)
            {
                await _cuisineTypesService.Delete(restaurantCuisineTypes.RestaurantId, restaurantCuisineTypes.CuisineTypeId);
            }

            IReadOnlyCollection <RestaurantDenyType> toDelete2 =
                new RestaurantDenyType[0];

            using (var cp = ContextProviderFactory.Create())
            {
                toDelete2 =
                    await cp.GetTable <RestaurantDenyType>()
                    .Where(t => t.RestaurantId == id)
                    .ToArrayAsync();
            }

            foreach (var restaurantDenyType in toDelete2)
            {
                await _denyTypesService.Delete(restaurantDenyType.RestaurantId, restaurantDenyType.DenyTypeId);
            }

            await base.Delete(id);

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteDenyTypeById(int restaurantId, int[] denyTypeIds)
        {
            if (restaurantId <= 0)
            {
                return(BadRequest());
            }

            int count = 0;

            foreach (var denyTypeId in denyTypeIds)
            {
                var res =
                    await _restaurantDenyTypesService.Delete(restaurantId, denyTypeId);

                count += res ? 1 : 0;
            }

            return(Ok(count == denyTypeIds.Length));
        }