Exemple #1
0
 private static void TodoEventHandler(object sender, EventArgs e)
 {
     if (e.GetType() == typeof(TodoItemCreatedArgs))
     {
         var args = e as TodoItemCreatedArgs;
         if (args != null)
         {
             _todoService.CreateTodo(new TodoItem(args.Id, args.Title, args.IsCompleted));
         }
     }
     else if (e.GetType() == typeof(TodoItemCompletedArgs))
     {
         var args = e as TodoItemCompletedArgs;
         _todoService.CompleteTodo(args.Id);
     }
     else if (e.GetType() == typeof(TodoItemDeletedArgs))
     {
         var args = e as TodoItemDeletedArgs;
         _todoService.DeleteTodo(args.Id);
     }
     else
     {
         _logger.LogInformation("Todo EventHandler called");
     }
 }
        public async Task <ActionResult> Create(string todoDescription)
        {
            Devon4NetLogger.Debug("Executing GetTodo from controller TodoController");
            var result = await _todoService.CreateTodo(todoDescription).ConfigureAwait(false);

            return(StatusCode(StatusCodes.Status201Created, result));
        }
        public async Task <IActionResult> CreateTodo([FromBody] TodoCreateRequest request)
        {
            try
            {
                var error = ManuallyValidateNewTodoPayload(request);
                if (!string.IsNullOrEmpty(error))
                {
                    return(BadRequest(error));
                }
                var todo      = new TodoItem(request.Title, request.Description);
                var todoExist = await _todoService.TodoExist(todo.Title);

                if (todoExist)
                {
                    return(BadRequest($"A similar todo with title {todo.Title} already exist"));
                }
                var createResult = await _todoService.CreateTodo(todo);

                if (createResult == null)
                {
                    return(StatusCode((int)HttpStatusCode.NotFound));
                }
                return(Created(new Uri($"/{createResult.Id}"), createResult));
            }
            catch (Exception exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, exception.Message));
            }
        }
Exemple #4
0
        /// <summary>
        /// TodoRabbitMqHandler handler command
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public override async Task <bool> HandleCommand(TodoCommand command)
        {
            TodoService = GetInstance <ITodoService>();

            var result = await TodoService.CreateTodo(command.Description).ConfigureAwait(false);

            return(result != null);
        }
Exemple #5
0
    public async Task <ActionResult <TodoResponseModel> > Create([FromBody] TodoRequestModel model)
    {
        TodoDto newTodoDto     = _todoMapper.Map(model);
        TodoDto createdTodoDto = await _todoService.CreateTodo(newTodoDto);

        TodoResponseModel createdTodoModel = _todoMapper.Map(createdTodoDto);

        return(Ok(createdTodoModel));
    }
        public IActionResult Post([FromBody] TodoViewModel todoViewModel)
        {
            var userId = GetUserId();

            if (userId == null)
            {
                return(BadRequest());
            }

            var id = _todoService.CreateTodo(todoViewModel.Description, userId.Value);

            return(Ok(id));
        }
Exemple #7
0
        public override async Task <bool> HandleCommand(TodoCommand command)
        {
            TodoService = GetInstance <ITodoService>();

            if (TodoService == null)
            {
                throw new ArgumentException("The service 'TodoService' is not ready. Please check your dependency injection declaration for this service");
            }

            var result = await TodoService.CreateTodo(command.Description).ConfigureAwait(false);

            return(result != null);
        }
Exemple #8
0
        public async Task <ActionResult <TodoDTO> > CreateTodo([FromBody] TodoDTO todo)
        {
            try
            {
                var createdTodo = await _todoService.CreateTodo(todo);

                return(Ok(createdTodo));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
        public IActionResult Post([FromBody] string description)
        {
            if (string.IsNullOrEmpty(description))
            {
                return(new StatusCodeResult(400));
            }
            var entity = new Todo()
            {
                Description = description
            };

            _todoService.CreateTodo(entity);
            return(Ok());
        }
Exemple #10
0
        public async Task <IActionResult> CreateTodo([FromBody] TodoViewModel newTodo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TodoDTO isCreated = await _todoService.CreateTodo(_mapper.Map <TodoDTO>(newTodo));

            if (isCreated == null)
            {
                return(BadRequest());
            }

            return(Ok(_mapper.Map <TodoViewModel>(isCreated)));
        }
        public IActionResult Create(TodoViewModel todoViewModel)
        {
            int?userId = HttpContext.Session.GetInt32(TodoConstants.UserIdKey);

            var todo = new Todos
            {
                UserId         = userId.Value,
                Title          = todoViewModel.Title,
                Description    = todoViewModel.Description,
                DateAdded      = todoViewModel.DateAdded,
                DateToCommence = todoViewModel.DateToCommence
            };

            todoService.CreateTodo(todo);

            todoViewModel.SuccessMessage = "Todo Created Successfully";

            return(View(todoViewModel));
        }
        public async Task <IActionResult> Create([FromBody] Todo todo)
        {
            if (ModelState.IsValid)
            {
                await _todoService.CreateTodo(todo);

                var response = new ObjectResult(todo)
                {
                    StatusCode = (int)HttpStatusCode.Created
                };
                return(response);
            }

            return(new NotFoundObjectResult(new
            {
                Success = false,
                FullMessages = new[]
                {
                    "Not Found"
                }
            }));
        }
Exemple #13
0
        public async Task <IActionResult> CreateTodo([FromBody] NewTodoParams todoParams)
        {
            var todo = await _todoService.CreateTodo(todoParams);

            return(new OkObjectResult(todo));
        }
 public int Post([FromBody] TodoDto value)
 {
     return(_todoService.CreateTodo(value));
 }
Exemple #15
0
 public void Post([FromBody] Todo value)
 {
     _ToDoService.CreateTodo(value);
 }
Exemple #16
0
        public async Task <IActionResult> Create(TodoCreateRequest todo)
        {
            await _service.CreateTodo(todo);

            return(Ok());
        }
 public IActionResult AddTodo(Todo todo)
 {
     todoService.CreateTodo(todo);
     return(RedirectToAction("list"));
 }
Exemple #18
0
 public async Task <IActionResult> Post([FromBody] TodoDTO todoDTO)
 {
     return(await todoService.CreateTodo(todoDTO));
 }
        public async Task <CreatedNegotiatedContentResult <Todo> > CreateTodo([FromBody] Todo todo)
        {
            await _todosService.CreateTodo(todo);

            return(Created("/api/todos/" + todo.Id, todo));
        }
        public void Post([FromBody] Todo value)
        {
            var userName = this.User.Identity.Name;

            _ToDoService.CreateTodo(value, userName);
        }
Exemple #21
0
 public int CreateTodo([FromBody] CreateTodoReq request)
 {
     return(_todoService.CreateTodo(request));
 }
Exemple #22
0
 public IActionResult AddTodo(Todo todo, string name)
 {
     todoService.CreateTodo(todo);
     return(RedirectToAction("Index"));
 }
Exemple #23
0
 public void Post([FromBody] TodoModel newTodo)
 {
     _service.CreateTodo(newTodo);
 }
Exemple #24
0
        public async Task <IActionResult> CreateTodo([FromBody] Todo todo)
        {
            await _todosService.CreateTodo(todo);

            return(StatusCodeAndDtoWrapper.BuildSuccess(TodoDetailsDto.Build(todo), "Todo Created Successfully"));
        }