Ejemplo n.º 1
0
        public Artwork GetACode(Author owner)
        {
            try {
                return(_context.Artwork.First(obj => obj.Owner == owner && obj.Status == Models.Enums.ArtworkStatus.FreeToUse));
            }
            catch
            {
                int n     = 20; // i < "n" ---> "n" represents total number of codes ownered by the author.
                var codes = _context.ArtworkCode.Take(n).ToList();



                foreach (var code in codes)
                {
                    _context.ArtworkCode.Remove(code);
                    Artwork artwork = new Artwork();
                    artwork.Id      = code.Id;
                    artwork.Code    = code.ArtworkCodeCode;
                    artwork.OwnerID = owner.Id;
                    owner.AddCodeFromPot(artwork);
                }
                _context.SaveChanges();
                return(_context.Artwork.First(obj => obj.Owner == owner && obj.Status == Models.Enums.ArtworkStatus.FreeToUse));
            }
        }
Ejemplo n.º 2
0
        public void Pot(Author author)
        {
            int n     = 2000; // i < "n" ---> "n" represents total number of codes ownered by the author.
            var codes = _context.ArtworkCode.Take(n).ToList();



            foreach (var code in codes)
            {
                _context.ArtworkCode.Remove(code);
                Artwork artwork = new Artwork();
                artwork.Id      = code.Id;
                artwork.Code    = code.ArtworkCodeCode;
                artwork.OwnerID = author.Id;
                author.AddCodeFromPot(artwork);
            }
            _context.SaveChanges();
        }