Example #1
0
        public TemplatesModule(IDocumentStore documentStore, CreateTemplateCommand createTemplateCommand)
            : base("templates/{type}")
        {
            _documentStore = documentStore;
            Post["/"] = call =>
                            {
                                var model = this.Bind<ServiceEndpoints.Templates.CreateUnsubscribeTemplate>();

                                createTemplateCommand.Body = model.Body;
                                createTemplateCommand.Type = Enum.Parse(typeof(TemplateType), call.type, true);
                                createTemplateCommand.Execute();

                                return Response.AsText("OK");
                            };

            Get["/"] = call =>
                           {
                               using (var session = _documentStore.OpenSession())
                               {
                                   var type = (TemplateType)Enum.Parse(typeof(TemplateType), call.type, true);
                                   return Response.AsJson(session.Query<Template>().Where(q => q.Type == type).ToList());
                               }
                           };
        }