public async Task <IActionResult> Add(AddTodoViewModel item) { if (!ModelState.IsValid) { return(View()); } var currentUser = await _userManager.GetUserAsync(HttpContext.User); var _item = new TodoItem(item.Text, new Guid((currentUser.Id))) { DateDue = item.DateDue }; if (item.Labels != null) { string[] labels = item.Labels.Split(','); foreach (var i in labels) { var todoItemLabel = new TodoItem.TodoItemLabel(i.Trim()); if (_item.Labels.Contains(todoItemLabel)) { continue; } _item.Labels.Add(todoItemLabel); } } await _repository.AddAsync(_item); return(RedirectToAction("Index")); }
public async Task <ActionResult <TodoItem> > PostTodoItem(NewTodoItemDTO itemDTO) { var item = _mapper.Map <TodoItem>(itemDTO); await _todoRepository.AddAsync(item); return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item)); }
/// <inheritdoc/> public async Task <TodoDto> CreateTodo(TodoDto dto) { TodoEntity newTodoEntity = _todoMapper.Map(dto); TodoEntity createdTodoEntity = await _todoRepository.AddAsync(newTodoEntity); return(_todoMapper.Map(createdTodoEntity)); }
public async Task <TodoDto> AddAsync(NewTodoDto model) { TodoEntity entity = _mapper.Map <TodoEntity>(model); TodoEntity user = await _repository.AddAsync(entity); return(_mapper.Map <TodoDto>(user)); }
public async Task <ActionResult> AddTodo([FromBody] TodoViewModel todoViewModel) { var user = await accountManager.GetUser(); var todoList = await todoListRepository.GetAsync(todoViewModel.ListId); if (!todoList.Members.Any(x => x.UserId == user.Id)) { return(BadRequest("user not a member")); } var todo = (Todo)todoViewModel; todo.Creator = user; todo.Created = DateTime.Now; todo.TodoList = todoList; if (!string.IsNullOrWhiteSpace(todoViewModel.assigneeId)) { todo.Assignee = await accountManager.GetUser(todoViewModel.assigneeId); } if (await todoRepository.AddAsync(todo)) { return(new OkObjectResult((TodoViewModel)todo)); } return(BadRequest()); }
public async Task <TodoDTO> SaveAsync(TodoDTO dto = null, Todo_Master entity = null) { if (dto == null && entity == null) { throw new Exception($"{nameof(dto)} and {nameof(entity)} they were both null."); } if (dto != null && entity == null) { if (dto.TD_ID > 0) { entity = await FindAsync(todoId : dto.TD_ID); } entity ??= new Todo_Master(); _mapper.Map(dto, entity); } if (dto?.TD_ID <= 0 || entity.TD_ID <= 0) { entity = await _repository.AddAsync(entity); } else { entity = await _repository.UpdateAsync(entity); } await _repository.UnitOfWork.SaveEntitiesAsync(); dto ??= new TodoDTO(); _mapper.Map(entity, dto); return(dto); }
public async Task <IActionResult> CreateAsync([FromBody] TodoViewModel todo) { var createdTodo = await _todoService.AddAsync(todo); return(CreatedAtAction( nameof(GetByIdAsync), new { user = createdTodo.User.UserName, id = createdTodo.TodoID }, createdTodo )); }
public async Task <Unit> Handle(AddTodoCommand request, CancellationToken cancellationToken) { var todo = new Todo(request.Title, request.Description, request.CompletionDate, request.Priority); await todoRepository.AddAsync(todo); await todoRepository.SaveChangesAsync(); return(Unit.Value); }
public async Task <Guid> AddTodoAsync(ITodoItem item) { var data = _mapper.Map <ITodoDataItem>(item); if (string.IsNullOrWhiteSpace(data.Title)) { throw new InvalidDataException("Cannot add a empty title todo item"); } return(await _todoRepository.AddAsync(data)); }
public async Task AddAsync(AddTodo command) { if (!Enum.TryParse <Priority>(command.Priority, true, out var priority)) { throw new InvalidTodoPriorityException(command.Priority); } var todo = new Todo(command.Id, command.Title, command.Description, priority, State.NEW, command.CreatedAt); await _todoRepository.AddAsync(todo); }
public async Task <IActionResult> Create([FromBody] Todo item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _todoRepository.AddAsync(item); return(CreatedAtRoute("GetTodo", new { id = item.Id }, item)); }
public async Task <TodoResponse> SaveAsync(Todo todo) { try { // data process add data on todolist on repository await _todoRepository.AddAsync(todo); // data result after save will shown return(new TodoResponse(todo)); } catch (Exception ex) { return(new TodoResponse($"An error occurred when saving the todo: {ex.Message}")); } }
public async Task <IActionResult> Add(AddViewModel model) { if (ModelState.IsValid) { if (model.Text == null) { model.Text = ""; } Guid userId = new Guid(_userManager.GetUserId(User)); TodoItem item = new TodoItem(model.Text, userId); _repository.AddAsync(item); return(RedirectToAction("Index")); } return(View(model)); }
/// <summary> /// Create New Todo Items /// </summary> /// <param name="todo"></param> /// <returns></returns> public async Task <SaveTodoResponse> SaveAsync(TodoItem todo) { try { await _todoRepository.AddAsync(todo); await _unitOfWork.CompleteAsync(); return(new SaveTodoResponse(todo)); } catch (Exception ex) { return(new SaveTodoResponse($"An error occurred when saving the todo item: {ex.Message}")); } }
public async Task <bool> CreateAsync(TodoItemCreateRequest request) { if (request == null) { _logger.LogError("Request item cannot be null"); return(false); } var entity = new TodoItem { Description = request.Description, State = false }; var result = await _store.AddAsync(entity); return(result); }
public async Task <TodoModel> CreateTodoAsync(TodoModel todoModel) { if (todoModel is null) { throw new ArgumentNullException(nameof(todoModel)); } var todoEntity = new Data.Entities.Todo { Description = todoModel.Description, IsCompleted = todoModel.IsCompleted, }; todoEntity = await _todoRepository.AddAsync(todoEntity); return(new TodoModel { Id = todoEntity.Id, Description = todoEntity.Description, IsCompleted = todoEntity.IsCompleted, }); }
public async Task <IActionResult> Add(AddTodoViewModel todoModel) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { return(Forbid("User not found.")); } List <string> labels = todoModel.Labels .Split(',') .Select(l => l.Trim()) .Where(l => !string .IsNullOrWhiteSpace(l)) .Distinct() .ToList(); List <TodoItemLabel> labelList = await _todoRepository.GetLabelsAsync(labels); labels.Except(labelList.Select(l => l.Value)).ToList().ForEach(l2 => { labelList.Add(new TodoItemLabel(l2)); }); TodoItem todoItem = new TodoItem(todoModel.Text, Guid.NewGuid()) { UserId = new Guid(user.Id), DateDue = todoModel.DateDue, Labels = labelList }; await _todoRepository.AddAsync(todoItem); return(RedirectToAction(nameof(Index))); } return(View(todoModel)); }
public async Task <IActionResult> Create([FromBody] Todo item) { await _todoRepository.AddAsync(item); return(CreatedAtRoute("GetFilterTodo", new { id = item.Id }, item)); }
public async Task <ActionResult> AddTodoAsync([FromBody] TodoModel newTodo) { await _repository.AddAsync(newTodo); return(Ok()); }
public Task AddAsync(Todo todo) { return(_todoRepository.AddAsync(todo)); }
public async Task <Unit> Handle(AddTodo request, CancellationToken cancellationToken) { await repository.AddAsync(new Todo(repository.NextId(), request.Title, request.Description)); return(await Task.FromResult(Unit.Value)); }
private async Task OnCreateTodo(CreateTodo todo, CancellationToken ct) { var newTodo = await _todoRepo.AddAsync(todo.Title); await _publisher.PublishAsync(new TodoCreated(newTodo), ct); }
public async Task <bool> CreateTodoAsync(Todo todo) { return(await _todoRepository.AddAsync(todo)); }