private int[] ObterIdsTags(TarefaViewModel tarefaView)
        {
            int[] retorno = null;

            if (tarefaView.Tags != null && tarefaView.Tags.Count() != 0)
            {
                retorno = new int[tarefaView.Tags.Count()];
                int cont = 0;

                foreach (var item in tarefaView.Tags)
                {
                    retorno[cont] = item.TagId;
                    cont++;
                }
            }


            return(retorno);
        }
Exemple #2
0
        public bool Adicionar(TarefaViewModel tarefaViewModel)
        {
            var sucesso = true;

            try
            {
                var tarefa = _mapper.Map <Tarefa>(tarefaViewModel);
                tarefa.SetDataCriacao(DateTime.Now);
                _tarefaService.Adicionar(tarefa);

                sucesso = Commit();
            }
            catch (Exception ex)
            {
                //TODO: Log
            }

            return(sucesso);
        }
Exemple #3
0
        //List<TarefaViewModel> listaDeTarefas = new List<TarefaViewModel>();

        public TarefaViewModel Inserir(TarefaViewModel tarefa)
        {
            int contador = 0;
            List <TarefaViewModel> listaDeTarefas = Listar();

            if (listaDeTarefas != null)
            {
                contador = listaDeTarefas.Count;
            }

            tarefa.Id          = contador + 1;
            tarefa.DataCriacao = DateTime.Now;
            // listaDeTarefas.Add(tarefa);
            StreamWriter sw = new StreamWriter("tarefas.csv");

            sw.WriteLine($"{tarefa.Id};{tarefa.Nome};{tarefa.Descricao};{tarefa.Tipo};{tarefa.DataCriacao}");
            sw.Close();

            return(tarefa);
        }
Exemple #4
0
        public void Test_OnGet()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            TarefaViewModel tarefaMock = new TarefaViewModel {
            };

            _tarefaAppService.Setup(x => x.Consultar(id)).Returns(tarefaMock);

            RemoverModel pageModel = new RemoverModel(_tarefaAppService.Object);
            PageModelTester <RemoverModel> pageTester = new PageModelTester <RemoverModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(id))

            // Assert
            .TestPage();
        }
        // lista de tarefas
        public async Task <IActionResult> Index()
        {
            // obter os dados e retornar
            //TempTarefaItemService servico = new TempTarefaItemService();
            //var tarefas = servico.GetItemAsync();
            //return View(tarefas);

            // obter os dados e retornar
            //var tarefas = _tarefaService.GetItemAsync();

            var tarefas = await _tarefaService.GetItemAsync();

            var model = new TarefaViewModel();

            {
                model.TarefaItens = tarefas;
            }

            return(View(model));
        }
Exemple #6
0
 public ActionResult NovaTarefa(TarefaViewModel tarefaView)
 {
     if (ModelState.IsValid)
     {
         Data      objData   = new Data();
         TarefaMOD tarefaMOD = new TarefaMOD()
         {
             Nome       = tarefaView.Nome,
             Prioridade = tarefaView.Prioridade,
             Concluido  = tarefaView.Concluido,
             Observacao = tarefaView.Observacao
         };
         var resultado = objData.CriarTarefa(tarefaMOD);
         return(RedirectToAction("ListarNovasTarefas"));
     }
     else
     {
         ViewBag.Alerta = "Verifique os dados do formulario";
     }
     return(View());
 }
Exemple #7
0
    public async Task <IActionResult> OnPostAsync()
    {
        try
        {
            if (!ModelState.IsValid)
            {
                Tarefa = await _cpnucleoApiService.GetAsync <TarefaViewModel>("tarefa", Token, Tarefa.Id);

                return(Page());
            }

            await _cpnucleoApiService.DeleteAsync("tarefa", Token, Tarefa.Id);

            return(RedirectToPage("Listar"));
        }
        catch (Exception ex)
        {
            ModelState.AddModelError(string.Empty, ex.Message);
            return(Page());
        }
    }
Exemple #8
0
        public ActionResult ObterAlunos(TarefaViewModel viewModel)
        {
            using (var client = new WebClient()) {
                try {
                    var obj    = client.DownloadString(APIUrl.TurmaObterAlunos(viewModel.TurmaEscolhida, viewModel.Id));
                    var alunos = JsonConvert.DeserializeObject(obj, typeof(List <Interface.AlunoTarefa>));

                    var listaAlunoViewModel = Mapper.Map <List <AlunoTarefaViewModel> >(alunos);

                    foreach (var lista in listaAlunoViewModel)
                    {
                        lista.IdTarefa = viewModel.Id;
                    }

                    return(PartialView("_ListaAlunos", listaAlunoViewModel));
                } catch (WebException ex) {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(null);
                }
            }
        }
