Пример #1
0
        public Todo insert(Todo todo)
        {
            _context.Add(todo);

            _context.SaveChanges();

            return(todo);
        }
Пример #2
0
        public ActionResult Add(Todo todo)
        {
            if (ModelState.IsValid)
            {
                todo.AddedOn = DateTime.Now;
                db.Todos.Add(todo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(todo));
        }
Пример #3
0
        public JsonResult Post([FromBody] dynamic value)
        {
            string Title = value.title.Value;

            var list = new TodoList
            {
                Title = Title
            };

            _todosContext.TodoLists.Add(list);
            _todosContext.SaveChanges();

            return(Json(list));
        }
        public static void Initialize(TodosContext context)
        {
            context.Database.EnsureCreated();

            if (context.Todo.Any())
            {
                return;
            }

            var tasks = new Todo[]
            {
                new Todo {
                    Name = "First task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-01")
                },
                new Todo {
                    Name = "Second task", Description = "whaaat m8, no wei hello", CreateDate = DateTime.Parse("2010-09-02")
                }
            };

            foreach (var item in tasks)
            {
                context.Todo.Add(item);
            }
            context.SaveChanges();
        }
        public IHttpActionResult PutTodo(int id, Todo todo)
        {
            var dbTodo = db.Todos.Find(id);

            if (dbTodo == null)
            {
                return(NotFound());  // 404
            }

            dbTodo.Category = todo.Category;
            dbTodo.Text     = todo.Text;

            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                return(StatusCode(HttpStatusCode.InternalServerError)); // 500
            }

            return(StatusCode(HttpStatusCode.NoContent));  // 204
        }
Пример #6
0
 public void Add(Todos todo)
 {
     _context.Add(todo);
     _context.SaveChanges();
 }
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }