public IHttpActionResult PutTaskCategory(int id, TaskCategory taskCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != taskCategory.TaskCategoryId)
            {
                return(BadRequest());
            }

            db.Entry(taskCategory).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public IHttpActionResult PatchTask(int id, [FromBody] JsonPatchDocument <Task> taskPatchDocument)
        {
            var task = db.Tasks.Find(id);

            if (task == null)
            {
                return(NotFound());
            }

            // apply the patch document
            taskPatchDocument.ApplyTo(task);
            db.SaveChanges();
            return(Ok(task));
        }
 public ActionResult Create(string newTaskText)
 {
     try
     {
         db.Tasks.Add(new Task(parser.ParseToTask(newTaskText)));
         db.SaveChanges();
     }catch (ArgumentException e)
     {
         Console.WriteLine(e.Message);
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit([Bind(Include = "ID,Title,Description,Done")] Task task)
 {
     if (ModelState.IsValid)
     {
         using (var db = new SheetToDoContext())
         {
             db.Entry(task).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(task));
 }
 public ActionResult Archive(int?id)
 {
     using (var db = new SheetToDoContext())
     {
         Task task = db.Tasks.Find(id);
         if (task != null)
         {
             task.Archived = true;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(RedirectToAction("Index")); // TODO: make error page inform about error
     }
 }