public Models.TbListaNegra Salvar(Models.TbListaNegra ln)
        {
            db.Add(ln);
            db.SaveChanges();

            return(ln);
        }
Пример #2
0
        public ActionResult <Models.Response.ListaNegraResponse> Inserir([FromForm] Models.Request.ListaNegraRequest request)
        {
            try
            {
                Models.TbListaNegra tbLista = conversor.ConversorParaModeloTabela(request);
                if (request.Foto == null)
                {
                    tbLista.DsFoto = "user.png";
                }

                else
                {
                    tbLista.DsFoto = gerenciadorFoto.GerarNovoNome(request.Foto.FileName);
                }

                business.Inserir(tbLista);

                if (request.Foto != null)
                {
                    gerenciadorFoto.SalvarFoto(tbLista.DsFoto, request.Foto);
                }


                Models.Response.ListaNegraResponse resp = conversor.ConversorParaModeloResponse(tbLista);

                return(resp);
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new Models.Response.ErroResponse(
                                      400, ex.Message
                                      )));
            }
        }
Пример #3
0
        public Models.TbListaNegra Inserir(Models.TbListaNegra tbLista)
        {
            if (string.IsNullOrEmpty(tbLista.NmPessoa))
            {
                throw new ArgumentException("O nome é obrigatório!");
            }

            if (string.IsNullOrEmpty(tbLista.DsMotivo))
            {
                throw new ArgumentException("O motivo é obrigatório!");
            }

            if (tbLista.DtInclusao == null)
            {
                throw new ArgumentException("A data de inclusão é obrigatória!");
            }

            if (string.IsNullOrEmpty(tbLista.DsLocal))
            {
                throw new ArgumentException("O local é obrigatório!");
            }

            if (tbLista.IdUsuario == 0)
            {
                throw new ArgumentException("Algo errado, tente novamente");
            }

            return(db.Inserir(tbLista));
        }
 public void Alterar(int id, Models.TbListaNegra req)
 {
     Models.TbListaNegra listaNegra = ctx.TbListaNegra.FirstOrDefault(x => x.IdListaNegra == id);
     listaNegra.NmPessoa   = req.NmPessoa;
     listaNegra.DtInclusao = req.DtInclusao;
     listaNegra.DsMotivo   = req.DsMotivo;
     listaNegra.DsLocal    = req.DsLocal;
     listaNegra.DsFoto     = req.DsFoto;
     ctx.SaveChanges();
 }
Пример #5
0
        public Models.TbListaNegra Deletar(int id)
        {
            Models.TbListaNegra ln =
                db.TbListaNegra.FirstOrDefault(x => x.IdListaNegra == id);

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

            return(ln);
        }
Пример #6
0
        public Models.TbListaNegra Salvar(Models.TbListaNegra ln)
        {
            if (string.IsNullOrEmpty(ln.NmPessoa))
            {
                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));
        }
Пример #7
0
        public Models.TbListaNegra Alterar(int id, Models.TbListaNegra novo)
        {
            Models.TbListaNegra ln =
                db.TbListaNegra.FirstOrDefault(x => x.IdListaNegra == id);

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

                db.SaveChanges();
            }

            return(ln);
        }
Пример #8
0
        public Models.TbListaNegra Alterar(int id, Models.TbListaNegra novo)
        {
            if (novo.NmPessoa == 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));
        }
Пример #9
0
        public ActionResult <Models.TbListaNegra> Alterar(int id, [FromForm] Models.Request.ListaNegraRequest req)
        {
            try
            {
                Models.TbListaNegra lista = conversor.ConversorParaModeloTabela(req);

                if (req.Foto != null)
                {
                    lista.DsFoto = gerenciadorFoto.GerarNovoNome(req.Foto.FileName);
                    gerenciadorFoto.SalvarFoto(lista.DsFoto, req.Foto);
                }

                business.Alterar(id, lista);
                return(lista);
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new Models.Response.ErroResponse(
                                      400, ex.Message
                                      )));
            }
        }
Пример #10
0
        public void Alterar(int id, Models.TbListaNegra tbLista)
        {
            if (tbLista.NmPessoa == string.Empty)
            {
                throw new ArgumentException("O nome é obrigatório!");
            }

            if (tbLista.DsMotivo == string.Empty)
            {
                throw new ArgumentException("O motivo é obrigatório!");
            }
            if (tbLista.DtInclusao == null)
            {
                throw new ArgumentException("A data de inclusão é obrigatório!");
            }

            if (tbLista.DsLocal == string.Empty)
            {
                throw new ArgumentException("O local é obrigatório!");
            }

            db.Alterar(id, tbLista);
        }
 public void DeletarPessoa(int id)
 {
     Models.TbListaNegra listaNegra = ctx.TbListaNegra.FirstOrDefault(x => x.IdListaNegra == id);
     ctx.Remove(listaNegra);
     ctx.SaveChanges();
 }
 public Models.TbListaNegra Inserir(Models.TbListaNegra tbLista)
 {
     ctx.Add(tbLista);
     ctx.SaveChanges();
     return(tbLista);
 }