Example #1
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));
        }
Example #2
0
        public async Task <IActionResult> Update(string id, [FromBody] UpdateToDoDto ToDoDto)
        {
            var validationResult = _ToDoValidator.Validate(ToDoDto);

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

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

            entity.Id = int.Parse(id);
            await _ToDoRepository.UpdateAsync(entity);

            return(Ok());
        }