@page "/AllergyCategoriesPage"
@inject HttpClient http
<EjsGrid id="Grid" @ref="@grid" TValue="AllergyCategories" EnableRtl="true" AllowFiltering="true" AllowResizing="true" AllowSorting="true" AllowTextWrap="true" ShowColumnChooser="true" ShowColumnMenu="true" GridLines="@GridLine.Both" Height="100%" AllowGrouping="true" AllowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<EjsDataManager Adaptor="Adaptors.WebApiAdaptor" Url="api/AllergyCategories" CrossDomain="true"></EjsDataManager>
<GridFilterSettings Type="@Syncfusion.EJ2.Blazor.Grids.FilterType.Menu"></GridFilterSettings>
<EjsPager PageSize="12"></EjsPager>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(AllergyCategories.AllergyCategoryId) HeaderText="AllergyId" TextAlign="@TextAlign.Center" IsPrimaryKey="true" IsIdentity="true"></GridColumn>
<GridColumn Field=@nameof(AllergyCategories.AllergyCategoryName) HeaderText="AllergyName" TextAlign="@TextAlign.Center" ValidationRules="@(new { required= true })"></GridColumn>
</GridColumns>
</EjsGrid>
@code{
EjsGrid<AllergyCategories> grid;
}
namespace Newsha.Server.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AllergyCategoriesController : ControllerBase
{
private readonly AllergyCategoriesDataAccessLayer db = new AllergyCategoriesDataAccessLayer();
[HttpGet]
public object Get()
{
IEnumerable<AllergyCategories> data = db.GetAll();
var count = data.Count();
var queryString = Request.Query;
if (queryString.Keys.Contains("$inlinecount"))
{
StringValues Skip;
StringValues Take;
int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0;
int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count();
return new { Items = data.Skip(skip).Take(top), Count = count };
}
else
{
return data;
}
}
// GET: api/Default/5
[HttpGet("{id}")]
public AllergyCategories Get(object id)
{
return db.FindById(id);
}
// POST: api/Default
[HttpPost]
[HttpGet("[action]")]
public object GetNameId()
{
return db.GetNameId();
}
public void Post([FromBody] AllergyCategories entity)
{
if (ModelState.IsValid)
{
db.Add (entity);
}
}
// PUT: api/Default/5
[HttpPut]
public void Put([FromBody] AllergyCategories entity)
{
if (ModelState.IsValid)
{
db.Update(entity);
}
}
// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
public void DeleteById(int id)
{
if (ModelState.IsValid)
{
db.DeleteById(id);
}
}
}
}
public void Add(AllergyCategories entity)
{
try
{
_UW.AllergyCategories.Add(entity);
_UW.Commit();
}
catch
{
throw;
}
}
Attachment:
add2_5d4fbe77.rar