예제 #1
0
        public ActionResult Edit(Todo todo)
        {
            var userId = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                todo.UserId          = userId;
                db.Entry(todo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(todo));
        }
예제 #2
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void CategoriesList_UpdateItem(int id)
        {
            var context = new TODOListEntities();

            using (context)
            {
                Category category = context.Categories.Find(id);
                if (category == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("",
                                             String.Format("Product with id {0} was not found", id));
                    return;
                }
                TryUpdateModel(category);
                if (ModelState.IsValid)
                {
                    context.Entry(category).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
예제 #3
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void TodosListView_UpdateItem(int id)
        {
            var context = new TODOListEntities();

            using (context)
            {
                Todo todo = context.Todos.Find(id);
                if (todo == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("",
                                             String.Format("Product with id {0} was not found", id));
                    return;
                }
                TryUpdateModel(todo);
                if (ModelState.IsValid)
                {
                    todo.DateOfLastChange     = DateTime.Now;
                    context.Entry(todo).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
예제 #4
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void CategoriesList_UpdateItem(int id)
        {

            var context = new TODOListEntities();

            using (context)
            {
                Category category = context.Categories.Find(id);
                if (category == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("",
                        String.Format("Product with id {0} was not found", id));
                    return;
                }
                TryUpdateModel(category);
                if (ModelState.IsValid)
                {
                    context.Entry(category).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
예제 #5
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void TodosListView_UpdateItem(int id)
        {
            var context = new TODOListEntities();

            using (context)
            {
                Todo todo = context.Todos.Find(id);
                if (todo == null)
                {
                    // The item wasn't found
                    ModelState.AddModelError("",
                        String.Format("Product with id {0} was not found", id));
                    return;
                }
                TryUpdateModel(todo);
                if (ModelState.IsValid)
                {
                    todo.DateOfLastChange = DateTime.Now;
                    context.Entry(todo).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }