Esempio n. 1
0
        public void TestRendering()
        {
            ModelProvider <CustomModel> modelProvider = (r, h) => new CustomModel(r, h);

            var providers = new List <IHandlerBuilder>()
            {
                ModScriban.Page(Data.FromString("Hello {{ world }}!"), modelProvider),
                ModRazor.Page(Data.FromString("Hello @Model.World!"), modelProvider),
                Placeholders.Page(Data.FromString("Hello [World]!"), modelProvider)
            };

            foreach (var provider in providers)
            {
                var layout = Layout.Create().Add("page", provider);

                using var runner = TestRunner.Run(layout);

                using var response = runner.GetResponse("/page");

                var content = response.GetContent();

                Assert.NotEqual("Hello World!", content);
                Assert.Contains("Hello World!", content);
            }
        }
        public IHandlerBuilder?Details([FromPath] int id)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            var announces = context.LetterAnnounces
                            .Include(la => la.Announce)
                            .Include(la => la.Announce.Customer)
                            .Where(la => la.Letter == letter)
                            .OrderBy(la => la.Order)
                            .Select(la => la.Announce)
                            .ToList();

            var availableAnnounces = context.Announces
                                     .Include(a => a.Customer)
                                     .Where(a => !announces.Contains(a))
                                     .Where(a => a.Status == AnnounceStatus.Prepared || a.Status == AnnounceStatus.Published)
                                     .OrderBy(a => a.Status)
                                     .ThenByDescending(a => a.ID)
                                     .Select(a => a)
                                     .ToList();

            var viewModel = new LetterDetail(letter, announces.ToList(), availableAnnounces);

            return(ModRazor.Page(Resource.FromAssembly("Letter.Details.cshtml"), (r, h) => new ViewModel <LetterDetail>(r, h, viewModel))
                   .Title($"Infobrief {letter.Title}"));
        }
Esempio n. 3
0
        public void TestRouting()
        {
            var providers = new List <IHandlerBuilder>()
            {
                ModScriban.Page(Data.FromString("{{ route 'https://google.de' }}|{{ route 'res/123' }}|{{ route 'other/456/' }}|{{ route './relative' }}")),
                ModRazor.Page(Data.FromString("@Model.Route(\"https://google.de\")|@Model.Route(\"res/123\")|@Model.Route(\"other/456/\")|@Model.Route(\"./relative\")")),
            };

            foreach (var provider in providers)
            {
                var inner = Layout.Create()
                            .Add("page", provider);

                var outer = Layout.Create()
                            .Add("res", Layout.Create())
                            .Add("inner", inner);

                var layout = Layout.Create()
                             .Add("other", Layout.Create())
                             .Add("outer", outer);

                using var runner = TestRunner.Run(layout);

                using var response = runner.GetResponse("/outer/inner/page");

                var content = response.GetContent();

                Assert.Contains("https://google.de|../res/123|../../other/456/|./relative", content);
            }
        }
        public IHandlerBuilder?Edit([FromPath] int id, IRequest request)
        {
            var user = AccessControl.GetAccount(request);

            if (!user.Admin && !(user.ID == id))
            {
                throw new ProviderException(ResponseStatus.Forbidden, "Your are not allowed to edit this user.");
            }

            using var context = Database.Create();

            var account = context.Accounts
                          .Where(c => c.ID == id)
                          .FirstOrDefault();

            if (account == null)
            {
                return(null);
            }

            var viewModel = new AccountDetails(user, account);

            return(ModRazor.Page(Resource.FromAssembly("Account.Editor.cshtml"), (r, h) => new ViewModel <AccountDetails>(r, h, viewModel))
                   .Title($"{account.DisplayName}"));
        }
        public IHandlerBuilder Index(int page, string status)
        {
            if (page < 1)
            {
                page = 1;
            }

            using var context = Database.Create();

            IQueryable <Announce> query = context.Announces
                                          .Include(a => a.Customer);

            if (!string.IsNullOrEmpty(status))
            {
                if (Enum.TryParse <AnnounceStatus>(status, true, out var announceStatus))
                {
                    query = query.Where(a => a.Status == announceStatus);
                }
            }

            var total = query.Count();

            var records = query.Skip((page - 1) * PAGE_SIZE)
                          .Take(PAGE_SIZE)
                          .OrderByDescending(c => c.Number)
                          .ToList();

            var pages = (total + PAGE_SIZE - 1) / PAGE_SIZE;

            var paged = new PagedList <Announce>(records, page, pages, total);

            return(ModRazor.Page(Resource.FromAssembly("Announce.List.cshtml"), (r, h) => new ViewModel <PagedList <Announce> >(r, h, paged))
                   .Title("Anzeigen"));
        }
        public IHandlerBuilder Index(int page, bool inactive, IRequest request)
        {
            if (page < 1)
            {
                page = 1;
            }

            using var context = Database.Create();

            IQueryable <Account> query = context.Accounts;

            if (!inactive)
            {
                query = query.Where(u => u.Active);
            }

            var total = query.Count();

            var records = query.Skip((page - 1) * PAGE_SIZE)
                          .Take(PAGE_SIZE)
                          .OrderBy(u => u.DisplayName)
                          .ToList();

            var pages = (total + PAGE_SIZE - 1) / PAGE_SIZE;

            var paged = new PagedList <Account>(records, page, pages, total);

            var user = AccessControl.GetAccount(request);

            var list = new AccountList(user, paged);

            return(ModRazor.Page(Resource.FromAssembly("Account.List.cshtml"), (r, h) => new ViewModel <AccountList>(r, h, list))
                   .Title("Mitarbeiter"));
        }
        public IHandlerBuilder Index(int page)
        {
            if (page < 1)
            {
                page = 1;
            }

            using var context = Database.Create();

            IQueryable <Letter> query = context.Letters
                                        .Include(l => l.Announces);

            var total = query.Count();

            var records = query.Skip((page - 1) * PAGE_SIZE)
                          .Take(PAGE_SIZE)
                          .OrderByDescending(l => l.Created)
                          .Select(l => new LetterListEntry(l, l.Announces.Count))
                          .ToList();

            var pages = (total + PAGE_SIZE - 1) / PAGE_SIZE;

            var paged = new PagedList <LetterListEntry>(records, page, pages, total);

            return(ModRazor.Page(Resource.FromAssembly("Letter.List.cshtml"), (r, h) => new ViewModel <PagedList <LetterListEntry> >(r, h, paged))
                   .Title("Infobriefe"));
        }
        public FortuneHandler(IHandler parent)
        {
            Parent = parent;

            Page = ModRazor.Page(Resource.FromAssembly("Fortunes.html"), (r, h) => GetFortunes(r, h))
                   .Title("Fortunes")
                   .AddAssemblyReference <HttpUtility>()
                   .AddUsing("System.Web")
                   .Build(this);

            Template = ModRazor.Template <TemplateModel>(Resource.FromAssembly("Template.html")).Build();
        }
        public IHandlerBuilder Create()
        {
            using var context = Database.Create();

            var announces = context.Announces
                            .Include(a => a.Customer)
                            .Where(a => a.Status == AnnounceStatus.Prepared || a.Status == AnnounceStatus.Published)
                            .OrderBy(a => a.Status)
                            .ThenByDescending(a => a.ID)
                            .Select(a => a)
                            .ToList();

            return(ModRazor.Page(Resource.FromAssembly("Letter.Create.cshtml"), (r, h) => new ViewModel <List <Announce> >(r, h, announces))
                   .Title("Infobrief erstellen"));
        }
        public IHandlerBuilder?Create([FromPath] int number)
        {
            using var context = Database.Create();

            var customer = context.Customers
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (customer == null)
            {
                return(null);
            }

            return(ModRazor.Page(Resource.FromAssembly("Announce.Create.cshtml"), (r, h) => new ViewModel <Customer>(r, h, customer))
                   .Title("Neue Anzeige"));
        }
        public IHandlerBuilder?Edit([FromPath] int number)
        {
            using var context = Database.Create();

            var customer = context.Customers
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (customer == null)
            {
                return(null);
            }

            return(ModRazor.Page(Resource.FromAssembly("Customer.Editor.cshtml"), (r, h) => new ViewModel <Customer>(r, h, customer))
                   .Title($"{customer.FirstName} {customer.Name}"));
        }
        public IHandlerBuilder Index()
        {
            using var context = Database.Create();

            var model = new DashboardViewModel
                        (
                Customers: context.Customers.Count(),
                AnnouncesToPrepare: context.Announces.Where(a => a.Status == AnnounceStatus.New).Count(),
                AnnouncesToPublish: context.Announces.Where(a => a.Status == AnnounceStatus.Prepared).Count(),
                ActiveAnnounces: context.Announces.Where(a => a.Status == AnnounceStatus.Published).Count(),
                ActiveAccounts: context.Accounts.Where(a => a.Active).Count()
                        );

            return(ModRazor.Page(Resource.FromAssembly("Dashboard.cshtml"), (r, h) => new ViewModel <DashboardViewModel>(r, h, model))
                   .Title("Übersicht"));
        }
        public IHandlerBuilder?Details([FromPath] int number)
        {
            using var context = Database.Create();

            var announce = context.Announces
                           .Include(a => a.Customer)
                           .Where(c => c.Number == number)
                           .FirstOrDefault();

            if (announce == null)
            {
                return(null);
            }

            return(ModRazor.Page(Resource.FromAssembly("Announce.Details.cshtml"), (r, h) => new ViewModel <Announce>(r, h, announce))
                   .Title("Anzeige"));
        }
        public IHandlerBuilder?Edit([FromPath] int id)
        {
            using var context = Database.Create();

            var letter = context.Letters
                         .Include(l => l.Announces)
                         .Where(c => c.ID == id)
                         .FirstOrDefault();

            if (letter == null)
            {
                return(null);
            }

            return(ModRazor.Page(Resource.FromAssembly("Letter.Editor.cshtml"), (r, h) => new ViewModel <Letter>(r, h, letter))
                   .Title($"Infobrief bearbeiten"));
        }
        public IHandlerBuilder?Details([FromPath] int id, IRequest request)
        {
            var user = AccessControl.GetAccount(request);

            using var context = Database.Create();

            var account = context.Accounts
                          .Where(c => c.ID == id)
                          .FirstOrDefault();

            if (account == null)
            {
                return(null);
            }

            var viewModel = new AccountDetails(user, account);

            return(ModRazor.Page(Resource.FromAssembly("Account.Details.cshtml"), (r, h) => new ViewModel <AccountDetails>(r, h, viewModel))
                   .Title($"{account.DisplayName}"));
        }
        public IHandlerBuilder Index(int page, string _)
        {
            if (page < 1)
            {
                page = 1;
            }

            using var context = Database.Create();

            var records = context.Customers
                          .Skip((page - 1) * PAGE_SIZE)
                          .Take(PAGE_SIZE)
                          .OrderByDescending(c => c.Number)
                          .ToList();

            var total = context.Customers.Count();

            var pages = (total + PAGE_SIZE - 1) / PAGE_SIZE;

            var paged = new PagedList <Customer>(records, page, pages, total);

            return(ModRazor.Page(Resource.FromAssembly("Customer.List.cshtml"), (r, h) => new ViewModel <PagedList <Customer> >(r, h, paged))
                   .Title("Kunden"));
        }
Esempio n. 17
0
        public void TestRoutingToPath()
        {
            var providers = new List <IHandlerBuilder>()
            {
                ModScriban.Page(Data.FromString("{{ route path }}"), (IRequest r, IHandler h) => new PathModel(r, h)),
                ModRazor.Page(Data.FromString("@Model.Route(Model.Path)"), (IRequest r, IHandler h) => new PathModel(r, h)),
            };

            foreach (var provider in providers)
            {
                var layout = Layout.Create()
                             .Add("page", provider)
                             .Add("test", Content.From("test"));

                using var runner = TestRunner.Run(layout);

                using var response = runner.GetResponse("/page");

                var content = response.GetContent();

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.Contains("/test/1", content);
            }
        }
 public IHandlerBuilder Create()
 {
     return(ModRazor.Page(Resource.FromAssembly("Account.Create.cshtml"))
            .Title("Mitarbeiter anlegen"));
 }
 public IHandlerBuilder Create()
 {
     return(ModRazor.Page(Resource.FromAssembly("Customer.Create.cshtml"))
            .Title("Kunden anlegen"));
 }