コード例 #1
0
    public async Task <ActionResult <TipoTarefa> > Post([FromBody] TipoTarefa obj)
    {
        if (!ModelState.IsValid)
        {
            return(BadRequest(ModelState));
        }

        try
        {
            obj = await _unitOfWork.TipoTarefaRepository.AddAsync(obj);

            await _unitOfWork.SaveChangesAsync();
        }
        catch (Exception)
        {
            if (await ObjExists(obj.Id))
            {
                return(Conflict());
            }
            else
            {
                throw;
            }
        }

        return(CreatedAtRoute("GetTipoTarefa", new { id = obj.Id }, obj));
    }
コード例 #2
0
    public async Task <IActionResult> Put(Guid id, [FromBody] TipoTarefa obj)
    {
        if (!ModelState.IsValid)
        {
            return(BadRequest(ModelState));
        }

        if (id != obj.Id)
        {
            return(BadRequest());
        }

        try
        {
            _unitOfWork.TipoTarefaRepository.Update(obj);

            await _unitOfWork.SaveChangesAsync();
        }
        catch (Exception)
        {
            if (!await ObjExists(id))
            {
                return(NotFound());
            }
            else
            {
                throw;
            }
        }

        return(NoContent());
    }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("TipoId,TipoNome")] TipoTarefa tipoTarefa)
        {
            if (id != tipoTarefa.TipoId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipoTarefa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoTarefaExists(tipoTarefa.TipoId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoTarefa));
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipoTarefa tipoTarefa = db.TiposDeTarefa.Find(id);

            db.TiposDeTarefa.Remove(tipoTarefa);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
ファイル: TarefaService.cs プロジェクト: juniferdev/teamwork
 public TarefaService(string nome, TipoTarefa tipo, string descricao, DateTime dataInicio, DateTime dataTermino)
 {
     TarefaNomeServ            = nome;
     TipoTarefaServ            = tipo;
     TarefaDescricaoServ       = descricao;
     TarefaDataPrevInicioServ  = dataInicio;
     TarefaDataPrevTerminoServ = dataTermino;
 }
コード例 #6
0
ファイル: TarefaService.cs プロジェクト: juniferdev/teamwork
 public TarefaService(string nome, TipoTarefa tipo, string descricao, DateTime dataInicio, DateTime dataTermino, int IdResponsavel, int IdProjeto)
 {
     TarefaNomeServ            = nome;
     TipoTarefaServ            = tipo;
     TarefaDescricaoServ       = descricao;
     TarefaDataPrevInicioServ  = dataInicio;
     TarefaDataPrevTerminoServ = dataTermino;
     IdProjetoServ             = IdProjeto;
 }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "Id,DesignacaoTipoTarefa")] TipoTarefa tipoTarefa)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tipoTarefa).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoTarefa));
 }
コード例 #8
0
        public ActionResult Create([Bind(Include = "Id,DesignacaoTipoTarefa")] TipoTarefa tipoTarefa)
        {
            if (ModelState.IsValid)
            {
                db.TiposDeTarefa.Add(tipoTarefa);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tipoTarefa));
        }
コード例 #9
0
    public async Task <ActionResult <TipoTarefa> > Get(Guid id)
    {
        TipoTarefa tipoTarefa = await _unitOfWork.TipoTarefaRepository.GetAsync(id);

        if (tipoTarefa == null)
        {
            return(NotFound());
        }

        return(Ok(tipoTarefa));
    }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("TipoId,TipoNome")] TipoTarefa tipoTarefa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tipoTarefa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoTarefa));
        }
コード例 #11
0
        // GET: TipoTarefas/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoTarefa tipoTarefa = db.TiposDeTarefa.Find(id);

            if (tipoTarefa == null)
            {
                return(HttpNotFound());
            }
            return(View(tipoTarefa));
        }
コード例 #12
0
    public async Task <IActionResult> Delete(Guid id)
    {
        TipoTarefa obj = await _unitOfWork.TipoTarefaRepository.GetAsync(id);

        if (obj == null)
        {
            return(NotFound());
        }

        await _unitOfWork.TipoTarefaRepository.RemoveAsync(id);

        await _unitOfWork.SaveChangesAsync();

        return(NoContent());
    }
コード例 #13
0
    public async Task <OperationResult> Handle(RemoveTipoTarefaCommand request, CancellationToken cancellationToken)
    {
        TipoTarefa obj = await _unitOfWork.TipoTarefaRepository.GetAsync(request.Id);

        if (obj == null)
        {
            return(OperationResult.NotFound);
        }

        await _unitOfWork.TipoTarefaRepository.RemoveAsync(request.Id);

        bool success = await _unitOfWork.SaveChangesAsync();

        OperationResult result = success ? OperationResult.Success : OperationResult.Failed;

        return(result);
    }
コード例 #14
0
    public async Task UpdateTipoTarefaCommand_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid     tipoTarefaId = Guid.NewGuid();
        DateTime dataInclusao = DateTime.Now;

        TipoTarefa tipoTarefa = MockEntityHelper.GetNewTipoTarefa(tipoTarefaId);

        await unitOfWork.TipoTarefaRepository.AddAsync(tipoTarefa);

        await unitOfWork.SaveChangesAsync();

        unitOfWork.TipoTarefaRepository.Detatch(tipoTarefa);

        UpdateTipoTarefaCommand request = new()
        {
            TipoTarefa = MockViewModelHelper.GetNewTipoTarefa(tipoTarefaId, dataInclusao)
        };

        GetTipoTarefaQuery request2 = new()
        {
            Id = tipoTarefaId
        };

        // Act
        TipoTarefaHandler handler  = new(unitOfWork, mapper);
        OperationResult   response = await handler.Handle(request, CancellationToken.None);

        TipoTarefaViewModel response2 = await handler.Handle(request2, CancellationToken.None);

        // Assert
        Assert.True(response == OperationResult.Success);
        Assert.True(response2 != null);
        Assert.True(response2.Id == tipoTarefaId);
        Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks);
    }
}
コード例 #15
0
    protected void Salvar_Click(object sender, EventArgs e)
    {
        int        dsTipoTarefa  = Convert.ToInt32(tipoTarefa.SelectedValue);
        TipoTarefa auxTipoTarefa = (TipoTarefa)dsTipoTarefa;

        if (string.IsNullOrWhiteSpace(txtCodigo.Text))
        {
            var listaParticipantes = new List <Pessoa>();
            foreach (var nomePessoa in txtParticipantes.Text.Split(',').ToList <string>())
            {
                Pessoa pessoa = PessoaController.Lista().FirstOrDefault(p => p.Nome.Equals(nomePessoa));
                if (pessoa == null || !(pessoa.IdPessoa >= 1))
                {
                    pessoa = PessoaController.Inseir(new Pessoa()
                    {
                        Nome  = nomePessoa,
                        Papel = Papel.Outros
                    });
                }
                listaParticipantes.Add(pessoa);
            }

            var listaMaterias = new List <Materia>();
            foreach (var nomeMateria in txtParticipantes.Text.Split(',').ToList <string>())
            {
                Materia materia = MateriaController.Lista().FirstOrDefault(p => p.Nome.Equals(nomeMateria));
                if (materia == null || !(materia.IdMateria >= 1))
                {
                    materia = MateriaController.Inseir(new Materia()
                    {
                        Nome = nomeMateria
                    });
                }
                listaMaterias.Add(materia);
            }

            TarefaController.Inseir(new Tarefa()
            {
                DataCadastro      = DateTime.Now,
                DataLimite        = Convert.ToDateTime(txtDataLimite.Text),
                DescricaoResumida = txtDescResumida.Text,
                DescricaoCompleta = txtDescCompleta.Text,
                TipoTarefa        = auxTipoTarefa,
                Participantes     = listaParticipantes,
                Materias          = listaMaterias
            });

            msgRegistro.CssClass = "text-success";
            msgRegistro.Text     = "Registo salvo com sucesso.";
            msgRegistro.Visible  = true;
        }
        else
        {
            int codigo = Convert.ToInt32(hdnCodigo.Value);
            var tarefa = TarefaController.Lista().FirstOrDefault(p => p.IdTarefa == codigo);
            if (tarefa == null)
            {
                msgRegistro.CssClass = "text-danger";
                msgRegistro.Text     = "Não foi possível identificar o registro.";
                msgRegistro.Visible  = true;
                return;
            }

            tarefa.DataLimite        = Convert.ToDateTime(txtDataLimite.Text);
            tarefa.DescricaoResumida = txtDescResumida.Text;
            tarefa.DescricaoCompleta = txtDescCompleta.Text;
            tarefa.TipoTarefa        = auxTipoTarefa;

            TarefaController.Editar(tarefa);

            msgRegistro.CssClass = "text-success";
            msgRegistro.Text     = "Registo atualizado com sucesso.";
            msgRegistro.Visible  = true;
        }
    }