Example #1
0
        internal PostDto GetPost(int id)
        {
            Post post = Context.Post.Include(o => o.Category).Include(o => o.Store).FirstOrDefault(o => o.Id == id);

            if (post == null)
            {
                throw new Exception("Error finding post");
            }

            PostDto dto = PostMapper.PostToDto(post);

            byte[] qrcode = CodeQrService.GenerateQr(Config.AppDomain + "/oferta/" + post.Id);
            dto.QrCode = qrcode;


            return(dto);
        }
Example #2
0
        public List <PostDto> GetPosts(string category)
        {
            List <Post> posts = new List <Post>();

            if (category != null)
            {
                posts = Context.Post.Include(o => o.Category).Include(o => o.Store).Where(o => o.Category.Name == category).ToList();
            }
            else
            {
                posts = Context.Post.Include(o => o.Category).Include(o => o.Store).ToList();
            }
            List <PostDto> dtos = new List <PostDto>();

            foreach (var item in posts)
            {
                PostDto dto = PostMapper.PostToDto(item);



                dtos.Add(dto);
            }
            return(dtos);
        }