Exemple #1
0
        public async Task DeleteAsync(int userId, int productId, int athleteProductId)
        {
            var athlete = await _athleteRepository.FindByCondition(condition : a => a.UserId == userId,
                                                                   include : source => source.Include(a => a.AthleteProducts.Where(ap => ap.Id == athleteProductId))
                                                                   .ThenInclude(ap => ap.Product));

            if (athlete is null)
            {
                throw new AthleteNotFoundException(userId);
            }

            var athleteProduct = athlete.AthleteProducts.SingleOrDefault(ap => ap.Id == athleteProductId);

            if (athleteProduct is null)
            {
                throw new ProductForAthleteNotFoundException(userId, productId);
            }

            await _athleteRepository.RemoveProductAsync(athlete, athleteProduct);

            await UpdateDietStats(athlete, userId, athleteProduct.Product, athleteProduct.Weight, '-', athleteProduct.DateCreated);
        }