public async Task <bool> AdicionarItem(TarefaItem tarefaItem)
        {
            this._context.Add(tarefaItem);
            await _context.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> EditarItem(TarefaItem tarefaItem)
        {
            try
            {
                _context.Update(tarefaItem);
                int retorno = await _context.SaveChangesAsync();

                if (retorno > 0)
                {
                    return(true);
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!ContatoExiste(tarefaItem.Id))
                {
                    throw new Exception("Tarefa não Existe!");
                }
                else
                {
                    throw ex;
                }
            }

            return(false);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefaItem)
        {
            if (id != tarefaItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tarefaItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TarefaItemExists(tarefaItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefaItem));
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefaItem)
        {
            if (id != tarefaItem.Id)
            {
                return(NotFound());
            }

            var currentUser = await _userManager.GetUserAsync(User);

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

            if (ModelState.IsValid)
            {
                try
                {
                    await _tarefaItemService.UpdateAsync(tarefaItem, currentUser);
                }
                catch (DbUpdateConcurrencyException) //Tratamento de concorrência (2 usuários editando ao mesmo tempo)
                {
                    throw;
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(tarefaItem));
        }
Beispiel #5
0
        public async Task <bool> DeletarItem(int?id)
        {
            //Save changes retorna o numero de linhas afetadas
            TarefaItem tarefa = _context.Tarefas.Find(id);

            _context.Tarefas.Remove(tarefa);
            return(await _context.SaveChangesAsync() == 1);
        }
Beispiel #6
0
        public async Task <bool> DeletarItem(int?id)
        {
            TarefaItem tarefa = _context.Tarefas.Find(id);

            _context.Tarefas.Remove(tarefa);
            var resultado = await _context.SaveChangesAsync();

            return(resultado == 1);
        }
        public async Task <IActionResult> AdicionarItemTarefa([Bind("Id, EstaCompleta, Nome, DataConclusao")] TarefaItem tarefa)
        {
            if (ModelState.IsValid)
            {
                await _tarefaService.AdicionarItem(tarefa);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
        public IActionResult Create([FromBody] TarefaItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }
            _tarefaRepositorio.Add(item);

            return(CreatedAtRoute("GetTarefa", new { id = item.Chave }, item));
        }
Beispiel #9
0
        public async Task Update(TarefaItem item)
        {
            if (item == null)
            {
                throw new ArgumentException(nameof(item));
            }

            _context.Tarefas.Update(item);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefaItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tarefaItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefaItem));
        }
Beispiel #11
0
        public async Task <IActionResult> AdicionarItemTarefa(TarefaItem tarefa)
        {
            if (ModelState.IsValid)
            {
                await _tarefaService.AdicionarItem(tarefa);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(tarefa));
        }
        public IActionResult Create([FromBody] TarefaItem item)
        {
            //o Atributo [FromBody] informa ao MVC para obter o valor do item tarefa a partir do corpo da requisição HTTP.


            if (item == null)
            {
                return(BadRequest());
            }
            _tarefaRepositorio.Add(item);
            return(CreatedAtRoute("GetTarefa", new { id = item.Chave }, item));
        }
Beispiel #13
0
        public async Task <bool> DeletarItem(int?Id)
        {
            TarefaItem tarefa = _context.Tarefas.Find(Id);

            _context.Tarefas.Remove(tarefa);

            //Will return the numbers of rows affected, if only one item have been changed
            //The task should be successeful
            var resultado = await _context.SaveChangesAsync();

            return(resultado == 1);
        }
Beispiel #14
0
        public async Task <bool> AdicionarItemAsync(TarefaItem novoItem)
        {
            var tarefa = new TarefaItem
            {
                EstaCompleta  = false,
                Nome          = novoItem.Nome,
                OwnerId       = novoItem.OwnerId,
                DataConclusao = novoItem.DataConclusao
            };

            _context.Tarefas.Add(tarefa);
            return(await _context.SaveChangesAsync() == 1);
        }
        public async Task <bool> AdicionarItem(TarefaItem novaTarefa)
        {
            var tarefa = new TarefaItem {
                isCompleta    = false,
                Nome          = novaTarefa.Nome,
                DataConclusao = novaTarefa.DataConclusao
            };

            _context.Tarefas.Add(tarefa);
            var resultado = await _context.SaveChangesAsync();

            return(resultado == 1);
        }
Beispiel #16
0
        public async Task <IActionResult> AdicionarItemTarefa([Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefa)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            tarefa.OwnerId = currentUser.Id;

            if (ModelState.IsValid)
            {
                await _tarefaService.AdicionarItem(tarefa);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
        public async Task <bool> AdicionarItemTarefa(TarefaItem item)
        {
            var tarefa = new TarefaItem()
            {
                EstaCompleta        = false,
                Nome                = item.Nome,
                DataConclusaoTarefa = item.DataConclusaoTarefa
            };

            _context.Tarefas.Add(item);
            var result = await _context.SaveChangesAsync();

            return(result == 1);
        }
        public async Task Update(TarefaItem item, IdentityUser User)
        {
            if (item.OwnerId == null)
            {
                item.OwnerId = User.Id;
            }

            if (item == null)
            {
                throw new ArgumentException(nameof(item));
            }

            _contexto.Tarefas.Update(item);
            await _contexto.SaveChangesAsync();
        }
Beispiel #19
0
        public async Task UpdateAsync(TarefaItem item, ApplicationUser user)
        {
            if (item.OwnerId == null)
            {
                item.OwnerId = user.Id;
            }

            if (item == null)
            {
                throw new ArgumentException(nameof(item));
            }

            _context.Tarefas.Update(item);
            await _context.SaveChangesAsync();
        }
Beispiel #20
0
        public async Task <bool> AdicionarItem(TarefaItem novoItem)
        {
            // TarefaItem novoItemOut = new TarefaItem();

            // novoItemOut.EstaCompleta    = false;
            // novoItemOut.Nome            = novoItem.Nome;
            // novoItemOut.DataConclusao   = novoItem.DataConclusao;

            // _context.Tarefas.Add(novoItemOut);

            _context.Tarefas.Add(novoItem);

            var resultado = await _context.SaveChangesAsync();

            return(resultado == 1);
        }
Beispiel #21
0
        public async Task <bool> AdicionarItem(TarefaItem NovoItem)
        {
            var tarefa = new TarefaItem
            {
                EstaCompleta  = false,
                Nome          = NovoItem.Nome,
                DataConclusao = NovoItem.DataConclusao
            };

            //Add task to database context
            _context.Tarefas.Add(tarefa);
            //Persist task to database
            var resultado = await _context.SaveChangesAsync();

            return(resultado == 1);;
        }
Beispiel #22
0
        public async Task <IActionResult> Create([Bind("Nome,DataConclusao,EstaCompleta")] TarefaItem tarefa)
        {
            if (ModelState.IsValid)
            {
                var isOk = await _tarefaService.AdicionarItem(tarefa);

                if (isOk)
                {
                    return(RedirectToAction("Index"));
                }

                return(NotFound());
            }

            return(View(tarefa));
        }
        public IActionResult Update(long id, [FromBody] TarefaItem item)
        {
            if (item == null || item.Chave != id)
            {
                return(BadRequest());
            }
            var tarefa = _tarefaRepositorio.Find(id);

            if (tarefa == null)
            {
                return(NotFound());
            }
            //tarefa.EstaCompleta = item.EstaCompleta;
            tarefa.Nome = item.Nome;
            _tarefaRepositorio.Update(tarefa);
            return(new NoContentResult());
        }
Beispiel #24
0
        public async Task <IActionResult> Edit([Bind("Id,Nome,DataConclusao,EstaCompleta")] TarefaItem tarefa)
        {
            if (tarefa == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try { await _tarefaService.EditarItem(tarefa); }
                catch { return(NotFound()); }

                return(RedirectToAction("Index"));
            }

            return(View(tarefa));
        }
        public async Task <IActionResult> Edit(int?id, [Bind("id,EstaCompleta,Nome,DataConclusaoTarefa")] TarefaItem tarefa)
        {
            if (id != tarefa.id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try {
                    await _tarefaItemService.Update(tarefa);
                } catch (DbUpdateConcurrencyException ex) {
                    throw ex;
                } catch (Exception e) {
                    throw e;
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
Beispiel #26
0
        public async Task <IActionResult> AdicionarItemTarefa([Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefa)
        {
            //Este Bind informa quais campos o DataBind deve vincular, só será permitido a injeção na tarefa desses 4 campos
            //O Bind é uma maneira de restringir, proteger.
            if (ModelState.IsValid)
            {
                var currentUser = await _userManager.GetUserAsync(User);

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

                tarefa.OwnerId = currentUser.Id;
                await _tarefaItemService.AdicionarItemAsync(tarefa);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(tarefa));
        }
Beispiel #27
0
        public async Task <IActionResult> Edit(int Id, [Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem TarefaItem)
        {
            if (Id != TarefaItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _TarefaService.Update(TarefaItem);
                }
                catch
                {
                    throw;
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(TarefaItem));
        }
Beispiel #28
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,EstaCompleta,Nome,DataConclusao")] TarefaItem tarefaItem)
        {
            if (id != tarefaItem.Id)
            {
                return(NotFound());
            }

            var currentUser = await _userManager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                try
                {
                    await _tarefaService.Update(tarefaItem, currentUser);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefaItem));
        }
 public Task Update(TarefaItem item, IdentityUser User)
 {
     throw new NotImplementedException();
 }
 public Task Update(TarefaItem item)
 {
     throw new NotImplementedException();
 }