Ejemplo n.º 1
0
        public async Task Upsert(LastSeenItem lastSeenItem, string ownerName)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(lastSeenItem.Id) || lastSeenItem.Id == "undefined")
                {
                    lastSeenItem.Id = null;
                }

                var db            = _mongoClient.GetDatabase(DatabaseName);
                var lastSeenItems = db.GetCollection <LastSeenItemEntity>(ItemsCollectionName);
                var oldEntity     = await lastSeenItems
                                    .Find(e => e.OwnerName == ownerName && e.Id == lastSeenItem.Id)
                                    .FirstOrDefaultAsync();

                var lastModified = oldEntity?.Modified ?? DateTime.UtcNow;

                var entity = _mapper.Map <LastSeenItemEntity>(lastSeenItem);
                entity.OwnerName = ownerName;
                entity.Modified  = lastSeenItem.MoveToTop ? DateTime.UtcNow : lastModified;

                if (entity.Id == null)
                {
                    await lastSeenItems.InsertOneAsync(entity);
                }
                else
                {
                    await lastSeenItems.ReplaceOneAsync(e => e.Id == entity.Id, entity);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
            }
        }
        public async Task Upsert(LastSeenItem lastSeenItem, string ownerName)
        {
            if (new ApplicationSettings().DemoUsername == ownerName)
            {
                return;
            }

            if (lastSeenItem.Unfinished == false)
            {
                lastSeenItem.Hours   = 0;
                lastSeenItem.Minutes = 0;
                lastSeenItem.Seconds = 0;
            }

            await _lastSeenRepository.Upsert(lastSeenItem, ownerName);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Upsert([FromBody] LastSeenItemModel model)
        {
            var domain = new LastSeenItem
            {
                Id             = model.Id,
                Season         = model.Season,
                Episode        = model.Episode,
                VisitUrl       = model.VisitUrl,
                Unfinished     = model.Unfinished,
                Hours          = model.Hours,
                Minutes        = model.Minutes,
                Seconds        = model.Seconds,
                Notes          = model.Notes,
                MoveToTop      = model.MoveToTop,
                Name           = model.Name,
                ImageUrl       = model.ImageUrl,
                TrackingUrl    = model.TrackingUrl,
                EpisodesBehind = model.EpisodesBehind,
            };
            await _lastSeenService.Upsert(domain, GetUsername());

            return(Ok());
        }