Example #1
0
        public async Task Remove(int id)
        {
            var model = await _db.RestaurantFoods.FindAsync(id);

            Errors.ThrowIfNull(model);

            if (_fileOnServer.Exists(model.PathToImage))
            {
                _fileOnServer.Remove(model.PathToImage);
            }

            _db.Remove(model);
        }
Example #2
0
        public void Add(RestaurantDTO modelDTO, IFormFile file, List <Cuisine> cuisines)
        {
            var model = MapModel(modelDTO);

            if (file != null)
            {
                _fileOnServer.Remove(model.PathToImage);
                model.PathToImage = _fileOnServer.Add(PathToFolder, file);
            }

            if (cuisines != null)
            {
                var restaurantCuisineService = new BindRestaurantWithCuisine(model, cuisines);

                var listRestaurantCuisine = restaurantCuisineService.Add();
                Db.RestaurantCuisines.AddRange(listRestaurantCuisine);
            }

            Db.Restaurants.Update(model);
        }