Esempio n. 1
0
        public Models.TbListinhaNegra Salvar(Models.TbListinhaNegra ln)
        {
            db.Add(ln);
            db.SaveChanges();

            return(ln);
        }
Esempio n. 2
0
        public Models.TbListinhaNegra ParaTabela(Models.Request.ListaNegraRequest request)
        {
            Models.TbListinhaNegra ln = new Models.TbListinhaNegra();
            ln.NmIndividuo = request.Individuo;
            ln.DsMotivo    = request.Motivo;
            ln.DtInclusao  = request.Inclusao;
            ln.DsLocal     = request.Local;

            return(ln);
        }
Esempio n. 3
0
 public Models.Response.ListaNegraResponse ParaResponse(Models.TbListinhaNegra ln)
 {
     Models.Response.ListaNegraResponse resp = new Models.Response.ListaNegraResponse();
     resp.Id       = ln.IdListaNegra;
     resp.Nome     = ln.NmIndividuo;
     resp.Motivo   = ln.DsMotivo;
     resp.Inclusao = ln.DtInclusao;
     resp.Local    = ln.DsLocal;
     resp.Foto     = ln.DsFoto;
     return(resp);
 }
Esempio n. 4
0
        public Models.TbListinhaNegra Deletar(int id)
        {
            Models.TbListinhaNegra ln =
                db.TbListinhaNegra.FirstOrDefault(x => x.IdListaNegra == id);

            if (ln != null)
            {
                db.TbListinhaNegra.Remove(ln);
                db.SaveChanges();
            }

            return(ln);
        }
Esempio n. 5
0
 public ActionResult <Models.Response.ListaNegraResponse> Deletar(int id)
 {
     try
     {
         Models.TbListinhaNegra             ln   = business.Deletar(id);
         Models.Response.ListaNegraResponse resp = conversor.ParaResponse(ln);
         return(resp);
     }
     catch (System.Exception ex)
     {
         return(BadRequest(
                    new Models.Response.ErroResponse(404, ex.Message)
                    ));
     }
 }
        public Models.TbListinhaNegra Salvar(Models.TbListinhaNegra ln)
        {
            if (string.IsNullOrEmpty(ln.NmIndividuo))
            {
                throw new Exception("Nome é obrigatório");
            }
            if (string.IsNullOrEmpty(ln.DsMotivo))
            {
                throw new Exception("Motivo é obrigatório");
            }
            //  if (string.IsNullOrEmpty(ln.DsLocal))
            //    throw new Exception("Local é obrigatório");

            return(db.Salvar(ln));
        }
Esempio n. 7
0
        public ActionResult <Models.Response.ListaNegraResponse> Alterar(int id, Models.Request.ListaNegraRequest request)
        {
            try
            {
                Models.TbListinhaNegra ln = conversor.ParaTabela(request);
                business.Alterar(id, ln);

                Models.Response.ListaNegraResponse resp = conversor.ParaResponse(ln);
                return(resp);
            }
            catch (System.Exception ex)
            {
                return(BadRequest(
                           new Models.Response.ErroResponse(404, ex.Message)
                           ));
            }
        }
Esempio n. 8
0
        public Models.TbListinhaNegra Alterar(int id, Models.TbListinhaNegra novo)
        {
            Models.TbListinhaNegra ln =
                db.TbListinhaNegra.FirstOrDefault(x => x.IdListaNegra == id);

            if (ln != null)
            {
                ln.NmIndividuo = novo.NmIndividuo;
                ln.DsMotivo    = novo.DsMotivo;
                ln.DsLocal     = novo.DsLocal;
                ln.DtInclusao  = novo.DtInclusao;

                db.SaveChanges();
            }

            return(ln);
        }
        public Models.TbListinhaNegra Alterar(int id, Models.TbListinhaNegra novo)
        {
            if (novo.NmIndividuo == string.Empty)
            {
                throw new Exception("Nome é obrigatório");
            }
            if (novo.DsMotivo == string.Empty)
            {
                throw new Exception("Motivo é obrigatório");
            }
            if (novo.DsLocal == string.Empty)
            {
                throw new Exception("Local é obrigatório");
            }


            return(db.Alterar(id, novo));
        }
Esempio n. 10
0
        public ActionResult <Models.Response.ListaNegraResponse> Inserir([FromForm] Models.Request.ListaNegraRequest request)
        {
            try
            {
                Models.TbListinhaNegra ln = conversor.ParaTabela(request);
                ln.DsFoto = gerenciadorFoto.GerarNovoNome(request.Foto.FileName);

                business.Salvar(ln);
                gerenciadorFoto.SalvarFoto(ln.DsFoto, request.Foto);

                Models.Response.ListaNegraResponse resp = conversor.ParaResponse(ln);
                return(resp);
            }
            catch (System.Exception ex)
            {
                return(BadRequest(
                           new Models.Response.ErroResponse(404, ex.Message)
                           ));
            }
        }