示例#1
0
        public async Task <OperationResult <bool> > DeleteArtist(ApplicationUser user, Guid artistId)
        {
            var sw = new Stopwatch();

            sw.Start();
            var errors = new List <Exception>();
            var artist = DbContext.Artists.FirstOrDefault(x => x.RoadieId == artistId);

            if (artist == null)
            {
                await LogAndPublish($"DeleteArtist Unknown Artist [{artistId}]", LogLevel.Warning);

                return(new OperationResult <bool>(true, $"Artist Not Found [{artistId}]"));
            }

            try
            {
                var result = await ArtistFactory.Delete(artist);

                if (!result.IsSuccess)
                {
                    return new OperationResult <bool>
                           {
                               Errors = result.Errors
                           }
                }
                ;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                await LogAndPublish("Error deleting artist.");

                errors.Add(ex);
            }

            sw.Stop();
            await LogAndPublish($"DeleteArtist `{artist}`, By User `{user}`", LogLevel.Information);

            return(new OperationResult <bool>
            {
                IsSuccess = !errors.Any(),
                Data = true,
                OperationTime = sw.ElapsedMilliseconds,
                Errors = errors
            });
        }