public JsonResult CreateTask(TaskEx task) { try { // Validation if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }); } var taskRespo = new TaskRepository(); TaskEx addedTask = taskRespo.AddTask(task); // Inform all connected clients var clientName = Request["clientName"]; Task.Factory.StartNew( () => { // var clients = Hub.GetClients<TaskHub>(); _context.Clients.RecCreated(clientName, task); }); // Return result to current (caller) client return Json(new { Result = "OK", Record = addedTask }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }
public JsonResult TaskList() { try { var taskRespo = new TaskRepository(); List<TaskEx> tasks = taskRespo.GetAllTasks(); return Json(new { Result = "OK", Records = tasks }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }
public JsonResult DeleteTask(int id) { try { var taskRespo = new TaskRepository(); taskRespo.DeleteTask(id); // Inform all connected clients var clientName = Request["clientName"]; Task.Factory.StartNew( () => { // var clients = Hub.GetClients<TaskHub>(); _context.Clients.RecDeleted(clientName, id); }); // Return result to current (caller) client return Json(new { Result = "OK" }); } catch (Exception ex) { return Json(new { Result = "ERROR", Message = ex.Message }); } }