Example #1
0
        /// <summary>
        /// Adds a new Todo-item
        /// </summary>
        /// <param name="name">Name of the new Todo-item.</param>
        private async Task AddTodo(string name)
        {
            // Create new todo with name, image url and empty list of tasks
            TodoViewModel todo = new TodoViewModel(_dialogService)
            {
                Name = name,
                Order = Todos.Count + 1,
                Tasks = new ObservableCollection<TaskViewModel>()
            };

            // Add item to database
            await _repo.AddTodo(todo).ContinueWith(p =>
            {
                // Get Id of added item
                todo.Id = p.Result;                
            });

            // Add item to collection
            Todos.Add(todo);

            // Set as the selected Todo-item
            SelectedTodo = todo;

            // Clear new todo
            NewTodoName = string.Empty;            
        }
Example #2
0
 public TodoMutation(ITodoRepository todoRepository)
 {
     Name = "Mutation";
     Field <TodoType>(
         "createToDo",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <TodoInput> > {
         Name = "todoItem"
     }
             ),
         resolve: context =>
     {
         var todo = context.GetArgument <Todo>("todoItem");
         return(todoRepository.AddTodo(todo));
     });
     Field <TodoType>(
         "deleteToDo",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <IntGraphType> > {
         Name = "id"
     }),
         resolve: context =>
     {
         var id = context.GetArgument <int>("id");
         return(todoRepository.DeleteTodo(id));
     });
 }
Example #3
0
 public TodoMutation(ITodoRepository todoRepository)
 {
     Field <TodoType>(
         "addTodo",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <TodoInputType> > {
         Name = "todo"
     }),
         resolve: ctx =>
     {
         var todo = ctx.GetArgument <Todo>("todo");
         return(todoRepository.AddTodo(todo));
     });
     Field <TodoType>(
         "removeTodo",
         arguments: new QueryArguments(
             new QueryArgument <IntGraphType> {
         Name = "id"
     }),
         resolve: ctx =>
     {
         var id = ctx.GetArgument <int>("id");
         return(todoRepository.DeleteTodo(id));
     });
 }
Example #4
0
        public void AddTodo([FromBody] Todo todo)
        {
            if (todo == null)
            {
                BadRequest();
            }

            _repository.AddTodo(todo);
        }
Example #5
0
 public IActionResult AddTodo([FromBody] Todo todo)
 {
     if (string.IsNullOrEmpty(todo.Description))
     {
         return(BadRequest("The Description field must not be empty"));
     }
     _repository.AddTodo(todo);
     return(CreatedAtRoute("GetTodo", new { id = todo.Id }, todo));
 }
Example #6
0
        public void Execute()
        {
            if (_todo == null)
            {
                return;
            }

            _todoRepo.AddTodo(_todo);
        }
Example #7
0
        public async Task <Todo> AddTodo(Todo newTodo)
        {
            // Apply business layer logic (generate id)
            newTodo.Id = Guid.NewGuid();

            // Add
            await _todoRepository.AddTodo(newTodo);

            // Return the newTodo
            return(newTodo);
        }
Example #8
0
 public bool Execute(string title, string description)
 {
     try
     {
         _repository.AddTodo(new Todo(title, description));
         return(true);
     } catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #9
0
 public IAction AddTodo(string text)
 {
     return(new ThunkAction <AppState>(async(dispatch, getState) =>
     {
         var addedTodo = await _repo.AddTodo(new Data.Entities.Todo {
             Text = text
         });
         dispatch(new AddTodoAction {
             Text = addedTodo.Text
         });
     }));
 }
Example #10
0
        public async Task <ActionResult <Todo> > AddTodo(Todo todo)
        {
            if (!ModelState.IsValid)
            {
                return(ValidationProblem());
            }
            var createdTodo = await _demorep.AddTodo(todo);

            if (createdTodo < 0)
            {
                return(BadRequest("Input formate wrong\nTry without ID field"));
            }
            return(Ok(todo));
        }
Example #11
0
        public async Task <bool> SaveTodo(TodoDTO todoDTO)
        {
            var todo = _mapper.Map <TodoDTO, Todos>(todoDTO);

            if (!string.IsNullOrEmpty(todoDTO.TodoId))
            {
                todo.Id = ObjectId.Parse(todoDTO.TodoId);
                return(await _todoRepository.UpdateTodo(todo) != null);
            }
            else
            {
                return(await _todoRepository.AddTodo(todo) != null);
            }
        }
Example #12
0
        public async Task <ActionResult> Todo(Todo todo)
        {
            try
            {
                if (todo != null)
                {
                    await _todoRepo.AddTodo(new Todo { Name = todo.Name, Creation_Date = DateTime.Now, State = 0 });

                    return(Ok());
                }
                return(NoContent());
            }
            catch (Exception e)
            {
                return(Problem(e.Message));
            }
        }
        public async Task <TodoItem> CreateTodo(TodoItem todo)
        {
            try
            {
                var todoExist = await _todoRepository.TodoExist(todo.Title);

                if (todoExist)
                {
                    return(null);
                }
                return(await _todoRepository.AddTodo(todo));
            }
            catch (Exception exception)
            {
                // LogException with global Logger
                throw exception;
            }
        }
Example #14
0
        public async Task <IActionResult> Post([FromBody] TodoViewModel todo)
        {
            IActionResult response = BadRequest(ModelState.Values);

            if (ModelState.IsValid)
            {
                var newTodo = Mapper.Map <Todo>(todo);

                newTodo.Username = User.Identity.Name;

                _repository.AddTodo(newTodo);

                if (await _repository.SaveChangesAsync())
                {
                    response = Created($"/api/todos/{newTodo.Id}", newTodo);
                }
                else
                {
                    _logger.LogError("Failed to save todo to database");
                }
            }

            return(response);
        }
Example #15
0
 public IActionResult AddTodo(Todo todo)
 {
     repository.AddTodo(todo);
     return(View("List", repository.GetAllTodos()));
 }
Example #16
0
 public void AddTodo(Todo todo)
 {
     _repository.AddTodo(todo);
 }
 public IActionResult AddTodo(Todo newTodo)
 {
     todoRepository.AddTodo(newTodo);
     return(RedirectToAction("Index"));
 }
 public void Post([FromBody] Todo todo)
 {
     _repository.AddTodo(todo);
 }
 public Todo AddTodo(Todo newTodo)
 {
     return(_todoRepo.AddTodo(newTodo));
 }
Example #20
0
 public IActionResult Add(string title)
 {
     TodoRepository.AddTodo(title);
     return(RedirectToAction("List"));
 }