public ActionResult Create(TaskDto taskDto) { var context = new DatabaseContext(); var createdTask = context.Tasks.Add(new Task { Name = taskDto.Name, Description = taskDto.Description, TypeId = taskDto.TypeId, Created = DateTime.Now }); context.SaveChanges(); var taskType = context.TaskTypes.FirstOrDefault(t => t.Id == createdTask.TypeId); return Json(new TaskDto { Id = createdTask.Id, Name = createdTask.Name, Description = createdTask.Description, TypeId = createdTask.TypeId, Created = createdTask.Created, TypeString = taskType != null ? taskType.Name : "", CreatedString = createdTask.Created.ToString("yy-MM-dd") }); }
public ActionResult Remove(int id) { var context = new DatabaseContext(); var task = context.Tasks.Find(id); if (task != null) { context.Tasks.Remove(task); context.SaveChanges(); } return Json(new { }, JsonRequestBehavior.AllowGet); }