public async Task <IActionResult> PutAgendaItem(long id, AgendaItem agendaItem)
        {
            if (id != agendaItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(agendaItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgendaItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateCustomer(long id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <IActionResult> PutContact(int id, Contact contact)
        {
            if (id != contact.ContactId)
            {
                return(BadRequest());
            }

            contact.DateUpdate            = DateTime.UtcNow;
            _context.Entry(contact).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> PutContacts([FromRoute] long id, [FromBody] Contacts contacts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contacts.IdUser)
            {
                return(BadRequest());
            }

            _context.Entry(contacts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <T> Create(T entity)
        {
            var result = await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(result.Entity);
        }
        public async Task <TblComunidade> Post(TblComunidade comunidade)
        {
            await context.AddAsync(comunidade);

            await context.SaveChangesAsync();

            return(comunidade);
        }
Esempio n. 7
0
        public async Task <ActionResult <Contato> > PostContato(Contato contato)
        {
            _context.Contatos.Add(contato);
            await _context.SaveChangesAsync();

            // A post method returns 200 or 201 (created) at its response. Inside CreatedAtAction, we add a Header 'Location' giving to the user,
            // the URI to access the resource that we have created.
            return(CreatedAtAction(nameof(GetContatoById), new { id = contato.Id }, contato));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,LastName,Email,Phone")] Contacts contacts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contacts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contacts));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("Id,Titulo,Descricao,Data,HorarioInicio,HorarioFim")] Tarefa tarefa)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tarefa);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tarefa));
        }
Esempio n. 10
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Senha")] Usuarios usuarios)
        {
            if (ModelState.IsValid)
            {
                _context.Add(usuarios);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(usuarios));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("CustomerId,Name,Address,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Email,Telefonefixo,Telefonecelular,Empresa,Cargo,Dataaniversario")] Contatos contatos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contatos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contatos));
        }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("TacheId,Title,Description,Debut,Fin,Priorite")] Tache tache)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tache);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tache));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("Id,Nombre,Apellido,Email,Numero,Tipo")] Registro registro)
        {
            if (ModelState.IsValid)
            {
                _context.Add(registro);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(registro));
        }
Esempio n. 15
0
        public async Task <bool> Add(Persona item)
        {
            try
            {
                context.Persona.Add(item);
                await context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <ActionResult> Create([Bind(Include = "TelephoneId,ContactId,TelephoneContent,ContactType")] Telephone telephone)
        {
            if (ModelState.IsValid)
            {
                var contact = db.Contatos.Find(telephone.ContactId);
                telephone.Contact = contact;
                db.Telefones.Add(telephone);

                await db.SaveChangesAsync();

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            ViewBag.ContactId = telephone.ContactId;
            return(View(telephone));
        }
Esempio n. 17
0
        public async Task <ActionResult> Create([Bind(Include = "AddressId,ContactId,AddressContent,ContactType")] Address address)
        {
            if (ModelState.IsValid)
            {
                address.AddressId = Guid.NewGuid().ToString();

                var contact = db.Contatos.Find(address.ContactId);
                address.Contact = contact;
                db.Enderecos.Add(address);

                await db.SaveChangesAsync();

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            return(View(address));
        }
Esempio n. 18
0
        public async Task <IActionResult> CreateUsuario(Usuario usuario)
        {
            context.Usuarios.Add(usuario);
            await context.SaveChangesAsync();

            /**
             * CreatedAtAction
             * 1º - Retorna STATUSCODE = 201 e adiciona ao Location a resposta
             * 2º - Refencia a ação GetUsuario
             * 3º - retorna usuário no qual usuario.include == id
             */
            return(CreatedAtAction(nameof(GetUsuario),
                                   new { id = usuario.Id },
                                   usuario
                                   ));
        }
        public async Task <ActionResult> Create([Bind(Include = "EmailId,ContactId,EmailContent,ContactType")] Email email)
        {
            if (ModelState.IsValid)
            {
                var contact = db.Contatos.Find(email.ContactId);
                email.Contact = contact;
                email.EmailId = Guid.NewGuid().ToString();

                db.Emails.Add(email);
                await db.SaveChangesAsync();

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            ViewBag.ContactId = email.ContactId;
            return(View(email));
        }
        public async Task <IActionResult> Post([FromBody] InfoModel info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorsHelp.ModelStateErrors(ModelState)));
            }
            if (await agendactx.DboInfos.Where(x => x.IdPersona == info.IdPersona).AnyAsync())
            {
                return(BadRequest(ErrorsHelp.RespuestaHttp(400, $"El ID: {info.IdPersona} ya existe.")));
            }
            if (await agendactx.DboInfos.Where(x => x.Email == info.Email).AnyAsync())
            {
                return(BadRequest(ErrorsHelp.RespuestaHttp(400, $"El correo electrónico: {info.Email}  ya existe.")));
            }

            await agendactx.DboInfos.AddAsync(info);

            await agendactx.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = info.IdPersona }, info));
        }
        public async Task <ActionResult> put(TblComunidade comunidade)
        {
            if (comunidade == null)
            {
                return(NotFound());
            }
            comunidade.NomeComunidade  = comunidade.NomeComunidade;
            comunidade.NomeResponsavel = comunidade.NomeResponsavel;
            context.TblComunidade.Update(comunidade);
            await context.SaveChangesAsync();


            return(NoContent());
        }
Esempio n. 22
0
        public async Task <bool> Atualizar(Contato contato)
        {
            if (ContatoExiste(contato.Id))
            {
                _banco.Contato.Update(contato);
                await _banco.SaveChangesAsync();

                return(await Task.FromResult(true));
            }
            else
            {
                return(await Task.FromResult(false));
            }
        }
Esempio n. 23
0
        public async Task <ActionResult> Create([Bind(Include = "ContactId,Name,Observation,FavoriteTag")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    contact.ContactId = Guid.NewGuid().ToString();
                    db.Contatos.Add(contact);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException exdb)
                {
                    throw exdb;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(View(contact));
        }
Esempio n. 24
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));
            }
        }
Esempio n. 25
0
        public void DeleteAgenda(int id)
        {
            var agenda = _context.Agenda.Find(id);

            if (agenda == null)
            {
                this.AdicionarNotificacao("Registro informado não existe");
                return;
            }
            try
            {
                _context.Agenda.Remove(agenda);
                _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                this.AdicionarNotificacao("Ocorreu um erro ao tentar excluir o registro");
            }
        }
Esempio n. 26
0
        public async Task <int> Post([FromBody] Agenda agenda)
        {
            _context.Agenda.Add(agenda);

            return(await _context.SaveChangesAsync());
        }
 public async Task InsertAsync(Consultas consulta)
 {
     _context.Add(consulta);
     await _context.SaveChangesAsync();
 }