Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> GetTask(int id)
        {
            Task task = await db.Tasks.FindAsync(id);

            if (task == null || task.IsDelete)
            {
                return(NotFound());
            }

            return(Ok(task));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 // 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();
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }