Exemplo n.º 1
0
        public void AddPhoto(RestaurantPhoto restaurantPhoto)
        {
            restaurantPhoto.PhotoTypeId =
                _restaurantPhotoRepository.Find(
                    p =>
                    p.RestaurantBranchId == restaurantPhoto.RestaurantBranchId &&
                    p.PhotoTypeId == (int)PhotoType.Primary).Any()
                    ? (int)PhotoType.Secondary
                    : (int)PhotoType.Primary;

            _restaurantPhotoRepository.Insert(restaurantPhoto);
            _restaurantPhotoRepository.SaveChanges();
        }
Exemplo n.º 2
0
        public async Task <RestaurantPhoto> DeleteRestaurantPhoto(int restaurantPhotoId)
        {
            RestaurantPhoto dbEntry = dbContext.RestaurantPhotos.Find(restaurantPhotoId);

            if (dbEntry == null)
            {
                throw new InvalidOperationException("Restaurant photo not found");
            }
            dbContext.RestaurantPhotos.Remove(dbEntry);

            await dbContext.SaveChangesAsync();

            return(dbEntry);
        }
Exemplo n.º 3
0
        public async Task <int> SaveRestaurantPhoto(RestaurantPhoto restaurantPhoto)
        {
            if (restaurantPhoto == null)
            {
                throw new ArgumentNullException(nameof(restaurantPhoto), "Parameter is null");
            }
            if (restaurantPhoto.Id == 0)
            {
                dbContext.RestaurantPhotos.Add(restaurantPhoto);
            }
            else
            {
                RestaurantPhoto dbEntry = dbContext.RestaurantPhotos.Find(restaurantPhoto.Id);
                if (dbEntry == null)
                {
                    throw new InvalidOperationException("Restaurant photo not found");
                }
                dbEntry.Photo = restaurantPhoto.Photo;
            }

            await dbContext.SaveChangesAsync();

            return(restaurantPhoto.Id);
        }