Example #1
0
        public object Get(GetTechnologyStack request)
        {
            int id;
            var techStack = int.TryParse(request.Slug, out id)
                ? Db.SingleById <TechnologyStack>(id)
                : Db.Single <TechnologyStack>(x => x.Slug == request.Slug.ToLower());

            if (techStack == null)
            {
                throw HttpError.NotFound("Tech stack not found");
            }

            var techChoices = Db.LoadSelect(Db.From <TechnologyChoice>()
                                            .Join <Technology>()
                                            .Join <TechnologyStack>()
                                            .Where(x => x.TechnologyStackId == techStack.Id));

            var result = techStack.ConvertTo <TechStackDetails>();

            if (!string.IsNullOrEmpty(techStack.Details))
            {
                result.DetailsHtml = MarkdownConfig.Transform(techStack.Details);
            }

            result.TechnologyChoices = techChoices.Map(x => x.ToTechnologyInStack());

            var response = new GetTechnologyStackResponse
            {
                Created = DateTime.UtcNow,
                Result  = result
            };

            return(response);
        }
        public object Get(GetTechnologyStack request)
        {
            DbFactory.RegisterPageView("/stack/" + request.Slug);

            var key = ContentCache.TechnologyStackKey(request.Slug, clear: request.Reload);

            return(base.Request.ToOptimizedResultUsingCache(ContentCache.Client, key, () =>
            {
                int id;
                var techStack = int.TryParse(request.Slug, out id)
                    ? Db.SingleById <TechnologyStack>(id)
                    : Db.Single <TechnologyStack>(x => x.Slug == request.Slug.ToLower());

                if (techStack == null)
                {
                    throw HttpError.NotFound("Tech stack not found");
                }

                var techChoices = Db.LoadSelect(Db.From <TechnologyChoice>()
                                                .Join <Technology>()
                                                .Join <TechnologyStack>()
                                                .Where(x => x.TechnologyStackId == techStack.Id));

                var result = techStack.ConvertTo <TechStackDetails>();
                if (!string.IsNullOrEmpty(techStack.Details))
                {
                    result.DetailsHtml = new Markdown().Transform(techStack.Details);
                }

                result.TechnologyChoices = techChoices.Map(x => x.ToTechnologyInStack());

                var response = new GetTechnologyStackResponse
                {
                    Created = DateTime.UtcNow,
                    Result = result
                };
                return response;
            }));
        }