예제 #1
0
        public async Task <NowPlaying> PlayNextAsync()
        {
            if (_context.Player.Video != null)
            {
                await _historyRepository.AddAsync(_context.Player.Video, _context).ConfigureAwait(false);

                _context.Player.Video     = null;
                _context.Player.IsPlaying = false;
                await _context.SaveChangesAsync().ConfigureAwait(false);
            }

            var first = await _currentPlaylistRepository.GetFirstAsync().ConfigureAwait(false);

            if (first == null)
            {
                return(_context.Player);
            }

            var nowPlaying = await PlayNowPrivateAsync(first.Video, false).ConfigureAwait(false);

            await _currentPlaylistRepository.RemoveAsync(first.Id, _context).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(nowPlaying);
        }
        private async Task <IHttpActionResult> PostHistory(History history)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await _repository.AddAsync(history);
            }
            catch (DbUpdateException)
            {
                if (await HistoryExistsAsync(history.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = history.Id }, history));
        }
예제 #3
0
        public async Task <bool> AddAsync(HistoryItem historyItem)
        {
            var historyEntity = _mapper.Map <HistoryItem, HistoryEntity>(historyItem);

            historyEntity.PartitionKey = historyEntity.UserId;
            historyEntity.RowKey       = historyItem.WatchingItemId;
            historyEntity.Date         = DateTime.Now;
            return(await _historyRepository.AddAsync(historyEntity));
        }
예제 #4
0
        public async Task AddAsync(OperationType operationType, string currency, decimal amountOfMoney, decimal price, Guid userId)
        {
            var user = await _userRepository.FindAsync(userId);

            if (user == null)
            {
                throw new Exception("User is not exist");
            }

            var history = new History(operationType, currency, amountOfMoney, price, user);
            await _historyRepository.AddAsync(history);

            await _context.Clients.All.SendAsync("Add", _mapper.Map <History, HistoryDto>(history));
        }
예제 #5
0
        public async Task <HistoryDto> AddHistory(AddHistoryDTO model, CancellationToken cancellationToken = default)
        {
            if (model is null)
            {
                throw new ArgumentNullException("", Resources.ModelIsNull);
            }
            var history = _mapper.Map <History>(model);

            history.Rating      = -1;
            history.CreatedDate = DateTime.UtcNow;
            await _historyRepository.AddAsync(history, cancellationToken);

            _emailService.SendEmailAsync(history);
            return(_mapper.Map <HistoryDto>(history));
        }
예제 #6
0
        public async Task SaveHistory(Issue oldIssue, Issue newIssue, HistoryTypes action)
        {
            if (oldIssue == null)
            {
                oldIssue = Issue.Empty;
            }

            if (newIssue == null)
            {
                throw new ArgumentNullException(nameof(newIssue));
            }

            if (oldIssue != Issue.Empty && oldIssue.Id != newIssue.Id)
            {
                throw new InvalidIssueIdException(newIssue.Id);
            }

            var oldType = oldIssue.GetType();
            var newType = newIssue.GetType();

            var oldProperties = oldType.GetProperties();
            var newProperties = newType.GetProperties();

            List <Field> changedFields = new List <Field>();

            foreach (var oldProperty in oldProperties)
            {
                var matchingProperty = newProperties.FirstOrDefault(x =>
                                                                    !Attribute.IsDefined(x, typeof(IgnoreHistoryAttribute)) &&
                                                                    x.Name == oldProperty.Name && x.PropertyType == oldProperty.PropertyType);

                if (matchingProperty == null)
                {
                    continue;
                }

                var fieldTypeAttribute = oldProperty.GetCustomAttribute(typeof(HistoryFieldTypeAttribute)) as HistoryFieldTypeAttribute;
                var fieldType          = fieldTypeAttribute?.FieldType ?? FieldTypes.String;

                string oldValue;
                string newValue;

                switch (fieldType)
                {
                case FieldTypes.Assignees:
                case FieldTypes.LinkedIssues:
                    var oldPropertyArray = (((IEnumerable <Guid>)oldProperty.GetValue(oldIssue)) ?? Enumerable.Empty <Guid>()).ToArray();
                    var newPropertyArray = (((IEnumerable <Guid>)matchingProperty.GetValue(newIssue)) ?? Enumerable.Empty <Guid>()).ToArray();
                    oldValue = string.Join(',', oldPropertyArray);
                    newValue = string.Join(',', newPropertyArray);
                    break;

                default:
                    oldValue = oldProperty.GetValue(oldIssue)?.ToString();
                    newValue = matchingProperty.GetValue(newIssue)?.ToString();
                    break;
                }

                if (oldValue == newValue)
                {
                    continue;
                }

                var field = new Field(matchingProperty.Name, oldValue, newValue, fieldType);
                changedFields.Add(field);
            }

            var dateChanged = DateTime.Now;
            var userId      = _appContext.Identity.Id;

            if (changedFields.Count == 0)
            {
                return;
            }

            var history = new History(Guid.NewGuid(), newIssue.Id, userId, action, dateChanged, changedFields.ToArray());
            await _historyRepository.AddAsync(history);
        }
        public async Task <bool> Handle(CreateHistoryItemCommand request, CancellationToken cancellationToken)
        {
            await _historyIntegrationEventService.PublishThroughEventBusAsync(_mapper.Map <CreateHistoryItemCommand, HistoryUpdatedIntegrationEvent>(request));

            return(await _historyRepository.AddAsync(_mapper.Map <CreateHistoryItemCommand, HistoryEntity>(request)));
        }
예제 #8
0
 public async Task AddAsync(History history) =>
 await historyRepository.AddAsync(history);