public HttpResponseMessage PostBlogItem(BlogItemViewModel item)
        {
            var modelStateErrors = ModelState.Values.ToList();

            List <string> errors = (from s in modelStateErrors from e in s.Errors where e.ErrorMessage != null &&
                                    e.ErrorMessage.Trim() != "" select e.ErrorMessage).ToList();

            if (errors.Count == 0)
            {
                try
                {
                    string userId = Request.GetOwinContext().Authentication.User.Identity.GetUserId();

                    var currentUser = UserManager.FindById(userId);
                    currentUser.BlogItems.Add(new BlogItem()
                    {
                        Content = item.Content,
                        Title   = item.Title,
                        date    = DateTime.Now
                    });

                    UserManager.Update(currentUser);
                    return(Request.CreateResponse(HttpStatusCode.Accepted));
                }
                catch
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
            }
            else
            {
                return(Request.CreateResponse <List <string> >(HttpStatusCode.BadRequest, errors));
            }
        }
Exemple #2
0
        public static BlogItemViewModel ConvertToViewModel(this BlogEntry entry)
        {
            var viewEntry = new BlogItemViewModel()
            {
                ID               = entry.BlogEntryId.ToString(),
                Title            = entry.Title,
                UtcTimeString    = entry.CreationDate.ToString("r"),
                NrComments       = entry.TotalComments,
                Content          = entry.Content,
                ShowTitleLink    = true,
                AllowAddComments = entry.LastUpdateDate.AddMonths(2) > DateTimeOffset.Now,
                EntryLink        = string.Format("/Blog/{0}/{1}/{2}/{3}",
                                                 entry.CreationDate.Year,
                                                 entry.CreationDate.Month.ToString("00"),
                                                 entry.CreationDate.Day.ToString("00"),
                                                 entry.StrippedDownTitle)
            };

            foreach (var cat in entry.Categories)
            {
                viewEntry.Categories.Add(new CategoryViewModel()
                {
                    Name = cat.Name, Value = cat.Value
                });
            }

            return(viewEntry);
        }
        public IActionResult Post(int blogToSee)
        {
            BlogItem          b          = blogRepo.RetrieveBlogItemById(blogToSee);
            var               mapperBlog = mapper.BlogToBlogItemViewModel();
            BlogItemViewModel bmodel     = mapperBlog.Map <BlogItemViewModel>(b);

            return(View("Singleblog", bmodel));
        }
