예제 #1
0
        private void PopulateFilmDetails(Film film)
        {
            if (film?.Id == null)
            {
                return;
            }

            Actor    actorResult    = null;
            Category categoryResult = null;

            en.Actor    actorAlias    = null;
            en.Film     filmAlias     = null;
            en.Category categoryAlias = null;


            var actors = _session.QueryOver <en.Actor>(() => actorAlias)
                         .JoinAlias(fi => fi.Films, () => filmAlias)
                         .Where(fa => filmAlias.Id == film.Id)
                         .SelectList
                         (
                list => list
                .Select(() => actorAlias.Id).WithAlias(() => actorResult.Id)
                .Select(() => actorAlias.FirstName).WithAlias(() => actorResult.FirstName)
                .Select(() => actorAlias.LastName).WithAlias(() => actorResult.LastName)
                .Select(() => actorAlias.LastUpdate).WithAlias(() => actorResult.LastUpdate)
                         )
                         .TransformUsing(Transformers.AliasToBean <Actor>())
                         .Future <Actor>();

            var categories = _session.QueryOver <en.Category>(() => categoryAlias)
                             .JoinAlias(fi => fi.Films, () => filmAlias)
                             .Where(fa => filmAlias.Id == film.Id)
                             .SelectList
                             (
                list => list
                .Select(() => categoryAlias.Id).WithAlias(() => categoryResult.Id)
                .Select(() => categoryAlias.Name).WithAlias(() => categoryResult.Name)
                .Select(() => categoryAlias.LastUpdate).WithAlias(() => categoryResult.LastUpdate)
                             )
                             .TransformUsing(Transformers.AliasToBean <Category>())
                             .List <Category>();

            film.Actors     = actors.ToList();
            film.Categories = categories.ToList();
        }
예제 #2
0
        public ActorCreateResponse Create(ActorCreateRequest request)
        {
            var response = new ActorCreateResponse();

            var repoActor = new en.Actor
            {
                FirstName  = request.FirstName,
                LastName   = request.LastName,
                LastUpdate = DateTime.Now
            };

            _session.Save(repoActor);

            response.Actor = new Actor()
            {
                Id         = repoActor.Id,
                FirstName  = repoActor.FirstName,
                LastName   = repoActor.LastName,
                LastUpdate = repoActor.LastUpdate
            };

            return(response);
        }
예제 #3
0
        public ActorSearchResponse Search(ActorSearchRequest request)
        {
            var response = new ActorSearchResponse();

            en.Actor actorAlias = null;
            Actor    result     = null;

            var queryOver =
                _session.QueryOver <en.Actor>(() => actorAlias);

            if (!string.IsNullOrWhiteSpace(request.FirstName))
            {
                queryOver.WhereRestrictionOn(c => c.FirstName).IsInsensitiveLike(request.FirstName.Trim(),
                                                                                 nh.Criterion.MatchMode.Anywhere);
            }

            if (!string.IsNullOrWhiteSpace(request.LastName))
            {
                queryOver.WhereRestrictionOn(c => c.LastName).IsInsensitiveLike(request.LastName.Trim(),
                                                                                nh.Criterion.MatchMode.Anywhere);
            }

            response.Items =
                queryOver
                .SelectList(list => list
                            .Select(() => actorAlias.Id).WithAlias(() => result.Id)
                            .Select(() => actorAlias.FirstName).WithAlias(() => result.FirstName)
                            .Select(() => actorAlias.LastName).WithAlias(() => result.LastName)
                            )
                .TransformUsing(Transformers.AliasToBean <Actor>())
                .Skip((request.PageNumber - 1) * request.ItemsPerPage)
                .Take(request.ItemsPerPage)
                .List <Actor>();

            return(response);
        }