Exemplo n.º 1
0
        public void Delete(Guid id)
        {
            var data = GetData(id);

            data.OnAuditDelete(DateTime.Now);

            _context.Update(data);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Email,Telefonefixo,Telefonecelular,Empresa,Cargo,Dataaniversario")] Contatos contatos)
        {
            if (id != contatos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contatos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContatosExists(contatos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contatos));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,Name,Address,Phone")] Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Email,Senha")] Usuarios usuarios)
        {
            if (id != usuarios.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(usuarios);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsuariosExists(usuarios.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(usuarios));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Titulo,Descricao,Data,HorarioInicio,HorarioFim")] Tarefa tarefa)
        {
            if (id != tarefa.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tarefa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TarefaExists(tarefa.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,LastName,Email,Phone")] Contacts contacts)
        {
            if (id != contacts.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contacts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContactsExists(contacts.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contacts));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre,Apellido,Email,Numero,Tipo")] Registro registro)
        {
            if (id != registro.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(registro);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RegistroExists(registro.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(registro));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("TacheId,Title,Description,Debut,Fin,Priorite")] Tache tache)
        {
            if (id != tache.TacheId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tache);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TacheExists(tache.TacheId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tache));
        }
        public void Update(Contact obj)
        {
            if (!_context.Contact.Any(c => c.Id == obj.Id))
            {
                throw new NotFoundException("Id not found");
            }

            try
            {
                _context.Update(obj);
                _context.SaveChanges();
            }
            catch (DbConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }
Exemplo n.º 10
0
        public async Task <bool> Atualizar(Usuario usuario)
        {
            _banco.Update(usuario);
            _banco.SaveChanges();

            if (UsuarioExiste(usuario.Id))
            {
                _banco.Usuario.Update(usuario);
                await _banco.SaveChangesAsync();

                return(await Task.FromResult(true));
            }
            else
            {
                return(await Task.FromResult(false));
            }
        }
Exemplo n.º 11
0
        private void BtnSalvarEvento_Click(object sender, EventArgs e)
        {
            if (Singleton.alteracaoDeEvento == false)
            {
                //Checa as validacoes antes
                if (Singleton.ListaConvidado.Convidados.Count == 0)
                {
                    MessageBox.Show("Preencha a lista de convidados");
                }
                else if (DataFim.Value <= DateTime.Now)
                {
                    MessageBox.Show("A data de saida tem q ser maior que a data de hoje");
                }
                else if (DataComeco.Value <= DateTime.Now)
                {
                    MessageBox.Show("A data de comeco tem q ser maior que a data de hoje");
                }
                else if (DataComeco.Value >= DataFim.Value)
                {
                    MessageBox.Show("A data estao com horarios incompativeis");
                }
                else if (TxtEventoLocal.Text.Trim() == "")
                {
                    MessageBox.Show("Preencha o local !");
                }
                else if (TxtEventoNome.Text.Trim() == "")
                {
                    MessageBox.Show("Preencha o nome do evento!");
                }
                else if (TxtDescricao.Text.Trim() == "")
                {
                    MessageBox.Show("Preencha a descricao");
                }
                else
                {
                    bool permiteSalvarNoBanco = true;
                    //Faz uma validacao pra ver se vc ja tem um evento em tal horario
                    //Se o horario de um evento ja marcado bater, vai retornar o item de uma lista
                    List <Evento> comparacaoDeEventoPorHorario = _context.Eventos.ToList();

                    foreach (var item in comparacaoDeEventoPorHorario)
                    {
                        if (item.HorarioComeco > DataComeco.Value && item.HorarioComeco > DataFim.Value)
                        {
                        }
                        else if (item.HorarioFim < DataComeco.Value && item.HorarioFim < DataFim.Value)
                        {
                        }
                        else
                        {
                            MessageBox.Show("Em sua agenda de eventos, dentro do horario estipulado já existe um evento nesse horario");
                            permiteSalvarNoBanco = false;
                            break;
                        }
                    }

                    if (permiteSalvarNoBanco)
                    {
                        string tipoEvento;
                        if (RBtnExclusivo.Checked)
                        {
                            tipoEvento = "Exclusivo";
                        }
                        else
                        {
                            tipoEvento = "Compartilhado";
                        }

                        var _evento = new Evento()
                        {
                            EventoId      = 0,
                            Descricao     = TxtDescricao.Text,
                            EventoTipo    = tipoEvento,
                            Local         = TxtEventoLocal.Text.Trim(),
                            Nome          = TxtEventoNome.Text.Trim(),
                            UsuarioId     = Singleton.UsuarioLogado.UserId,
                            HorarioComeco = DataComeco.Value,
                            HorarioFim    = DataFim.Value,
                        };

                        try
                        {
                            _context.Update(_evento);
                            _context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            Utilidades.MensagemErro(ex.Message);
                        }

                        List <Participante> participantes = new List <Participante>();
                        foreach (var participante in Singleton.ListaConvidado.Convidados)
                        {
                            participantes.Add(new Participante
                            {
                                ParticipanteId   = 0,
                                EventoId         = _evento.EventoId,
                                NomeParticipante = participante
                            });
                        }

                        try
                        {
                            _context.UpdateRange(participantes);
                            _context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            Utilidades.MensagemErro(ex.Message);
                        }
                        //Implementar com mais de um usuario, com a lista de amizade
                        EventoUsuario eventoUsuario = new EventoUsuario()
                        {
                            EventoId  = _evento.EventoId,
                            UsuarioId = Singleton.UsuarioLogado.UserId,
                        };

                        var dialogResult = MessageBox.Show("Operacao realizada com sucesso!", "Deseja cadastrar mais um evento?", MessageBoxButtons.YesNo);

                        if (dialogResult == DialogResult.Yes)
                        {
                            TxtDescricao.Text   = "";
                            TxtEventoLocal.Text = "";
                            TxtEventoNome.Text  = "";

                            Singleton.ListaConvidado.Convidados.Clear();
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                }
            }
            else
            {
                //OPERACAO PARA ALTERAR
            }
        }
Exemplo n.º 12
0
 public T Atualizar(Guid id, T entity)
 {
     _agendaContext.Update <T>(entity);
     _agendaContext.SaveChanges();
     return(entity);
 }