public async Task <IActionResult> PutTodoItems([FromBody] TodoItem[] todos)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            foreach (TodoItem item in todos)
            {
                _context.Entry(item).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TodoItemExists(item.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }


            return(NoContent());
        }
Exemple #2
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todoItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public async Task <IActionResult> PutTodo([FromRoute] int id, [FromBody] Todo todo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            todo.id = id;

            _context.Entry(todo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #4
0
 public ActionResult Edit([Bind(Include = "ID,Name,DueDate,Type,Hours,Difficulty")] TodoList todoList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(todoList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(todoList));
 }
Exemple #5
0
        public async Task <IActionResult> PutTodoItem(int id, TodoItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #6
0
        public int PutTodoItem([FromBody] TodoItem todoItem)
        {
            try
            {
                _context.Entry(todoItem).State = EntityState.Modified;
                _context.SaveChanges();

                return(1);
            }
            catch
            {
                throw;
            }
        }
Exemple #7
0
        public async Task <bool> ModifyTodoItem_Details(TodoItem_Details TodoItem_Details)
        {
            _context.Entry(TodoItem_Details).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new TODOCustomError($"Erorr While modifying Todod item : {ex.Message}");
            }
        }
Exemple #8
0
        public async Task <Todo> Change(Todo todo)
        {
            if (todo == null)
            {
                throw new Exception("Todo cannot be null");
            }
            if (todo.Id < 0)
            {
                throw new Exception("Todo.Id must be greater than zero");
            }
            _context.Entry(todo).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            var rowsAffected = await _context.SaveChangesAsync();

            if (rowsAffected != 1)
            {
                throw new Exception("Change Failed");
            }
            return(todo);
        }
        public async Task <IActionResult> PutTodoEntry(int id, TodoEntry todoEntry)
        {
            todoEntry.id = id;

            _context.Entry(todoEntry).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoEntryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }