Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Root.Apps.Web.Csweb.Controllers
- {
- using System;
- using System.Diagnostics;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Contentstack.Core;
- using Deliverystack.Core;
- using Deliverystack.Core.Models.Repositories;
- using Root.Apps.Web.Csweb.Models;
- using Root.Core.Models.Entries;
- public class EntryController : Controller
- {
- private readonly ILogger<EntryController> _logger;
- private IRepository _repository;
- private ContentstackClient _stack;
- public EntryController(
- IRepository repository,
- ILogger<EntryController> logger,
- ContentstackClient stack)
- {
- _repository = repository;
- _logger = logger;
- _stack = stack;
- }
- public IActionResult Privacy()
- {
- return View();
- }
- [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
- public IActionResult Error()
- {
- return View("Error", new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
- }
- public IActionResult Index(string url)
- {
- if (string.IsNullOrEmpty(url) || !url.StartsWith("/"))
- {
- url = "/" + url;
- }
- new Instrument(_logger).Track(this, "INSIDE CONTROLLER");
- // new Instrument().Track(this, "Index({0})", url);
- WebpageEntry? entryModel = null;
- // url == HttpContext.Request.Path
- try
- {
- entryModel = _repository.GetEntryModel(url) as WebpageEntry;
- if (entryModel == null)
- {
- new Instrument().Warn(this, "Unable to locate entry by URL: {0}", url);
- }
- }
- catch (Exception ex)
- {
- throw ex;
- // new Instrument().Exception(this, ex, "exception retrieving entry model for {0} : ", url); //TODO: ilogger
- // Console.WriteLine(ex + " : " + ex.Message);
- //To see the exception in the browser in development throw ex;
- // return Error();
- }
- if (entryModel != null)
- {
- //TODO: why is .ContentTypeUid empty/null here?
- // new Instrument().Debug(this, "model for {0} [{1}] : {2}", url, entryModel.ContentTypeUid, entryModel);
- if (!String.IsNullOrEmpty(entryModel.PageData.View))
- {
- return View(entryModel.PageData.View, entryModel);
- }
- return View(entryModel);
- }
- else
- {
- // throw new HttpException(404, "Not Found");
- // Response.Clear();
- // Response.StatusCode = 404;
- // Response.End();
- }
- return View("index");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment