Esempio n. 1
0
        public async Task ToDo_Create_New_Entry()
        {
            var result = await _toDoRepository.AddAsync(new Core.Entities.ToDoItem
            {
                Title     = "Test",
                CreatedOn = DateTime.Now,
                Status    = Core.Enums.ToDoItemStatus.New
            });

            result.Should().BeGreaterThan(0);
        }
Esempio n. 2
0
        public async Task <Output <int> > HandleAsync(CreateToDoCommand command)
        {
            _argumentValidator.Validate(command);
            _argumentValidator.Validate(command.ToDoModel);

            var result = await _toDoRepository.AddAsync(command.ToDoModel.ToTableModel());

            var isSuccess = result > 0;

            return(new Output <int>(isSuccess, result));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([FromBody] CreateToDoDto ToDoDto)
        {
            var validationResult = _ToDoValidator.Validate(ToDoDto);

            if (!validationResult.IsValid)
            {
                return(BadRequest(BadRequestMessageHelper.BadRequestFormat(validationResult.Errors)));
            }

            var entity = _mapper.Map <CreateToDoDto, ToDoEntity>(ToDoDto);
            await _ToDoRepository.AddAsync(entity);

            return(Created($"{entity.Id}", null));
        }
Esempio n. 4
0
        public async Task <ToDoResponse> SaveAsync(ToDo todo)
        {
            try
            {
                await _todoRepository.AddAsync(todo);

                await _unitOfWork.CompleteAsync();

                return(new ToDoResponse(todo));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ToDoResponse($"An error occurred when saving the todo: {ex.Message}"));
            }
        }
Esempio n. 5
0
        public async Task <ToDo> CreateAsync(CreateToDoDto createToDoDto)
        {
            var todo = ToDo.Create(
                createToDoDto.Name,
                createToDoDto.Description,
                createToDoDto.Price,
                createToDoDto.DueAt,
                createToDoDto.BillToEmail);

            _logger.LogTrace("Created new todo with id {id}", todo.id);

            await _toDoRepository.AddAsync(todo);

            _logger.LogTrace("Stored new todo with id {id}", todo.id);

            return(todo);
        }
        public async Task <IActionResult> AddToDo([FromBody] ToDo toDo)
        {
            await myToDoRepository.AddAsync(toDo);

            return(CreatedAtRoute(nameof(GetToDoById), new { id = toDo.Id }, toDo));
        }