Exemple #4
0
        public async Task <ActionResult> CreateAsync([Bind(Include = "Id,Title,Author,Post,Tags")] BlogItemViewModel item)
        {
            if (ModelState.IsValid)
            {
                item.Post.CreatedDate = DateTime.Now.ToString();
                await BlogPostRepository <BlogItemViewModel> .CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Exemple #5
0
        public async Task <ActionResult> EditAsync([Bind(Include = "Id,Title,Author,Post,Tags")] BlogItemViewModel item)
        {
            if (ModelState.IsValid)
            {
                BlogItemViewModel blogItem = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(item.Id);

                item.UserReviews      = blogItem.UserReviews;
                item.Post.CreatedDate = blogItem.Post.CreatedDate;
                await BlogPostRepository <BlogItemViewModel> .UpdateItemAsync(item.Id, item);

                return(RedirectToAction("Details", new { id = item.Id }));
            }

            return(View(item));
        }
        public IActionResult Overview()
        {
            BlogViewModel model = new BlogViewModel();

            model.BlogItemsInSystem = new List <BlogItemViewModel>();
            var mapperBlog = mapper.BlogToBlogItemViewModel();

            foreach (BlogItem b in blogRepo.RetrieveAllBlogItems())
            {
                BlogItemViewModel bmodel = mapperBlog.Map <BlogItemViewModel>(b);
                model.BlogItemsInSystem.Add(bmodel);
            }

            return(View("BlogOverview", model));
        }
 public IActionResult SingleBlogItem(int blogId)
 {
     if (blogId != 0)
     {
         BlogItem          b          = blogRepo.RetrieveBlogItemById(blogId);
         var               mapperBlog = mapper.BlogToBlogItemViewModel();
         BlogItemViewModel bmodel     = mapperBlog.Map <BlogItemViewModel>(b);
         return(View("SingleBlogItem", bmodel));
     }
     else
     {
         BlogItemViewModel model = new BlogItemViewModel();
         return(View("SingleBlogItem", model));
     }
 }
Exemple #8
0
        public async Task <ActionResult> EditAsync(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BlogItemViewModel item = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(id);

            if (item == null)
            {
                return(HttpNotFound());
            }

            return(View(item));
        }
        public IActionResult Index()
        {
            XElement xml     = XElement.Load("https://www.minutoseguros.com.br/blog/feed/");
            var      channel = xml.Element("channel");

            BlogViewModel blog = new BlogViewModel();

            blog.Title         = channel.Element("title").Value;
            blog.Description   = channel.Element("description").Value;
            blog.BlogItens     = new List <BlogItemViewModel> ();
            blog.LastBuildDate = Convert.ToDateTime(channel.Element("lastBuildDate").Value);
            blog.BestWords     = new List <BlogBestWordViewModel> ();

            foreach (var item in channel.Elements("item").OrderByDescending(x => Convert.ToDateTime(x.Element("pubDate").Value)).Take(10))
            {
                BlogItemViewModel blogItem = new BlogItemViewModel();
                blogItem.BestWords   = new List <BlogBestWordViewModel> ();
                blogItem.Title       = item.Element("title").Value;
                blogItem.Link        = item.Element("link").Value;
                blogItem.PubDate     = Convert.ToDateTime(item.Element("pubDate").Value);
                blogItem.Description = item.Element("description").Value;

                try {
                    blogItem.Image = item.Value.Split(new string[] { "img" }, StringSplitOptions.None) [1].Split(new string[] { "src=\"" }, StringSplitOptions.None) [1].Split(new string[] { "\"" }, StringSplitOptions.None) [0];
                } catch {
                    blogItem.Image = "https://www.minutoseguros.com.br/blog/wp-content/uploads/2018/12/para-brisa-trincado-conclusao.jpg";
                }

                blogItem.Categories = new List <string> ();
                foreach (var category in item.Elements("category"))
                {
                    blogItem.Categories.Add(category.Value);
                    blogItem.BestWords = ListBestWords(blogItem.BestWords, category.Value);
                    blog.BestWords     = ListBestWords(blog.BestWords, category.Value);
                }

                // adiciona as melhores palavras para o item e para o total
                blogItem.BestWords = ListBestWords(blogItem.BestWords, blogItem.Title);
                blogItem.BestWords = ListBestWords(blogItem.BestWords, blogItem.Title);
                blog.BestWords     = ListBestWords(blog.BestWords, blogItem.Title);
                blog.BestWords     = ListBestWords(blog.BestWords, blogItem.Title);

                blog.BlogItens.Add(blogItem);
            }

            return(View(blog));
        }
Exemple #10
0
        public async Task <ActionResult> CreateCommentAsync(string id, [Bind(Include = "Author,Review")] BlogReviewViewModel item)
        {
            if (ModelState.IsValid)
            {
                item.CreatedDate = DateTime.Now.ToString();
                BlogItemViewModel blog = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(id);

                if (blog.UserReviews == null)
                {
                    blog.UserReviews = new List <BlogReviewViewModel>();
                }
                blog.UserReviews.Add(item);
                await BlogPostRepository <BlogItemViewModel> .UpdateItemAsync(blog.Id, blog);

                return(RedirectToAction("Details", new { id = blog.Id }));
            }

            return(View(item));
        }
Exemple #11
0
        public async Task <ActionResult> DetailsAsync(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BlogItemViewModel item = await BlogPostRepository <BlogItemViewModel> .GetItemAsync(id);

            if (item == null)
            {
                return(HttpNotFound());
            }

            if (item.UserReviews == null)
            {
                item.UserReviews = new List <BlogReviewViewModel>();
            }

            return(View(item));
        }