public ActionResult SalvarEdicaoTarefa(AlterarTarefaRequest alterarTarefaRequest)
        {
            try
            {
                if (_usuarioService.BuscarUsuarioSessao() == null)
                {
                    return(RedirectToAction("Index", "Usuario"));
                }

                _tarefaService.Alterar(alterarTarefaRequest);
                TempData["MensagemSucesso"] = "Tarefa alterada com sucesso";
                return(RedirectToAction("Index", "Tarefa"));
            }
            catch (Exception)
            {
                TempData["MensagemErro"] = "Erro ao tentar editar tarefa";
                return(RedirectToAction("Index", "Tarefa"));
            }
        }
        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));
        }
        public IHttpActionResult PutTarefa(int id, TarefaDTO tarefaDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tarefaDTO.TarefaId)
            {
                return(BadRequest());
            }

            try
            {
                var tarefaDomain = AutoMapper.Mapper.Map <Tarefa>(tarefaDTO);
                _tarefaService.Alterar(tarefaDomain);
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }