public async Task <ActionResult <Comment> > PostComment(Comment comment) { _context.Comments.Add(comment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetComment", new { id = comment.CommentId }, comment)); }
public async Task <bool> AddRange(List <ItemCreateDto> items, string email) { // Bax gor basqa userin todo-suna item elave eliyirmi: foreach (var item in items) { var todo = await _context.Todos .FirstOrDefaultAsync(t => t.Id == item.TodoId && t.Author.NormalizedEmail == email); if (todo == null) { return(false); } } // Herseyi Item listinin icine yigib added olaraq track ele: var newItems = new List <Item>(); for (int i = 0; i < items.Count(); i++) { newItems.Add(new Item() { Content = items[i].Content, isDone = items[i].IsDone, Order = items[i].Order, TodoId = items[i].TodoId }); } await _context.Items.AddRangeAsync(newItems); var res = await _context.SaveChangesAsync(); return(res > 0); }
public async Task <IActionResult> AddTodo(string user, [FromBody] AddTodoModel model) { if (!TodoAppUser.IsAllowed(user)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var todo = new Todo { // Don't do this at home! Id = db.Todos.Max(t => t.Id) + 1, AddedAt = DateTimeOffset.Now, LastUpdatedAt = DateTimeOffset.Now, IsComplete = false, UserName = user, Description = model.Description }; db.Todos.Add(todo); await db.SaveChangesAsync(); return(Ok(todo)); }
public async Task <Todo> Create(Todo todo) { _context.Todos.Add(todo); await _context.SaveChangesAsync(); return(todo); }
public async Task <ActionResult <TodoItem> > Post(TodoItem item) { _context.TodoItems.Add(item); await _context.SaveChangesAsync(); return(Ok(item)); }
public async Task <ActionResult <Models.Task> > PostTask(Models.Task task) { _context.Tasks.Add(task); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTask", new { id = task.TaskId }, task)); }
public async Task <ActionResult <TaskList> > PostTaskList(TaskList taskList) { _context.TaskLists.Add(taskList); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTaskList", new { id = taskList.TaskListId }, taskList)); }
public async Task <IActionResult> PutTodo(int id, Todo todo) { if (id != todo.Id) { return(BadRequest()); } _context.Entry(todo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <TodoItem> AddTodoItem(Models.TodoItem value, int userId) { var existingTags = await _context.Tags .Where(t => value.Tags.Contains(t)) .ToDictionaryAsync(t => t.Name); var item = new TodoItem { Title = value.Title, Description = value.Description, OwnerId = userId, Completed = null, Created = DateTime.Now, }; await UpdateTodoTags(item, value.Tags); _context.Add(item); await _context.SaveChangesAsync(); StopTracking(item); return(item); }
public async Task <IActionResult> PutEmployee(int id, Employee employee) { if (id != employee.Id) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create(TodoList list) { _context.TodoLists.Add(list); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetTodoList", new { id = list.ID }, list)); }
public async Task <IActionResult> Post([FromBody] TodoItem item) { if (item is null) { return(BadRequest()); } await _context.AddAsync(item); try { await _context.SaveChangesAsync(); } catch (Exception) { // TODO: Insert logging here // The new entity 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, "Could not commit new entity to the database")); } return(CreatedAtRoute("GetTodo", new { id = item.Id }, item)); }
public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem todoItem) { _context.TodoItems.Add(todoItem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoItem", new { id = todoItem.ID }, todoItem)); }
public async Task <IActionResult> Create(TodoItem item) { _context.TodoItems.Add(item); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetTodo", new { id = item.ID }, item)); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTodoList([FromRoute] int id, [FromBody] TodoList todoList) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != todoList.ID) { return(BadRequest()); } _context.Entry(todoList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <UserTaskViewModel> > PatchUserTask(int id, UserTaskDTO userTaskUpdate) { var userTask = await _context.UserTasks.FindAsync(id); if (userTask == null) { return(NotFound()); } userTask.Name = userTaskUpdate.Name ?? userTask.Name; userTask.Status = userTaskUpdate.Status; userTask.User = await _context.Users.FindAsync(userTaskUpdate.UserId); userTask.Deadline = userTaskUpdate.Deadline; _context.Entry(userTask).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new UserTaskViewModel { Id = userTask.Id, Name = userTask.Name ?? "No-name", Deadline = userTask.Deadline ?? DateTime.Now, UserId = userTask?.User.Id, Status = userTask?.Status.ToString() ?? Models.TaskStatus.New.ToString(), GroupId = userTask?.TaskGroup?.Id }); }
public async void ChangeStateTodo(Guid id, TodoState state) { var todo = _context.Todo.Where(t => t.Id.Equals(id)).FirstOrDefault(); todo.State = state; await _context.SaveChangesAsync(); }
public async Task Delete(TodoAggregate item) { var entity = m_dbContext.Todos.Where(dl => dl.Id == item.Id).FirstOrDefault(); m_dbContext.Todos.Remove(entity); await m_dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Post([FromBody] TodoItem todoItem) { await _context.TodoItems.AddAsync(todoItem); await _context.SaveChangesAsync(); return(CreatedAtRoute("GetTodoItem", new { id = todoItem.ID }, todoItem)); }
public async Task <TodoItem> AddAsync(Collection collection, TodoItem item) { _database.Attach(collection); collection.TodoItems.Add(item); await _database.SaveChangesAsync(); return(item); }
public async Task <Column> InsertColumnAsync(Column column) { DAL.Column newColumn = new() { Title = column.Title }; _context.Columns.Add(newColumn); await _context.SaveChangesAsync(); return(await GetSingleColumnAsync(newColumn.Id)); }
public async Task <ActionResult> PostAsync([FromBody] TodoItem item) { await _dbContext.TodoItems.AddAsync(item); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <T> AddAsync(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task <int> Add(Todo todo) { await _context.Todos.AddAsync(todo); await _context.SaveChangesAsync(); return(todo.Id); }
public async Task <IActionResult> OnPostCreateAsync() { await _db.TodoItems.AddAsync(TodoItem); await _db.SaveChangesAsync(); return(RedirectToPage()); }
public async Task <Collection> AddAsync(Collection collection) { var value = _database.Add(collection); await _database.SaveChangesAsync(); value.State = EntityState.Detached; return(value.Entity); }
public async Task AddAsync(TodoItem todoItem) { if (_context.TodoItem.Any(s => s.Id == todoItem.Id)) { throw new DuplicateTodoItemException(" duplicate id: { " + todoItem.Id + "}"); } _context.TodoItem.Add(todoItem); await _context.SaveChangesAsync(); }
public async Task <IActionResult> Post([FromBody] TodoBag value) { var todo = Todo.CreateFrom(value); _context.Add(todo); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { id = todo.Id }, todo)); }
public async Task <ActionResult <TodoItem> > AddTodoItemAsync(TodoItem item) { await Task.Delay(Config.ActionDelay); _dbContext.TodoItems.Add(item); await _dbContext.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTodoItemAsync), new { id = item.Id }, item)); }