Example #1
0
        public Retorno<PostBEC> Get(PostFilterBEC filterBEC)
        {
            var retorno = new Retorno<PostBEC> { Result = eResult.Inexistente };

            try
            {
                using (var context = new ContextDB())
                {
                    var post = (from p in context.PostSet
                                where p.id.Equals(filterBEC.id)
                                select new PostBEC
                                {
                                    id = p.id,
                                    Titulo = p.Titulo,
                                    Texto = p.Texto,
                                    Data = p.DataInclusao,
                                    URL = p.URL,
                                    Capa = p.Capa,
                                    TagSet = p.TagSet.Select(s => new PostTagBEC { Nome = s.Tag, URL = s.URL }).ToList(),
                                    Categoria = new PostCategoriaBEC { Nome = p.Categoria.Nome, URL = p.Categoria.URL },
                                    ImagemSet = p.ImagemSet.Select(s => new PostImagemBEC { id = s.id, Extensao = s.Extensao, Legenda = s.Legenda }).ToList(),

                                })
                            .FirstOrDefault();

                    if (post is PostBEC)
                    {
                        retorno.Entidade = post;
                        retorno.Result = eResult.Existente;
                    }

                }
            }
            catch (Exception _ex)
            {
                LogBEC logBEC = new LogBEC { Exception = _ex };
                LogBC.Instance.Log(logBEC);
            }

            return retorno;
        }
Example #2
0
        public List<PostBEC> ListAtual(PostFilterBEC filterBEC)
        {
            var retorno = new List<PostBEC>();

            //try
            //{
                using (var context = new ContextDB())
                {
                    retorno = (from p in context.PostSet
                               where p.isAtivo
                               select new PostBEC
                                       {
                                           id = p.id,
                                           Titulo = p.Titulo,
                                           Texto = p.Texto,
                                           Previa = p.Texto.Substring(0, 100),
                                           Data = p.DataInclusao,
                                           URL = p.URL,
                                           Capa = p.Capa,
                                           isCapaImagem = p.isCapaImagem,
                                           isCompleto = true,
                                           TagSet = p.TagSet.Select(s => new PostTagBEC { Nome = s.Tag, URL = s.URL }).ToList(),
                                           Categoria = new PostCategoriaBEC { Nome = p.Categoria.Nome, URL = p.Categoria.URL },
                                           ImagemSet = p.ImagemSet.Select(s => new PostImagemBEC { id = s.id, Extensao = s.Extensao, Legenda = s.Legenda }).ToList(),

                                       })
                            .OrderByDescending(o => o.id)
                            .Take(filterBEC.Take)
                            .ToList();
                }
            //}
            //catch (Exception _ex)
            //{
            //    LogBEC logBEC = new LogBEC { Exception = _ex };
            //    LogBC.Instance.Log(logBEC);
            //}

            return retorno;
        }
Example #3
0
        public List<PostBEC> List(PostFilterBEC filterBEC)
        {
            var retorno = new List<PostBEC>();

            //try
            //{
                using (var context = new ContextDB())
                {
                    var nottIn = new List<int>();

                    if (!filterBEC.TakeNotIn.Equals(0))
                    {
                        nottIn = (from p in context.PostSet
                                  where p.isAtivo
                                  select p.id)
                                .OrderByDescending(o => o)
                                .Take(filterBEC.TakeNotIn)
                                .ToList();
                    }

                    var query = (from p in context.PostSet
                               where p.isAtivo
                               && (filterBEC.Mes.Equals(0) || p.DataInclusao.Month.Equals(filterBEC.Mes))
                               && (filterBEC.Ano.Equals(0) || p.DataInclusao.Year.Equals(filterBEC.Ano))
                               && (!filterBEC.idNotIn.Any() || !filterBEC.idNotIn.Contains(p.id))
                               && (!nottIn.Any() || !nottIn.Contains(p.id))
                               && (string.IsNullOrEmpty(filterBEC.Tag) || p.TagSet.Any(a => a.URL.Equals(filterBEC.Tag)))
                               && (string.IsNullOrEmpty(filterBEC.Categoria) || p.Categoria.URL.Equals(filterBEC.Categoria))
                                 select new PostBEC
                               {
                                   id = p.id,
                                   Titulo = p.Titulo,
                                   Texto = p.Texto,
                                   Previa = p.Texto.Substring(0, 100),
                                   Data = p.DataInclusao,
                                   URL = p.URL,
                                   Capa = p.Capa,
                                   isCapaImagem = p.isCapaImagem,
                                   isCompleto = true,
                                   TagSet = p.TagSet.Select(s => new PostTagBEC { Nome = s.Tag, URL = s.URL }).ToList(),
                                   Categoria = new PostCategoriaBEC { Nome = p.Categoria.Nome, URL = p.Categoria.URL },
                                   ImagemSet = p.ImagemSet.Select(s => new PostImagemBEC { id = s.id, Extensao = s.Extensao, Legenda = s.Legenda }).ToList(),

                               })
                            .OrderByDescending(o => o.id);

                    if (filterBEC.Take.Equals(0))
                    {
                        retorno = query.ToList();
                    }
                    else
                    {
                        retorno = query.Take(filterBEC.Take).ToList();
                    }
                }
            //}
            //catch (Exception _ex)
            //{
            //    LogBEC logBEC = new LogBEC { Exception = _ex, Usuario = filterBEC.ToString() };
            //    LogBC.Instance.Log(logBEC);
            //}

            return retorno;
        }