예제 #1
0
            public async Task <Response> Handle(Request request)
            {
                var entity = await _context.AthleteWeights
                             .Include(x => x.Tenant)
                             .Include(x => x.Athlete)
                             .SingleOrDefaultAsync(x => x.Id == request.AthleteWeight.Id &&
                                                   x.Tenant.UniqueId == request.TenantUniqueId);

                if (entity == null)
                {
                    var tenant = await _context.Tenants.SingleAsync(x => x.UniqueId == request.TenantUniqueId);

                    var athlete = await _context.Athletes.SingleAsync(x => x.Username == request.Username);

                    _context.AthleteWeights.Add(entity = new AthleteWeight()
                    {
                        TenantId = tenant.Id, AthleteId = athlete.Id
                    });
                }

                entity.WeightInKgs = request.AthleteWeight.WeightInKgs;

                entity.WeighedOn = request.AthleteWeight.WeighedOn;

                await _context.SaveChangesAsync();

                _bus.Publish(new AddedOrUpdatedAthleteWeightMessage(AthleteWeightApiModel.FromAthleteWeight(entity), request.CorrelationId, request.TenantUniqueId));

                return(new Response());
            }
예제 #2
0
 public async Task <Response> Handle(Request request)
 {
     return(new Response()
     {
         AthleteWeight = AthleteWeightApiModel.FromAthleteWeight(await _context.AthleteWeights
                                                                 .Include(x => x.Tenant)
                                                                 .SingleAsync(x => x.Id == request.Id && x.Tenant.UniqueId == request.TenantUniqueId))
     });
 }
예제 #3
0
            public async Task <Response> Handle(Request request)
            {
                var athleteWeight = await _context.AthleteWeights
                                    .OrderByDescending(x => x.WeighedOn)
                                    .FirstOrDefaultAsync();

                return(new Response()
                {
                    AthleteWeight = athleteWeight != null?AthleteWeightApiModel.FromAthleteWeight(athleteWeight) : null
                });
            }
예제 #4
0
            public async Task <Response> Handle(Request request)
            {
                var athleteWeights = await _context.AthleteWeights
                                     .Include(x => x.Tenant)
                                     .Where(x => x.Tenant.UniqueId == request.TenantUniqueId)
                                     .ToListAsync();

                return(new Response()
                {
                    AthleteWeights = athleteWeights.Select(x => AthleteWeightApiModel.FromAthleteWeight(x)).ToList()
                });
            }