Beispiel #1
0
        public Retorno <object> Add(Apolice model)
        {
            Retorno <object> oRet = new Retorno <object>();

            try
            {
                if (String.IsNullOrEmpty(model.CPFCNPJ))
                {
                    throw new Exception("Informe o CPF/CNPJ");
                }
                if (String.IsNullOrEmpty(model.Placa))
                {
                    throw new Exception("Informe a placa");
                }
                if (model.ValorPremio <= 0)
                {
                    throw new Exception("Informe um valor válido");
                }

                _seguroDBContext.Add(model);
                _seguroDBContext.SaveChanges();
                oRet.setSuccesso();
                oRet.Object = model;
            }
            catch (System.Exception ex)
            {
                oRet.setErro(ex.Message);
            }
            return(oRet);
        }
Beispiel #2
0
        public Retorno <object> GetAll()
        {
            Retorno <object> oRet = new Retorno <object>();
            var lstApolices       = new List <Apolice>();

            try
            {
                lstApolices = (from p in _seguroDBContext.Apolice
                               select p).ToList();
                oRet.setSuccesso();
                oRet.Object = lstApolices;
            }
            catch (System.Exception ex)
            {
                oRet.setErro(ex.Message);
            }
            return(oRet);
        }
Beispiel #3
0
        public Retorno <object> Get(int id)
        {
            Retorno <object> oRet = new Retorno <object>();
            var apolice           = new Apolice();

            try
            {
                apolice = (from p in _seguroDBContext.Apolice
                           where p.NumApolice == id
                           select p).FirstOrDefault();

                oRet.setSuccesso();
                oRet.Object = apolice;
            }
            catch (System.Exception ex)
            {
                oRet.setErro(ex.Message);
            }
            return(oRet);
        }
Beispiel #4
0
        public Retorno Update(int id, Apolice model)
        {
            Retorno oRet = new Retorno();

            try
            {
                if (String.IsNullOrEmpty(model.CPFCNPJ))
                {
                    throw new Exception("Informe o CPF/CNPJ");
                }
                if (String.IsNullOrEmpty(model.Placa))
                {
                    throw new Exception("Informe a placa");
                }
                if (model.ValorPremio <= 0)
                {
                    throw new Exception("Informe um valor válido");
                }

                var apolice = (from p in _seguroDBContext.Apolice
                               where p.NumApolice == id
                               select p).FirstOrDefault();
                if (apolice != null)
                {
                    apolice.CPFCNPJ     = model.CPFCNPJ;
                    apolice.Placa       = model.Placa;
                    apolice.ValorPremio = model.ValorPremio;

                    _seguroDBContext.Update(apolice);
                    _seguroDBContext.SaveChanges();
                    oRet.setSuccesso();
                }
            }
            catch (System.Exception ex)
            {
                oRet.setErro(ex.Message);
            }
            return(oRet);
        }
Beispiel #5
0
        public Retorno Delete(int id)
        {
            Retorno oRet = new Retorno();

            try
            {
                var apolice = (from p in _seguroDBContext.Apolice
                               where p.NumApolice == id
                               select p).FirstOrDefault();
                if (apolice != null)
                {
                    _seguroDBContext.Remove(apolice);
                    _seguroDBContext.SaveChanges();
                    oRet.setSuccesso();
                }
            }
            catch (System.Exception ex)
            {
                oRet.setErro(ex.Message);
            }
            return(oRet);
        }