public async Task <IHttpActionResult> DeleteTask(int id) { Task task = await db.Tasks.FindAsync(id); if (task == null) { return(NotFound()); } task.IsDelete = true; db.Entry(task).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(id)) { return(NotFound()); } else { throw; } } return(Ok(task)); }
public async Task <IHttpActionResult> PutTask(int id, Task task) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != task.Id) { return(BadRequest()); } db.Entry(task).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetTask(int id) { Task task = await db.Tasks.FindAsync(id); if (task == null || task.IsDelete) { return(NotFound()); } return(Ok(task)); }
public async Task <IHttpActionResult> PostTask(Task task) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Tasks.Add(task); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = task.Id }, task)); }
// POST /Tasks /// <summary> /// Posts the specified model. /// </summary> /// <param name="model">The model.</param> public void Post(TaskModel model) { using (var dataContext = new DataContext()) { var item = new Task { Title = model.Title, Completed = model.Completed, User = dataContext.UserProfiles.AsNoTracking().First(x => x.UserName == this.User.Identity.Name) }; dataContext.Tasks.Add(item); dataContext.SaveChanges(); } }
public ActionResult Index(TaskModel model) { using (var dataContext = new DataContext()) { var item = new Task { Title = model.Title, Completed = model.Completed, User = dataContext.UserProfiles.AsNoTracking().First(x => x.UserName == User.Identity.Name) }; dataContext.Tasks.Add(item); dataContext.SaveChanges(); return Json(item, JsonRequestBehavior.AllowGet); } }