Example #1
0
        public async Task RemoveProductAsync(Athlete athlete, AthleteProduct product)
        {
            _context.Athletes.Attach(athlete);

            athlete.AthleteProducts.Remove(product);

            await _context.SaveChangesAsync();
        }
Example #2
0
        public async Task AddAsync(int userId, int productId, double weight)
        {
            var athlete = await _athleteRepository.FindByCondition(condition : a => a.UserId == userId,
                                                                   include : source => source.Include(a => a.AthleteProducts.Where(ap => ap.ProductId == productId)));

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

            var product = await _productRepository.GetOrFailAsync(productId);

            athlete.AthleteProducts.Add(AthleteProduct.Create(athlete, product, weight));

            await UpdateDietStats(athlete, userId, product, weight, '+', DateTime.Today);
        }