コード例 #1
0
        public async Task <bool> DeleteSeriesLiked(SeriesLiked seriesLiked)
        {
            using (var trans = _context.Database.BeginTransaction(_capPublisher, autoCommit: false))
            {
                try
                {
                    _context.SeriesLiked.Remove(seriesLiked);
                    await _context.SaveChangesAsync();

                    var seriesLikedDeletedEvent = _mapper.Map <SeriesLikedDeletedEvent>(seriesLiked);
                    await _capPublisher.SendEvent(EventInfo.SeriesLikedDeleted,
                                                  seriesLikedDeletedEvent);

                    await trans.CommitAsync();

                    return(true);
                }
                catch (Exception e)
                {
                    await trans.RollbackAsync();

                    _logger.LogError(e, $"Unexpected error while deleting series liked" +
                                     $" SeriesId:{seriesLiked.SeriesId} UserId:{seriesLiked.ViewerId}");
                    return(false);
                }
            }
        }
コード例 #2
0
        public async Task <bool> CreateSeriesLiked(Series series, string viewerId)
        {
            using (var trans = _context.Database.BeginTransaction(_capPublisher, autoCommit: false))
            {
                try
                {
                    var seriesLiked = new SeriesLiked
                    {
                        SeriesId = series.SeriesId,
                        ViewerId = viewerId
                    };
                    _context.SeriesLiked.Add(seriesLiked);
                    await _context.SaveChangesAsync();

                    var seriesLikedEvent = _mapper.Map <SeriesLikedEvent>(seriesLiked);
                    await _capPublisher.SendEvent(EventInfo.SeriesLikedCreated, seriesLikedEvent);

                    await trans.CommitAsync();

                    return(true);
                }
                catch (Exception e)
                {
                    await trans.RollbackAsync();

                    _logger.LogError(e, $"Unexpected error while creating series liked" +
                                     $" SeriesId:{series.SeriesId} UserId:{viewerId}");
                    return(false);
                }
            }
        }