|
Index.cshtml
<ej-kanban id="KanbanBoard" key-field="Status">
<e-datamanager url="Home/GetData" // To load Kanban data
crud-url="Home/Crud" // To perform CRUD opeations
adaptor="UrlAdaptor"> //Define dataManager
</e-datamanager>
……….
</ej-kanban> |
|
HomeController.cs
public class HomeController : Controller
{
private KanbanDataContext _context;
public IActionResult Index()
{
return View();
}
public ActionResult GetData(Syncfusion.JavaScript.DataManager value)
{
List<KanbanTask> datas = _context.Tasks.Take(50).ToList(); // Get all Kanban data
DataResult result1 = new DataResult();
DataOperations operation = new DataOperations();
result1.result = datas;
result1.count = datas.AsQueryable().Count();
if (value.Skip > 0)
result1.result = operation.PerformSkip(result1.result, value.Skip);
if (value.Take > 0)
result1.result = operation.PerformTake(result1.result, value.Take);
return Json(result1);
}
//Edit multiple cards for priority drag and drop
public object Crud([FromBody] KanbanCRUDParams param)
{
var value = param.value;
if (param.action == "insert" || (param.action == "batch" && (param.added.Count > 0))) // this block of code will execute while inserting the card
{
{
// Insert card in the database.
DataResult result1 = new DataResult();
if (param.added != null && param.added.Count() > 0)
{
foreach (var temp in param.added)
{
_context.Tasks.Add(temp);
}
}
_context.SaveChanges();
var data = _context.Tasks.ToList();
return Json(result1);
}
}
if ((param.action == "remove") || (param.action == "batch" && (param.deleted.Count > 0))) // this block of code will execute while delete the card
{
foreach (var temp in param.deleted)
{
KanbanTask old = _context.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault();
if (old != null) _context.Tasks.Remove(old);
}
_context.SaveChanges();
}
// when perform update operations
if (param.changed != null && param.changed.Count() > 0)
{
foreach (var temp in param.changed)
{
KanbanTask old = _context.Tasks.Where(o => o.Id == temp.Id).SingleOrDefault();
if (old != null)
{
KanbanTask update = _context.Tasks.Single(A => A.Id == temp.Id);
update.Id = temp.Id;
update.Status = temp.Status;
update.Summary = temp.Summary;
update.Type = temp.Type;
update.Priority = temp.Priority;
update.Tags = temp.Tags;
update.Estimate = temp.Estimate;
update.Assignee = temp.Assignee;
update.ImgUrl = temp.ImgUrl;
update.RankId = temp.RankId;
}
}
}
_context.SaveChanges();// Save changed data on database
List<KanbanTask> datasource = _context.Tasks.Take(500).ToList();
return datasource;
}
public class DataResult
{
public IEnumerable result { get; set; }
public int count { get; set; }
}
public HomeController(KanbanDataContext context)
{
_context = context;
}
}
|
Thank you for the sample, i have tried the sample and have 2 questions regarding the sample:
1) i tried the datamanager and it makes 2 requests to the getdata method, is that correct? is it also posible to use the other adaptors webapi in cross domain situatiions with the Kanban board?
2) the dropdowns do not get populated when editing do in need to configure something extra to the datamanager? it does work when i use viewbag.datasource
i would like to use the web api adopter in my sample. And you are correct in your assumption that the dropdown(s) list entries are not shown/loaded.
|
Insert.cshtml
@(Html.EJ().Kanban("Kanban")
.DataSource(data => data.URL("/api/Employee").BatchURL("/api/batch").UpdateURL("/put").RemoveURL("/delete").InsertURL("/post").Adaptor(AdaptorType.WebApiAdaptor))
………….
)
|
|
EmployeeController.cs
public class EmployeeController : ApiController
{
static readonly IEmployeeRepository repository = new EmployeeRepository();
// GET api/<controller>
[Route("get")]
// GET api/values
public async Task<object> Get()
{
await Task.Delay(1000);
var queryString = HttpContext.Current.Request.QueryString;
var data = repository.GetAll().ToList(); // Get all Kanban card
return new { Items = data, Count = data.Count() };
}
public Employee GetEmployee(int id)
{
Employee emp = repository.Get(id);
if (emp == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return emp;
}
[Route("post")]
public async Task<IHttpActionResult> Post([FromBody] Employee emp)
{ // Triggered when insert new card
if (emp == null)
{
return BadRequest(ModelState);
}
emp = repository.Add(emp);
return Content(HttpStatusCode.OK, emp);
}
[Route("put")]
public async Task<IHttpActionResult> Put([FromBody] Employee emp)
{ //Triggered when update card
await Task.Delay(1000);
if (emp == null)
{
return BadRequest(ModelState);
}
else
{
if (!repository.Update(emp))
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return Content(HttpStatusCode.OK, emp);
}
}
[Route("delete/{id}")]
public async Task<IHttpActionResult> Delete(int id)
{ // Triggered when delete card
Employee emp = repository.Get(id);
await Task.Delay(1000);
if (emp == null)
{
return NotFound();
}
else
{
repository.Remove(id);
return StatusCode(HttpStatusCode.OK);
}
}
} |