Refactored repository pattern for Add and Update methods so that they return their respective entity objects
This commit is contained in:
@ -31,18 +31,24 @@ namespace Oqtane.Server.Modules.HtmlText.Controllers
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] HtmlTextInfo HtmlText)
|
||||
public HtmlTextInfo Post([FromBody] HtmlTextInfo HtmlText)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
htmltext.AddHtmlText(HtmlText);
|
||||
{
|
||||
HtmlText = htmltext.AddHtmlText(HtmlText);
|
||||
}
|
||||
return HtmlText;
|
||||
}
|
||||
|
||||
// PUT api/<controller>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] HtmlTextInfo HtmlText)
|
||||
public HtmlTextInfo Put(int id, [FromBody] HtmlTextInfo HtmlText)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
htmltext.UpdateHtmlText(HtmlText);
|
||||
{
|
||||
HtmlText = htmltext.UpdateHtmlText(HtmlText);
|
||||
}
|
||||
return HtmlText;
|
||||
}
|
||||
|
||||
// DELETE api/<controller>/5
|
||||
|
@ -27,12 +27,13 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHtmlText(HtmlTextInfo HtmlText)
|
||||
public HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText)
|
||||
{
|
||||
try
|
||||
{
|
||||
db.HtmlText.Add(HtmlText);
|
||||
db.SaveChanges();
|
||||
return HtmlText;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -40,12 +41,13 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateHtmlText(HtmlTextInfo HtmlText)
|
||||
public HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText)
|
||||
{
|
||||
try
|
||||
{
|
||||
db.Entry(HtmlText).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return HtmlText;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -6,8 +6,8 @@ namespace Oqtane.Server.Modules.HtmlText.Repository
|
||||
public interface IHtmlTextRepository
|
||||
{
|
||||
IEnumerable<HtmlTextInfo> GetHtmlText();
|
||||
void AddHtmlText(HtmlTextInfo HtmlText);
|
||||
void UpdateHtmlText(HtmlTextInfo HtmlText);
|
||||
HtmlTextInfo AddHtmlText(HtmlTextInfo HtmlText);
|
||||
HtmlTextInfo UpdateHtmlText(HtmlTextInfo HtmlText);
|
||||
HtmlTextInfo GetHtmlText(int HtmlTextIdId);
|
||||
void DeleteHtmlText(int HtmlTextId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user