Пример #1
0
        public async Task <string> BuySnacks(SnackModel snack, int quantity)
        {
            var actualStock = snack.snackQuantity;

            if (actualStock < quantity)
            {
                return(await Task.Run(() => "The quantity exceeds the actual stock:" + actualStock));
            }
            var newStock = actualStock - quantity;

            snack.snackQuantity = newStock;
            await _snackRepository.UpdateSnack(snack);

            return(await Task.Run(() => "Sucess purchase"));
        }
        public async Task <string> LikeSnacks(SnackModel snack)
        {
            var likes = snack.snackLikes;

            if (likes >= 1)
            {
                snack.snackLikes--;
            }
            else
            {
                snack.snackLikes++;
            }

            await _snackRepository.UpdateSnack(snack);

            return(await Task.Run(() => "success like"));
        }