fix feeds order

This commit is contained in:
chsakell
2016-10-05 16:19:02 +03:00
parent 0d8e383a22
commit 09ef60ddf4
3 changed files with 5 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ namespace LiveGameFeed.Controllers
[HttpGet] [HttpGet]
public IEnumerable<MatchViewModel> Get() public IEnumerable<MatchViewModel> Get()
{ {
IEnumerable<Match> _matches = _matchRepository.GetAll(); IEnumerable<Match> _matches = _matchRepository.AllIncluding(m => m.Feeds);
IEnumerable<MatchViewModel> _matchesVM = Mapper.Map<IEnumerable<Match>, IEnumerable<MatchViewModel>>(_matches); IEnumerable<MatchViewModel> _matchesVM = Mapper.Map<IEnumerable<Match>, IEnumerable<MatchViewModel>>(_matches);
return _matchesVM; return _matchesVM;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using AutoMapper; using AutoMapper;
using LiveGameFeed.Models; using LiveGameFeed.Models;
@@ -11,7 +12,7 @@ namespace LiveGameFeed.Core.Mappings
Mapper.CreateMap<Match, MatchViewModel>() Mapper.CreateMap<Match, MatchViewModel>()
.ForMember(vm => vm.Type, map => map.MapFrom(m => m.Type.ToString())) .ForMember(vm => vm.Type, map => map.MapFrom(m => m.Type.ToString()))
.ForMember(vm => vm.Feeds, map => map.MapFrom(m => .ForMember(vm => vm.Feeds, map => map.MapFrom(m =>
Mapper.Map<ICollection<Feed>, ICollection<FeedViewModel>>(m.Feeds))); Mapper.Map<ICollection<Feed>, ICollection<FeedViewModel>>(m.Feeds.OrderByDescending(f => f.Id).ToList())));
Mapper.CreateMap<Feed, FeedViewModel>(); Mapper.CreateMap<Feed, FeedViewModel>();
} }
} }

View File

@@ -37,8 +37,8 @@ namespace LiveGameFeed
{ {
services.AddDbContext<LiveGameContext>(options => options.UseInMemoryDatabase()); services.AddDbContext<LiveGameContext>(options => options.UseInMemoryDatabase());
// Repositories // Repositories
services.AddSingleton<IMatchRepository, MatchRepository>(); services.AddScoped<IMatchRepository, MatchRepository>();
services.AddSingleton<IFeedRepository, FeedRepository>(); services.AddScoped<IFeedRepository, FeedRepository>();
// Automapper Configuration // Automapper Configuration
AutoMapperConfiguration.Configure(); AutoMapperConfiguration.Configure();