Exemple #9
0
        public async Task <IActionResult> Edit(int id, [Bind(nameof(TarefaViewModel.Id), nameof(TarefaViewModel.Nome), nameof(TarefaViewModel.Completa))] TarefaViewModel editarTarefa)
        {
            if (id != editarTarefa.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await servico.EditarAsync(editarTarefa);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Tarefa)));
            }
            return(View(editarTarefa));
        }
        public ActionResult Edit([Bind(Include = "TarefaId,Nome,Descricao,Situacao,DataCriacao, DataFinalizacao,HoraFinalizacao,CategoriaId,TagsIds,UsuarioId")] TarefaViewModel tarefaView)
        {
            if (ModelState.IsValid)
            {
                ObterIdUsuario();
                var tarefaDomain = AutoMapper.Mapper.Map <Tarefa>(tarefaView);
                tarefaDomain.Tags = _tagService.ObterTodos().Where(m => tarefaView.TagsIds.Contains(m.TagId)).ToList();

                var tarefaBase = _tarefaService.ObterPorId(tarefaDomain.TarefaId);
                tarefaBase.AtualizarTarefa(tarefaDomain);

                VerificaFinalizacaoTarefa(tarefaBase);
                _tarefaService.Alterar(tarefaBase);

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoriaId = new SelectList(ObterTodasCategorias(), "CategoriaId", "Nome", tarefaView.CategoriaId);
            ViewBag.Tags        = new MultiSelectList(ObterTodasTags(), "TagId", "Nome", ObterIdsTags(tarefaView));
            return(View(tarefaView));
        }
Exemple #11
0
        public void Test_OnPost(int percentualTarefa)
        {
            // Arrange
            Guid idTarefa  = Guid.NewGuid();
            Guid idProjeto = Guid.NewGuid();

            List <RecursoProjetoViewModel> listaMock = new List <RecursoProjetoViewModel> {
            };
            TarefaViewModel tarefaMock = new TarefaViewModel {
            };
            RecursoTarefaViewModel recursoTarefaMock = new RecursoTarefaViewModel {
                IdTarefa = idTarefa, PercentualTarefa = percentualTarefa, Tarefa = new TarefaViewModel()
            };

            _tarefaAppService.Setup(x => x.Consultar(idTarefa)).Returns(tarefaMock);
            _recursoProjetoAppService.Setup(x => x.ListarPorProjeto(idProjeto)).Returns(listaMock);
            _recursoTarefaAppService.Setup(x => x.Incluir(recursoTarefaMock));

            IncluirModel pageModel = new IncluirModel(_recursoTarefaAppService.Object, _recursoProjetoAppService.Object, _tarefaAppService.Object);
            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(false)
            .TestPage();

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(true)
            .TestRedirectToPage("Listar");

            // Assert
            Validation.For(recursoTarefaMock).ShouldReturn.NoErrors();
        }
Exemple #12
0
    public async Task GetTarefaQuery_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid sistemaId = Guid.NewGuid();
        await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId));

        Guid projetoId = Guid.NewGuid();
        await unitOfWork.ProjetoRepository.AddAsync(MockEntityHelper.GetNewProjeto(sistemaId, projetoId));

        Guid workflowId = Guid.NewGuid();
        await unitOfWork.WorkflowRepository.AddAsync(MockEntityHelper.GetNewWorkflow(workflowId));

        Guid recursoId = Guid.NewGuid();
        await unitOfWork.RecursoRepository.AddAsync(MockEntityHelper.GetNewRecurso(recursoId));

        Guid tipoTarefaId = Guid.NewGuid();
        await unitOfWork.TipoTarefaRepository.AddAsync(MockEntityHelper.GetNewTipoTarefa(tipoTarefaId));

        Guid tarefaId = Guid.NewGuid();
        await unitOfWork.TarefaRepository.AddAsync(MockEntityHelper.GetNewTarefa(projetoId, workflowId, recursoId, tipoTarefaId, tarefaId));

        await unitOfWork.SaveChangesAsync();

        GetTarefaQuery request = new()
        {
            Id = tarefaId
        };

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

        // Assert
        Assert.True(response != null);
        Assert.True(response.Id != Guid.Empty);
        Assert.True(response.DataInclusao.Ticks != 0);
    }
Exemple #13
0
        public void Test_OnPost(string descricao)
        {
            // Arrange
            Guid id       = Guid.NewGuid();
            Guid idTarefa = Guid.NewGuid();

            ImpedimentoTarefaViewModel impedimentoTarefaMock = new ImpedimentoTarefaViewModel {
                Id = id, IdTarefa = idTarefa, Descricao = descricao
            };
            List <ImpedimentoViewModel> listaMock = new List <ImpedimentoViewModel> {
            };
            TarefaViewModel tarefaMock            = new TarefaViewModel {
            };

            _impedimentoTarefaAppService.Setup(x => x.Incluir(impedimentoTarefaMock));
            _impedimentoAppService.Setup(x => x.Listar()).Returns(listaMock);
            _tarefaAppService.Setup(x => x.Consultar(idTarefa)).Returns(tarefaMock);

            IncluirModel pageModel = new IncluirModel(_impedimentoTarefaAppService.Object, _impedimentoAppService.Object, _tarefaAppService.Object);
            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(false)
            .TestPage();

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(true)
            .TestRedirectToPage("Listar");

            // Assert
            Validation.For(impedimentoTarefaMock).ShouldReturn.NoErrors();
        }
        public JsonResult Inserir(string usuarioLogado, TarefaInclusaoViewModel tarefaInclusaoViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TarefaRepositorio  rep     = new TarefaRepositorio();
                    UsuarioRepositorio urep    = new UsuarioRepositorio();
                    Usuario            usuario = urep.EncontrarPorLogin(usuarioLogado);
                    Tarefa             tarefa  = new Tarefa()
                    {
                        IdTarefa    = 0,
                        Nome        = tarefaInclusaoViewModel.Nome,
                        DataEntrega = tarefaInclusaoViewModel.DataEntrega,
                        Descricao   = tarefaInclusaoViewModel.Descricao
                    };

                    Tarefa tarefa_inserida = rep.Inserir(usuario.IdUsuario, tarefa);

                    TarefaViewModel tarefaViewModel = new TarefaViewModel()
                    {
                        IdTarefa    = tarefa_inserida.IdTarefa,
                        Nome        = tarefa_inserida.Nome,
                        DataEntrega = tarefa_inserida.DataEntrega,
                        Descricao   = tarefa_inserida.Descricao
                    };

                    return(Json(new { sucesso = true, dados = tarefaViewModel }));
                }
                else
                {
                    return(Json(new { sucesso = false, dados = ModelState.Values.SelectMany(v => v.Errors).ToList() }));
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #15
0
        public async Task <IActionResult> Atualizar(Guid id, [FromBody] TarefaViewModel tarefaViewModel)
        {
            if (id != tarefaViewModel.Id)
            {
                NotificarErro("Os ids informados são diferentes!");
                return(CustomResponse());
            }

            var tarefaParaAtualizar = await ObterTarefa(id);

            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }

            tarefaParaAtualizar.Nome      = tarefaViewModel.Nome;
            tarefaParaAtualizar.Realizada = tarefaViewModel.Realizada;

            await _tarefaService.Atualizar(_mapper.Map <Tarefa>(tarefaParaAtualizar));

            return(CustomResponse(tarefaViewModel));
        }
        public ActionResult Alterar(TarefaViewModel model)
        {
            if (ModelState.IsValid)

            {
                try
                {
                    var tarefa = _tarefaRepository.GetById(model.TarefaId);

                    tarefa.Titulo = model.Titulo;

                    _tarefaRepository.Update(tarefa);
                }
                catch (Exception e)
                {
                    ViewBag.Mensagem = e.Message;
                    return(View());
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
        public async Task <ActionResult <TarefaViewModel> > Adicionar(TarefaViewModel tarefaViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(CustomResponse(ModelState));
            }
            tarefaViewModel.Id = Guid.NewGuid();
            if (tarefaViewModel.ImagemUpload != null)
            {
                var caminho         = "/Paginas/Pdf/Tarefas/";
                var caminhoAmbiente = _env.WebRootPath;
                var gravaPdf        = Pdfs.UploadArquivo(tarefaViewModel.ImagemUpload, tarefaViewModel.Id.ToString(), caminho, caminhoAmbiente, false);
                if (gravaPdf.Key == 1)
                {
                    return(CustomResponse(gravaPdf.Value));
                }
                tarefaViewModel.CaminhoImagem = gravaPdf.Value;
            }

            var result = await _tarefaService.Adicionar(_mapper.Map <Tarefa>(tarefaViewModel));

            return(CustomResponse(tarefaViewModel));
        }
        public ActionResult Cadastro(TarefaViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var tarefa = new Tarefa();
                    tarefa.Titulo  = model.Titulo;
                    tarefa.Usuario = _usuarioRepository.GetById(int.Parse(Session["IdUsuario"].ToString()));
                    _tarefaRepository.Insert(tarefa);
                }
                catch (Exception e)
                {
                    ViewBag.Mensagem = e.Message;
                    return(View());
                }

                ViewBag.Mensagem = "Tarefa cadastrada com sucesso.";
                ModelState.Clear();
                return(RedirectToAction("index"));
            }
            return(View());
        }
