public async Task <bool> AddItemAsync(NewTodoItem newItem, ApplicationUser user) { var entity = new TodoItem { Id = Guid.NewGuid(), OwnerId = user.Id, IsDone = false, Title = newItem.Title, DueAt = DateTimeOffset.Now.AddDays(3) }; _context.Items.Add(entity); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <bool> AddItemAsync(NewTodoItem newItem) { var entity = new TodoItem { Id = Guid.NewGuid(), //a random ID number IsDone = false, //isDone is set to false (no tick in the checkbox) Title = newItem.Title, //the new title goes in DueAt = DateTimeOffset.Now.AddDays(3) //the date is set to 3 days in the future }; _context.Items.Add(entity); //add all these fields to the entity //save the changes to the database var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <IActionResult> AddItem(NewTodoItem newItem) { if (!ModelState.IsValid) //if the model returns an error { //do stuff return(BadRequest(ModelState)); } //check if the adding is successful (we still need to add AddItemAsync as it throws an error) bool IsSuccessful = await _todoItemService.AddItemAsync(newItem); if (!IsSuccessful) //if it fails { return(BadRequest(new { error = "Could not add item" })); } //otherwise, if it works return OK result return(Ok()); }
public IActionResult Create([FromBody] NewTodoItem item) { if (item == null) { return(BadRequest()); } TodoItem newItem = new TodoItem(); newItem.Name = item.Name; newItem.Details = item.Details; _context.TodoItems.Add(newItem); _context.SaveChanges(); return(Ok(newItem)); }
public async Task<IActionResult> AddItem(NewTodoItem newItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) return Unauthorized(); var successful = await _todoItemService.AddItemAsync(newItem, currentUser); if (!successful) { return BadRequest(new { error = "Could not add item." }); } return Ok(); }
public async Task <bool> AddItemAsync(NewTodoItem newItem, ApplicationUser currentUser) { var entity = new TodoItem { Id = Guid.NewGuid(), IsDone = false, Title = newItem.Title, DueAt = newItem.DueAt, OwnerId = currentUser.Id }; _context.Items.Add(entity); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
// Action POST public async Task <ActionResult> AddItem(NewTodoItem newTodoItem) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var successful = await _todoItemService.AddItemAsync(newTodoItem, currentUser); if (!successful) { return(BadRequest(new { Error = "Could not add item" })); } return(Redirect("/todo")); //return Ok(); }
public async Task <IActionResult> AddItem(NewTodoItem newItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Unauthorized()); } var successful = await _todoItemService.AddItemAsync(newItem, currentUser); if (!successful) { return(BadRequest(new { error = "Não pode ser adicionado item." })); } return(Ok()); }
public Task <bool> AddItemAsync(NewTodoItem newItem) { throw new NotImplementedException(); }
public Task <bool> AddItemAsync(NewTodoItem item, ApplicationUser user) { throw new NotImplementedException(); }
public bool AddItem(NewTodoItem item, string userId) { return(repository.AddItem(item, userId)); }
public async Task <ActionResult <TodoItem> > AddTodoItem(NewTodoItem newItem) { // return return(Ok(await _todoService.AddItemToList(newItem))); }