コード例 #1
0
        public void BuyAlbum(int credentialId, int albumId, short price)
        {
            //Load the profile
            Profile profile = GetById(credentialId);

            //Validate sum
            if (profile.GetSum() < price)
            {
                throw new NotEnoughFundsException("Du har ikke nok penge", profile.GetSum(), price);
            }

            if (profile.Purchases.Any(x => x.AlbumId == albumId))
            {
                throw new AlreadyPurchasedException("Du har allerede købt produktet", albumId);
            }

            ProfileRepository.AddAlbumPurchase(profile.ProfileId, albumId, price, DateTime.Now);
        }