Пример #1
0
 public ActionResult Create(Tasks task)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.AddToTasks(task);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(String.Empty, ex);
     }
     return(View(task));
 }
Пример #2
0
        public ActionResult Delete(int id)
        {
            TasksDBEntities context = new TasksDBEntities();
            var             deleted = context.list_tasks.Find(id);

            context.list_tasks.Remove(deleted);
            context.SaveChanges();

            return(Json(deleted, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public IHttpActionResult PutTask(int id, TaskDetail task)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != task.Task_ID)
            {
                return(BadRequest());
            }

            Task taskItem = new Task()
            {
                Task_ID          = task.Task_ID,
                Task_Description = task.Task,
                Priority         = task.Priority,
                Start_Date       = task.Start_Date,
                End_Date         = task.End_Date
            };

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public ActionResult Add(string task, string date)
        {
            TasksDBEntities context     = new TasksDBEntities();
            var             newListItem = new list_tasks {
                Task = task, Task_date = DateTime.Parse(date)
            };
            var added = context.list_tasks.Add(newListItem);

            context.SaveChanges();

            var result = new Task
            {
                Id          = added.Id,
                Name        = added.Task,
                CreatedDate = added.Task_date,
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }