public IActionResult ViewFile(Guid id) { var record = _resourceRepository.GetByIdAsync(id).Result; var fileInfo = _resourceRepository.DownloadFile(record.FileId); var fileName = fileInfo.FileInfo.Filename; var minetype = FileContentType.GetMimeType(Path.GetExtension(fileName)); return(File(fileInfo, minetype, fileName)); }
public async Task <IActionResult> ManagePage(Guid pageId) { var pageRecord = await _pageRepository.GetByIdAsync(pageId); if (pageRecord.TemplateId.HasValue) { PupulateAviliableTemplate(pageRecord.TemplateId.Value); var template = await _templateRepository.GetByIdAsync((Guid)pageRecord.TemplateId); pageRecord.BodyContent = template.BodyContent; pageRecord.FootContent = template.FootContent; pageRecord.HeadContent = template.HeadContent; } return(View(pageRecord)); }
public async Task <IActionResult> Index([FromServices] MongoDbBaseRepository <User, Guid> server) { //var user = new User() //{ // Id = Guid.NewGuid(), // Name = "simple", // Password = "******", // Address = "重庆江北" //}; //await server.InsertAsync(user); var user = await server.GetByIdAsync(new Guid("d06fe44f-d603-4e7b-a4cb-080fd181ab3a")); var userList = await server.SearchAsync(Builders <User> .Filter.Empty); return(View()); }
public async Task <IActionResult> Index([FromServices] MongoDbBaseRepository <User, Guid> server) { //var user = new User() //{ // Id = Guid.NewGuid(), // Name = "alangur", // Password = "******", // Address = "重庆渝中" //}; //await server.InsertAsync(user); var user = await server.GetByIdAsync(new Guid("b787fabf-337d-4bcd-92ec-8571905c87d1")); var userList = await server.SearchAsync(Builders <User> .Filter.Empty); return(View()); }
public IActionResult Edit(Guid id) { var record = _settingsRepository.GetByIdAsync(id).Result; return(View(record)); }
public async Task <IActionResult> ManageTemplate(Guid templateId) { var record = await _templateRepository.GetByIdAsync(templateId); return(View(record)); }
public async Task <IActionResult> DynamicRazorPage(Guid?pageId) { if (!pageId.HasValue) { return(NotFound()); } var page = _pageRepository.GetByIdAsync(pageId.Value).Result; if (page == null || !page.TemplateId.HasValue) { throw new Exception("Page Not exists"); } var engine = new RazorLightEngineBuilder() .UseMemoryCachingProvider() .Build(); string template = "Hello, @Model.Name. Welcome to RazorLight repository"; var model = new { Name = "John Doe" }; string content = await engine.CompileRenderAsync("templateKey", template, model); //var engine = new EngineFactory().Create(new StringContentRazorProject( // getContentFunc: key => // { // var template = _templateRepository.GetByIdAsync(Guid.Parse(key)).Result; // if (template == null) // throw new Exception("Template is null"); // MemoryStream stream = new MemoryStream(); // StreamWriter writer = new StreamWriter(stream); // writer.Write(template.BodyContent); // writer.Flush(); // stream.Seek(0, SeekOrigin.Begin); // return stream; // }, // existsCheckFunc: key => // { // var template = _templateRepository.GetByIdAsync(Guid.Parse(key)).Result; // return template != null; // }, // getParentLayoutKeyFunc: key => // { // var template = _templateRepository.GetByIdAsync(Guid.Parse(key)).Result; // if (template == null) // return string.Empty; // return template.ParentTemplateId.HasValue ? template.ParentTemplateId.Value.ToString() : string.Empty; // } // )); //var templateKey = page.TemplateId.Value.ToString(); //var templte = await engine.GetTemplateAsync(templateKey); //if (page.TemplateId.HasValue) //{ // var pageTemplate = _templateRepository.GetByIdAsync(page.TemplateId.Value).Result; // if (pageTemplate == null) // throw new Exception("Template is null"); // if (pageTemplate.ParentTemplateId.HasValue) // templte.Layout = pageTemplate.ParentTemplateId.Value.ToString(); //} //var viewbag = CreateViewBag(); //viewbag.Page = page; //var model = new //{ // Name = "DukeCheng", // Page = page //}; //templte.PageContext = new PageContext(viewbag) //{ // ExecutingPageKey = templateKey, // ModelTypeInfo = new ModelTypeInfo(model.GetType()) //}; ////var content = await engine.CompileRenderAsync(templateKey, model, model.GetType(), null); //var content = await engine.RenderTemplateAsync(templte, model); return(Content(content, "text/html", Encoding.UTF8)); }
public async Task <UrlRecord> GetUrlRecord(Guid urlRecordId) { return(await _urlRecordRepository.GetByIdAsync(urlRecordId)); }