Initial commit
This commit is contained in:
		| @ -0,0 +1,55 @@ | ||||
| using System.Collections.Generic; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Oqtane.Shared.Modules.HtmlText.Models; | ||||
| using Oqtane.Server.Modules.HtmlText.Repository; | ||||
|  | ||||
| namespace Oqtane.Server.Modules.HtmlText.Controllers | ||||
| { | ||||
|     [Route("{site}/api/[controller]")] | ||||
|     public class HtmlTextController : Controller | ||||
|     { | ||||
|         private IHtmlTextRepository htmltext; | ||||
|  | ||||
|         public HtmlTextController(IHtmlTextRepository HtmlText) | ||||
|         { | ||||
|             htmltext = HtmlText; | ||||
|         } | ||||
|  | ||||
|         // GET: api/<controller> | ||||
|         [HttpGet] | ||||
|         public IEnumerable<HtmlTextInfo> Get() | ||||
|         { | ||||
|             return htmltext.GetHtmlText(); | ||||
|         } | ||||
|  | ||||
|         // GET api/<controller>/5 | ||||
|         [HttpGet("{id}")] | ||||
|         public HtmlTextInfo Get(int id) | ||||
|         { | ||||
|             return htmltext.GetHtmlText(id); | ||||
|         } | ||||
|  | ||||
|         // POST api/<controller> | ||||
|         [HttpPost] | ||||
|         public void Post([FromBody] HtmlTextInfo HtmlText) | ||||
|         { | ||||
|             if (ModelState.IsValid) | ||||
|                 htmltext.AddHtmlText(HtmlText); | ||||
|         } | ||||
|  | ||||
|         // PUT api/<controller>/5 | ||||
|         [HttpPut("{id}")] | ||||
|         public void Put(int id, [FromBody] HtmlTextInfo HtmlText) | ||||
|         { | ||||
|             if (ModelState.IsValid) | ||||
|                 htmltext.UpdateHtmlText(HtmlText); | ||||
|         } | ||||
|  | ||||
|         // DELETE api/<controller>/5 | ||||
|         [HttpDelete("{id}")] | ||||
|         public void Delete(int id) | ||||
|         { | ||||
|             htmltext.DeleteHtmlText(id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										18
									
								
								Oqtane.Server/Modules/HtmlText/Repository/HtmlTextContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Oqtane.Server/Modules/HtmlText/Repository/HtmlTextContext.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Oqtane.Models; | ||||
| using Oqtane.Shared.Modules.HtmlText.Models; | ||||
| using Oqtane.Repository; | ||||
| using Oqtane.Modules; | ||||
|  | ||||
| namespace Oqtane.Server.Modules.HtmlText.Repository | ||||
| { | ||||
|     public class HtmlTextContext : ContextBase, IService | ||||
|     { | ||||
|         public virtual DbSet<HtmlTextInfo> HtmlText { get; set; } | ||||
|  | ||||
|         public HtmlTextContext(ITenantRepository TenantRepository):base(TenantRepository) | ||||
|         { | ||||
|             // ContextBase handles multi-tenant database connections | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,83 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using Oqtane.Shared.Modules.HtmlText.Models; | ||||
| using Oqtane.Modules; | ||||
|  | ||||
| namespace Oqtane.Server.Modules.HtmlText.Repository | ||||
| { | ||||
|     public class HtmlTextRepository : IHtmlTextRepository, IService | ||||
|     { | ||||
|         private readonly HtmlTextContext db; | ||||
|  | ||||
|         public HtmlTextRepository(HtmlTextContext context) | ||||
|         { | ||||
|             db = context; | ||||
|         } | ||||
|  | ||||
|         public IEnumerable<HtmlTextInfo> GetHtmlText() | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return db.HtmlText.ToList(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void AddHtmlText(HtmlTextInfo HtmlText) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 db.HtmlText.Add(HtmlText); | ||||
|                 db.SaveChanges(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void UpdateHtmlText(HtmlTextInfo HtmlText) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 db.Entry(HtmlText).State = EntityState.Modified; | ||||
|                 db.SaveChanges(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public HtmlTextInfo GetHtmlText(int HtmlTextId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 HtmlTextInfo HtmlText = db.HtmlText.Find(HtmlTextId); | ||||
|                 return HtmlText; | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void DeleteHtmlText(int HtmlTextId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 HtmlTextInfo HtmlText = db.HtmlText.Find(HtmlTextId); | ||||
|                 db.HtmlText.Remove(HtmlText); | ||||
|                 db.SaveChanges(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 throw; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,14 @@ | ||||
| using System.Collections.Generic; | ||||
| using Oqtane.Shared.Modules.HtmlText.Models; | ||||
|  | ||||
| namespace Oqtane.Server.Modules.HtmlText.Repository | ||||
| { | ||||
|     public interface IHtmlTextRepository | ||||
|     { | ||||
|         IEnumerable<HtmlTextInfo> GetHtmlText(); | ||||
|         void AddHtmlText(HtmlTextInfo HtmlText); | ||||
|         void UpdateHtmlText(HtmlTextInfo HtmlText); | ||||
|         HtmlTextInfo GetHtmlText(int HtmlTextIdId); | ||||
|         void DeleteHtmlText(int HtmlTextId); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 oqtane
					oqtane