This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return movieRepository.GetAll().Select(Mapper.Map<MoviePresentationModel>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return movieRepository.GetAll().Project<Movie>().To<MoviePresentationModel>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData.Repositories | |
{ | |
public class MovieRepository | |
{ | |
static Context context = new Context(); | |
internal IQueryable<Domain.Movie> GetAll() | |
{ | |
return context.Movies; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData.Services | |
{ | |
public class MovieService | |
{ | |
private readonly MovieRepository movieRepository; | |
public MovieService(MovieRepository movieRepository) | |
{ | |
this.movieRepository = movieRepository; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData.Models | |
{ | |
public class MoviePresentationModel | |
{ | |
public int Id { get; set; } | |
public string Title { get; set; } | |
public int YearOfRelease { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData.Domain | |
{ | |
public class Movie | |
{ | |
public virtual int Id { get; set; } | |
public virtual string Title { get; set; } | |
public virtual DateTime Released { get; set; } | |
public virtual ICollection<Person> Directors { get; set; } | |
public virtual ICollection<Person> Actors { get; set; } | |
public virtual ICollection<UserRating> Ratings { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData | |
{ | |
public class DomainToModelMappingProfile : Profile | |
{ | |
public DomainToModelMappingProfile() | |
{ | |
Mapper.CreateMap<Movie, MoviePresentationModel>() | |
.ForMember(m => m.YearOfRelease, x => x.MapFrom(y => y.Released.Year)) | |
.ForMember(m => m.AverageRating, x => x.MapFrom(y => y.Ratings.Average(r => r.Rating))) | |
.ForMember(m => m.Actors, x => x.MapFrom(y => y.Actors.Select(a => a.Name))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebApi.OData | |
{ | |
public class DomainToModelMappingProfile : Profile | |
{ | |
public DomainToModelMappingProfile() | |
{ | |
Mapper.CreateMap<Movie, MoviePresentationModel>() | |
.ForMember(m => m.YearOfRelease, x => x.MapFrom(y => y.Released.Year)) | |
.ForMember(m => m.AverageRating, x => x.MapFrom(y => y.Ratings.Average(r => r.Rating))) | |
.ForMember(m => m.Actors, x => x.MapFrom(y => y.Actors.Select(a => a.Name))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach(var relatedPage in SlowPageRelationRepository.GetPagesRelatedTo(this.PageId, "en"") | |
{ | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SlowPageRelationRepository | |
{ | |
private static readonly SlowPageDatabaseHandler PageDatabaseHandler = new SlowPageDatabaseHandler(); | |
public static ICollection<Page> GetPagesRelatedTo(int page, string language) | |
{ | |
return PageDatabaseHandler.GetRelatedPages(page, language); | |
} | |
public static CategorizedPageCollection GetCategorizedPagesRelatedTo(int page, string language) |
NewerOlder