public async Task <IActionResult> Edit(int id, [Bind("TodoTaskId,Name,IsComplete")] TodoTask task) { if (id != task.TodoTaskId) { return(NotFound()); } if (ModelState.IsValid) { try { ctx.Update(task); await ctx.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (getTask(task.TodoTaskId) == null) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(task)); }
public async Task <bool> UpdateAsync(TodoItem item) { var entry = _database.Update(item); await _database.SaveChangesAsync(); return(entry.State == EntityState.Unchanged); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Text,DateCompleted,DateCreated,UserId,DateDue")] TodoItem todoItem) { if (id != todoItem.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(todoItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoItemExists(todoItem.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(todoItem)); }
public async Task <IActionResult> PutTaskAsync(int id, [FromBody] PutTaskRequest request) { Logger?.LogDebug("'{0}' has been invoked", nameof(PutTaskAsync)); var response = new Response(); try { var entity = await DbContext.GetTaskAsync(new Task(id)); if (entity == null) { return(NotFound()); } entity.Name = request.Name; DbContext.Update(entity); await DbContext.SaveChangesAsync(); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error, please contact to technical support."; Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PutTaskAsync), ex); } return(response.ToHttpResponse()); }
public async Task <IActionResult> PutTodo(int id, Todo todo) { if (id != todo.Id) { return(BadRequest()); } _context.Update(todo); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> UpdateAsync(Collection collection) { var entry = _database.Update(collection); await _database.SaveChangesAsync(); var isSucceed = entry.State == EntityState.Unchanged; entry.State = EntityState.Detached; return(isSucceed); }
public async Task <IActionResult> EditAsync([FromBody] TodoItem item) { var entity = await _dbContext.TodoItems.SingleOrDefaultAsync(b => b.Id == item.Id); entity.Name = item.Name; entity.KeyValuePairs = item.KeyValuePairs; _dbContext.Update(entity); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Complete(int?id) { if (id != null) { var todo = await _context.Todos.FindAsync(id); todo.EndedOn = DateTime.Now; todo.IsDone = true; _context.Update(todo); await _context.SaveChangesAsync(); } return(RedirectToAction("Index")); }
public async Task OnGetAsync(int?id) { if (id != null) { var todo = await _context.Todos.FindAsync(id); todo.EndedOn = DateTime.Now; todo.IsDone = true; _context.Update(todo); await _context.SaveChangesAsync(); } Todos = await _context.Todos.Where(t => t.IsDone).ToListAsync(); }
public async Task <TodoItem> ToggleCompleted(int id) { var item = await GetTodoItem(id); if (item.Completed.HasValue) { item.Completed = null; } else { item.Completed = DateTime.Now; } _context.Update(item); await _context.SaveChangesAsync(); StopTracking(item); return(item); }
public async Task <Board> UpdateBoardAsync(Board board) { if (!await boardRepository.CheckBoardExistsAsync(board.Id)) { throw new ArgumentException("Board with specified Id does not exist"); } if (board.CreationDate != null) { throw new ArgumentException("Cannot change board CreationDate"); } context.Update(board); await context.SaveChangesAsync(); context.Detach(board); return(board); }
public async Task <IActionResult> Put(int id, [FromBody] TodoItem item) { if (item is null || item.Id != id) { // RFC 2616 Section 10.4 recommends a plaintext explanation for 400 reponses return(BadRequest("Entity's id field does not match request's id.")); } TodoItem existingItem; try { existingItem = await _context.TodoItems.FirstAsync(i => i.Id == id); } catch { // RFC 2616 Section 10.4.5 (404) return(NotFound()); } // Update the existing item from the database without touching its Id existingItem.Title = item.Title; existingItem.IsComplete = item.IsComplete; _context.Update(existingItem); try { await _context.SaveChangesAsync(); } catch { // The update could not be committed to the database. // RFC 2616 Section 10.5 recommends that an explanation to be provided // for 500 responses. return(StatusCode(StatusCodes.Status500InternalServerError, "Unable to commit updated entity to backend database")); } // RFC 2616 Section 10.2.5 (204) return(NoContent()); }
public async Task <IActionResult> LogIn(string username, string password) { Boolean isLoggedOn = false; User user = new User(username, password); User inDb = await _context.Users.FirstOrDefaultAsync(u => u.username.Equals(user.username) && u.password.Equals(user.password)); if (inDb != default(User)) { isLoggedOn = true; inDb.isActive = true; _context.Update(inDb); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Todo", new { area = "" })); } else { } return(View("Index")); }
public void Update(Assignee element) { assigneeContext.Update(element); assigneeContext.SaveChanges(); }
public void Update(Todo element) { toDoContext.Update(element); toDoContext.SaveChanges(); }