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
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.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.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.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
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
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
namespace WebApi.OData.Models | |
{ | |
public class MoviePresentationModel | |
{ | |
public int Id { get; set; } | |
public string Title { get; set; } | |
public int YearOfRelease { get; set; } | |
public double AverageRating { get; set; } | |
public string[] Actors { 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
public class Movie | |
{ | |
public int Id { get; set; } | |
public string Title { get; set; } | |
public ICollection<Actor> Actors { get;set; } | |
} | |
public class MovieModel | |
{ | |
public string Title { get; set; } |
OlderNewer