Example #1
0
        public async Task <bool> DeleteArtist(int id)
        {
            bool result = false;

            using (var tx = Context.Database.BeginTransaction())
            {
                var artist = await Context.Artists.FirstOrDefaultAsync(art => art.Id == id);

                // already gone
                if (artist == null)
                {
                    return(true);
                }

                var albumIds = await Context.Albums.Where(alb => alb.ArtistId == id).Select(alb => alb.Id).ToListAsync();

                var albumRepo = new AlbumRepository(Context);

                foreach (var albumId in albumIds)
                {
                    // don't run async or we get p
                    result = await albumRepo.DeleteAlbum(albumId, tx);

                    if (!result)
                    {
                        return(false);
                    }
                }

                Context.Artists.Remove(artist);

                result = await SaveAsync(); // just save

                if (!result)
                {
                    return(false);
                }

                tx.Commit();

                return(result);
            }
        }
Example #2
0
        /// <summary>
        /// Artist look up by name - used for auto-complete box returns
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <List <ArtistLookupItem> > ArtistLookup(string search = null)
        {
            if (string.IsNullOrEmpty(search))
            {
                return(new List <ArtistLookupItem>());
            }

            var repo = new AlbumRepository(Context);

            var term = search.ToLower();

            return(await repo.Context.Artists
                   .Where(a => a.ArtistName.ToLower().StartsWith(term))
                   .Select(a => new ArtistLookupItem
            {
                name = a.ArtistName,
                id = a.ArtistName
            })
                   .ToListAsync());
        }