Exemple #19
0
        public TarefaViewModel CarregarTarefa(string userId, long atividadeId)
        {
            var retorno = new TarefaViewModel
            {
                AnotacaoViewModal =
                {
                    AnotacoesApoio = _anotacaoApoioServico.ObterAnotacoesApoio(null, atividadeId, null,
                                                                               null, null)
                },
                StatusAtividade           = _statusAtividadeServico.ObterTodos(),
                TarefaAtividadeOcorrencia =
                    _tarefaAtividadeOcorrenciaServico.ObterTarefaAtividadeOcorrenciaApoio(atividadeId).FirstOrDefault(),
                AtividadeId = atividadeId
            };

            var atividade = _atividadeServico.ObterPorId(atividadeId);

            retorno.PodeEditar = string.IsNullOrEmpty(atividade.ResponsavelPorUserId)
                ? atividade.CriadoPorUserId == userId
                : atividade.ResponsavelPorUserId == userId;

            return(retorno);
        }
        public ActionResult NovaTarefa(TarefaViewModel tarefaView)
        {
            if (ModelState.IsValid)
            {
                Data   objData = new Data();
                Tarefa tarefa  = new Tarefa();

                tarefa.Nome       = tarefaView.Nome;
                tarefa.Prioridade = tarefaView.Prioridade;
                tarefa.Concluida  = tarefaView.Concluida;
                tarefa.Observacao = tarefaView.Observacao;

                var resultado = objData.CriarTarefa(tarefa);

                return(RedirectToAction("ListarNovasTarefas"));
            }
            else
            {
                ViewBag.Alerta = "Por favor verificar os dados do formulario";
            }

            return(View());
        }
Exemple #21
0
        public async Task <ActionResult> Index()
        {
            var    model  = new TarefaViewModel();
            string apiUrl = "http://localhost:9849/api/Tarefa/";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(apiUrl);

                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();

                    model.Lista = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tarefa> >(data);
                }
            }

            return(View(model));
        }
Exemple #22
0
        // lista de tarefas
        public async Task <IActionResult> Index(bool?criterio)
        {
            // Obter os dados da tarefa
            //TempTarefaItemService servico = new TempTarefaItemService();
            //var tarefas = servico.GetItemAsync();

            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var tarefas = await _tarefaService.GetItemAsync(criterio, currentUser);

            var model = new TarefaViewModel();

            {
                model.TarefaItens = tarefas;
            }

            return(View(model));
        }
Exemple #23
0
 public ActionResult Editar(int idTarefa, Tarefa tarefa)
 {
     if (!ModelState.IsValid)
     {
         var viewModel = new TarefaViewModel();
         viewModel.Tarefa = tarefa;
         return(View(viewModel));
     }
     if (idTarefa != tarefa.IdTarefa)
     {
         return(RedirectToAction(nameof(Error), new { menssagem = "id não corresponde ao vendedor" }));
     }
     try
     {
         var statusAntigo = _TarefaService.FindById(idTarefa).Status;
         if (!statusAntigo.Equals(tarefa.Status))
         {
             string nomeClasse = "TasksToEmail.Models.Tarefa" + statusAntigo;
             string nomeMetodo = "SetTarefa" + tarefa.Status;
             var    typeObj    = Type.GetType(nomeClasse);
             var    obj        = Activator.CreateInstance(typeObj);
             tarefa.SetStatus((TarefaStatus)obj);
             var metodo = tarefa.GetType().GetMethod(nomeMetodo);
             metodo.Invoke(tarefa, null);
         }
         _TarefaService.Update(tarefa);
         return(RedirectToAction(nameof(HomeController.Index)));
     }
     catch (NotFoundException e)
     {
         return(RedirectToAction(nameof(Error), new { menssagem = e.Message }));
     }
     catch (DbConcurrencyException e)
     {
         return(RedirectToAction(nameof(Error), new { menssagem = e.Message }));
     }
 }
