Ejemplo n.º 1
0
        public Models.CreatePostModel Insert(Models.CreatePostModel post)
        {
            try
            {
                var postEntity = new Post
                {
                    Slug        = CreateSlugWithEnglishChar_CreatePost(post),
                    Title       = post.Title,
                    Description = post.Description,
                    Body        = post.Body,
                    Tag         = post.Tag,
                    CreatedAt   = post.CreatedAt,
                    UpdatedAt   = post.UpdatedAt
                };

                _context.Posts.Add(postEntity);
                _context.SaveChanges();

                return(_mapper.Map <Models.CreatePostModel>(postEntity));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        private string CreateSlugWithEnglishChar_CreatePost(Models.CreatePostModel post)
        {
            var slug = post.Title
                       .ToLower().Replace(" ", "-")
                       .Replace("?", "").Replace(".", "").Replace("!", "");

            byte[] tempBytes;
            tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(slug);

            return(System.Text.Encoding.UTF8.GetString(tempBytes));
        }