public Task <bool> Handle(RegistrarTarefaCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var tarefa = new Tarefa(Guid.NewGuid(), message.IdAluno, message.Nome, message.Descricao); if (_tarefaRepository.GetById(tarefa.Id) != null) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "Já existe um aluno com esse Email.")); return(Task.FromResult(false)); } _tarefaRepository.Add(tarefa); if (Commit()) { Bus.RaiseEvent(new TarefaRegistradaEvent(tarefa.Id, tarefa.IdGrupo, tarefa.IdAluno, tarefa.Nome, tarefa.Descricao)); } return(Task.FromResult(true)); }
public TarefaFormDto Cadastrar(TarefaFormDto formDto) { if (formDto == null) { formDto = new TarefaFormDto(); formDto.Erros.Add("Erro..."); return(formDto); } formDto.ValidationErros = _tarefaFormDtoValidator.Validate(formDto).Errors .Select(s => new ValidationFailureDto(s.ErrorMessage, s.PropertyName)) .ToList(); if (!formDto.IsValid()) { return(formDto); } var tarefa = new Tarefa(); tarefa = _mapper.Map <Tarefa>(formDto); if (!tarefa.IsValid()) { formDto.Erros = tarefa.Errors; return(formDto); } _tarefaRepository.Add(tarefa); return(_mapper.Map <TarefaFormDto>(tarefa)); }
public Int32 Create(TAREFA item, LOG log) { using (DbContextTransaction transaction = Db.Database.BeginTransaction(IsolationLevel.ReadCommitted)) { try { _logRepository.Add(log); _baseRepository.Add(item); transaction.Commit(); return(0); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public IActionResult Create([FromBody] Tarefa item) { if (item == null) { return(BadRequest()); } _tarefaRepository.Add(item); return(CreatedAtRoute("GetTarefa", new { id = item.Chave }, item)); }
public void Cadastrar(TarefaForCreationDTO dto) { var model = new Tarefa(dto.Titulo); model.Descricao = dto.Descricao; _tarefaRepository.Add(model); _unitOfWork.Complete(); }
public IActionResult Cadastro([FromForm] Tarefa tarefa, int projetoId) { ViewBag.Projetos = _projetoRepository.ObterTodos(); if (ModelState.IsValid) { _tarefaRepository.Add(tarefa); return(RedirectToAction("Todas", "Tarefa", new { id = tarefa.ProjetoId })); } ViewBag.Projeto = _projetoRepository.ObterPorId(projetoId); ViewBag.Mensagem = "Campos invalidos!"; return(View()); }
public Task <int> Handle(CreateTarefaCommand request, CancellationToken cancellationToken) { var model = new Tarefa ( request.Titulo, request.Descricao ); _repository.Add(model); _repository.SaveChanges(); return(Task.FromResult(model.Id)); }
public async Task <IActionResult> Post(Tarefa model) { try { _repo.Add(model); if (await _repo.SaveChangesAsync()) { return(Created($"/api/value/{model.Id}", model)); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou")); } return(BadRequest()); }
public void Add(Tarefa tarefa) { _tarefaRepository.Add(tarefa); }