Exemple #24
0
        public async Task <PartialViewResult> Pesquisa(string titulo, string descricao)
        {
            var    model  = new TarefaViewModel();
            string apiUrl = "http://localhost:9849/api/Tarefa/";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(apiUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync(apiUrl);

                if (response.IsSuccessStatusCode)
                {
                    var data = await response.Content.ReadAsStringAsync();

                    var listaCompleta = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Tarefa> >(data);
                    model.Lista = listaCompleta.Where(w => (w.Titulo.Contains(titulo) || string.IsNullOrEmpty(titulo)) && (w.Descricao.Contains(descricao) || string.IsNullOrEmpty(descricao))).ToList();
                }
            }

            return(PartialView("_Grid", model));
        }
Exemple #25
0
        public void Test_OnGet()
        {
            // Arrange
            Guid idTarefa  = Guid.NewGuid();
            Guid idProjeto = Guid.NewGuid();

            List <RecursoProjetoViewModel> listaMock = new List <RecursoProjetoViewModel> {
            };
            TarefaViewModel tarefaMock = new TarefaViewModel {
            };

            _tarefaAppService.Setup(x => x.Consultar(idTarefa)).Returns(tarefaMock);
            _recursoProjetoAppService.Setup(x => x.ListarPorProjeto(idProjeto)).Returns(listaMock);

            IncluirModel pageModel = new IncluirModel(_recursoTarefaAppService.Object, _recursoProjetoAppService.Object, _tarefaAppService.Object);
            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(idTarefa))

            // Assert
            .TestPage();
        }
Exemple #26
0
        public void Test_OnGet()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            TarefaViewModel tarefaMock = new TarefaViewModel {
            };
            List <ProjetoViewModel> listaProjetosMock      = new List <ProjetoViewModel> {
            };
            List <SistemaViewModel> listaSistemasMock      = new List <SistemaViewModel> {
            };
            List <WorkflowViewModel> listaWorkflowMock     = new List <WorkflowViewModel> {
            };
            List <TipoTarefaViewModel> listaTipoTarefaMock = new List <TipoTarefaViewModel> {
            };

            AlterarModel pageModel = new AlterarModel(_tarefaAppService.Object, _projetoAppService.Object, _sistemaAppService.Object, _workflowAppService.Object, _tipoTarefaAppService.Object)
            {
                PageContext = PageContextManager.CreatePageContext()
            };

            _tarefaAppService.Setup(x => x.Consultar(id)).Returns(tarefaMock);
            _projetoAppService.Setup(x => x.Listar()).Returns(listaProjetosMock);
            _sistemaAppService.Setup(x => x.Listar()).Returns(listaSistemasMock);
            _workflowAppService.Setup(x => x.Listar()).Returns(listaWorkflowMock);
            _tipoTarefaAppService.Setup(x => x.Listar()).Returns(listaTipoTarefaMock);

            PageModelTester <AlterarModel> pageTester = new PageModelTester <AlterarModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(id))

            // Assert
            .TestPage();
        }
        //private TarefaModel _tarefaInEdition;
        public TarefaPageView()
        {
            InitializeComponent();

            BindingContext = new TarefaViewModel();
        }
 public EditarSituacaoCommand(TarefaViewModel tarefaViewModel)
 {
     _tarefaViewModel = tarefaViewModel;
 }
Exemple #29
0
        public void Update(TarefaViewModel tarefaViewModel)
        {
            var updateCommand = _mapper.Map <AtualizarAlunoCommand>(tarefaViewModel);

            Bus.SendCommand(updateCommand);
        }
Exemple #30
0
        public void Register(TarefaViewModel tarefaViewModel)
        {
            var registerCommand = _mapper.Map <RegistrarTarefaCommand>(tarefaViewModel);

            Bus.SendCommand(registerCommand);
        }