Exemplo n.º 1
0
        public async Task <ActionResult <Residencial> > PostResidencial(Residencial residencial)
        {
            _context.Residenciales.Add(residencial);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetResidencial", new { id = residencial.IdResidencial }, residencial));
        }
Exemplo n.º 2
0
 /* http://localhost:56067/Api/Residencials?cpf=12345678910&nome=fulano&marca=gm&ano=1998 */
 public void Post(string cpf, string nome, string cEP, string numeroDaCasa, string complemento, string tipo, string logradouro)
 {
     if (!string.IsNullOrEmpty(cpf))
     {
         using (var ctx = new ContextDB())
         {
             Cliente     cliente   = new Cliente(cpf, nome);
             Residencial cotacaoRE = new Residencial(cEP, numeroDaCasa, complemento, tipo, logradouro);
             try
             {
                 var BuscaCPF = ctx.Clientes.Where(c => c.CPF == cliente.CPF).FirstOrDefault();
                 if (cliente.CPF == BuscaCPF.CPF)
                 {
                     cotacaoRE.ClienteId = BuscaCPF.Id;
                     ctx.Residencials.Add(cotacaoRE);
                     ctx.SaveChanges();
                 }
             }
             catch (NullReferenceException)
             {
                 ctx.Clientes.Add(cliente);
                 ctx.Residencials.Add(cotacaoRE);
                 ctx.SaveChanges();
                 return;
             }
         }
     }
 }
Exemplo n.º 3
0
        public async Task <IActionResult> PutResidencial(int id, Residencial residencial)
        {
            if (id != residencial.IdResidencial)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> PutResidencial(int id, Residencial residencial)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != residencial.Id)
            {
                return(BadRequest());
            }

            db.Entry(residencial).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 5
0
        public void Post(string cpf, string nome, string cEP, string numeroDaCasa, string complemento, string logradouro, string aptocasa, string iqre, string ferb, string dt, string ppa)
        {
            //iqre = Incêndio, queda de raio e explosão
            //ferb = Furto, Extorsão e Roubo de Bens
            //dt = Danos a Terceiros
            //ppa = Perda ou Pagamento de Aluguel
            //Esse post vai receber bool? idk, veremos

            if (!string.IsNullOrEmpty(cpf))
            {
                using (var ctx = new ContextDB())
                {
                    Cliente     cliente     = new Cliente(cpf, nome);
                    Residencial residencial = new Residencial(cEP, numeroDaCasa, complemento, logradouro, aptoCasa: bool.Parse(aptocasa), iQRE: bool.Parse(iqre), fERB: bool.Parse(ferb), dT: bool.Parse(dt), pPA: bool.Parse(ppa));
                    try
                    {
                        var BuscaCPF = ctx.Clientes.Where(c => c.CPF == cliente.CPF).FirstOrDefault();
                        if (cliente.CPF == BuscaCPF.CPF)
                        {
                            residencial.ClienteId = BuscaCPF.Id;
                            ctx.Residencials.Add(residencial);
                            ctx.SaveChanges();
                        }
                    }
                    catch (NullReferenceException)
                    {
                        ctx.Clientes.Add(cliente);
                        ctx.Residencials.Add(residencial);
                        ctx.SaveChanges();
                        return;
                    }
                }
            }
        }
Exemplo n.º 6
0
        public async Task <IHttpActionResult> GetResidencial(int id)
        {
            Residencial residencial = await db.Residencials.FindAsync(id);

            if (residencial == null)
            {
                return(NotFound());
            }

            return(Ok(residencial));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> PostResidencial(Residencial residencial)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Residencials.Add(residencial);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = residencial.Id }, residencial));
        }
Exemplo n.º 8
0
        public async Task <IHttpActionResult> DeleteResidencial(int id)
        {
            Residencial residencial = await db.Residencials.FindAsync(id);

            if (residencial == null)
            {
                return(NotFound());
            }

            db.Residencials.Remove(residencial);
            await db.SaveChangesAsync();

            return(Ok(residencial));
        }