Ejemplo n.º 1
0
        public static AliasDetailsView ToDetailsView(this Alias alias)
        {
            if (alias == null)
            {
                return(null);
            }

            var detailsView = new AliasDetailsView
            {
                Id             = alias.Id,
                Name           = alias.Name,
                DateOfCreation = alias.DateOfCreation,
                Points         = alias.Points,
                Time           = alias.Time,
                Wpm            = alias.Wpm,
                Accuracy       = alias.Accuracy,
                Rank           = alias.Rank,
            };

            if (alias.Performances.Count == 0)
            {
                return(detailsView);
            }

            var topPerformancesQuery = from p in alias.Performances
                                       .OrderByDescending(p => p.Points)
                                       .Take(10)
                                       select p;

            var recentPerformancesQuery = from p in alias.Performances
                                          .OrderByDescending(p => p.DateOfCompletion)
                                          .Take(10)
                                          select p;

            var topPerformances    = topPerformancesQuery.Select(perf => perf.ToListView()).ToList();
            var recentPerformances = recentPerformancesQuery.Select(perf => perf.ToListView()).ToList();

            detailsView.TopPerformances    = topPerformances;
            detailsView.RecentPerformances = recentPerformances;

            return(detailsView);
        }
Ejemplo n.º 2
0
        public async Task <bool> Patch(long id, AliasDetailsView alias)
        {
            var query = from a in _context.Aliases
                        .Where(a => a.Id == id)
                        select a;

            var dbAlias = await query.SingleOrDefaultAsync();

            if (dbAlias == null)
            {
                return(false);
            }

            dbAlias.Points   = alias.Points;
            dbAlias.Time     = alias.Time;
            dbAlias.Wpm      = alias.Wpm;
            dbAlias.Accuracy = alias.Accuracy;

            await _context.SaveChangesAsync();

            return(true);
        }