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]
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);
return _matchesVM;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using LiveGameFeed.Models;
@@ -11,7 +12,7 @@ namespace LiveGameFeed.Core.Mappings
Mapper.CreateMap<Match, MatchViewModel>()
.ForMember(vm => vm.Type, map => map.MapFrom(m => m.Type.ToString()))
.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>();
}
}

View File

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