Exemple #1
0
        public CategorySearchResponse Search(CategorySearchRequest request)
        {
            var      response = new CategorySearchResponse();
            Category result   = null;

            en.Category categoryAlias = null;

            var queryOver = _session.QueryOver <en.Category>(() => categoryAlias);

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

            var rowCountQuery =
                queryOver.Clone()
                .ToRowCountQuery()
                .FutureValue <int>();

            response.Items =
                queryOver
                .SelectList(list => list
                            .Select(() => categoryAlias.Id).WithAlias(() => result.Id)
                            .Select(() => categoryAlias.Name).WithAlias(() => result.Name)
                            .Select(() => categoryAlias.LastUpdate).WithAlias(() => result.LastUpdate)
                            )
                .TransformUsing(Transformers.AliasToBean <Category>())
                .List <Category>();

            response.TotalItems =
                rowCountQuery.Value;


            return(response);
        }
Exemple #2
0
        public CategoryCreateResponse Add(CategoryCreateRequest request)
        {
            var response = new CategoryCreateResponse();

            var existing = CheckForExisting(request.Name);

            if (existing != null)
            {
                response.ErrorMessage = "Category already exists";
            }
            else
            {
                var category = new en.Category
                {
                    Name       = request.Name,
                    LastUpdate = DateTime.UtcNow
                };

                _session.Save(category);

                response.Category = new Category
                {
                    Id         = category.Id,
                    Name       = category.Name,
                    LastUpdate = category.LastUpdate
                };

                response.CompletedAt = DateTime.UtcNow;
            }

            return(response);
        }
Exemple #3
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();
        }
Exemple #4
0
        public Category Get(int id)
        {
            en.Category categoryAlias = null;
            en.Film     filmAlias     = null;

            Film result = null;

            var repoCategory = _categoryRepository.Get(id);

            var category = new Category()
            {
                Id         = repoCategory.Id,
                Name       = repoCategory.Name,
                LastUpdate = repoCategory.LastUpdate
            };

            category.Films =
                _session.QueryOver <en.Category>(() => categoryAlias)
                .JoinAlias(ca => ca.Films, () => filmAlias)
                .Where(c => c.Id == id)
                .SelectList(list => list
                            .Select(() => filmAlias.Id).WithAlias(() => result.Id)
                            .Select(() => filmAlias.Title).WithAlias(() => result.Title)
                            .Select(() => filmAlias.ReleaseYear).WithAlias(() => result.ReleaseYear)
                            .Select(() => filmAlias.RentalDuration).WithAlias(() => result.RentalDuration)
                            .Select(() => filmAlias.Length).WithAlias(() => result.Length)
                            .Select(() => filmAlias.RentalRate).WithAlias(() => result.RentalRate)
                            .Select(() => filmAlias.Rating).WithAlias(() => result.Rating)
                            .Select(() => filmAlias.Description).WithAlias(() => result.Description)
                            .Select(() => filmAlias.LastUpdate).WithAlias(() => result.LastUpdate)
                            .Select(() => filmAlias.ReleaseYear).WithAlias(() => result.ReleaseYear)
                            .Select(() => filmAlias.ReplacementCost).WithAlias(() => result.ReplacementCost)
                            .Select(() => filmAlias.SpecialFeatures).WithAlias(() => result.SpecialFeatures)
                            )
                .TransformUsing(Transformers.AliasToBean <Film>())
                .List <Film>();

            return(category);
        }