Example #1
0
        public ActionResult Edit(BlogPostVM editedBlogPost)
        {
            if (ModelState.IsValid)
            {
                _blogPostRepo.EditBlogPost(editedBlogPost.BlogPost);
                var blogPostID = editedBlogPost.BlogPost.BlogPostId;
                _blogCategoryRepo.DeleteCategoryFromBlogPost(blogPostID);

                foreach (var category in editedBlogPost.CategoryArray)
                {
                    _blogCategoryRepo.AddCategoryToBlog(blogPostID, int.Parse(category));
                }

                string[] postTags = editedBlogPost.Tag.TagName.ToLower().Split(' ');
                editedBlogPost.Tags = _tagRepo.SelectAllTags(postTags);
                _blogTagRepo.DeleteTagFromBlog(blogPostID);
                foreach (var tag in editedBlogPost.Tags)
                {
                    _blogTagRepo.AddTagToBlog(blogPostID, tag.TagId);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(editedBlogPost));
        }
 public IActionResult Put(string slug, [FromBody] BlogPostVM blogPost)
 {
     try
     {
         blogPost.blogPost.slug = slug;
         BlogPost   blogPosted     = _blogLogic.PutBlog(blogPost.blogPost);
         BlogPostVM blogPostToSend = new BlogPostVM();
         blogPostToSend.blogPost = blogPosted;
         return(Ok(blogPostToSend));
     }
     catch (KeyNotFoundException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (ArgumentOutOfRangeException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (InvalidOperationException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #3
0
        public ActionResult AddBlogPost(BlogPostVM model)
        {
            if (ModelState.IsValid)
            {
            }

            return(View());
        }
Example #4
0
        public static BlogPost ConvertBlogPostVMToBlogPost(BlogPostVM blogPostVM)
        {
            BlogPost returnedBlogPost = blogPostVM.BlogPost;

            returnedBlogPost.AssignedCategories = CreateListOfCategory(blogPostVM.ChosenCategoriesArray);
            returnedBlogPost.AssignedTags       = CreateTagList(blogPostVM.Tag.TagName);
            return(returnedBlogPost);
        }
        public ActionResult AddBlogPost()
        {
            BlogPostVM model = new BlogPostVM();

            model.drpCategories = DrpServices.getDrpCategories();

            return(View(model));
        }
Example #6
0
        public ActionResult Edit(int id)
        {
            BlogPost        existingPost  = _blogServices.GetBlogPost(id);
            List <Category> allCategories = _blogServices.GetAllCategories();
            BlogPostVM      model         = WebServices.ConvertBlogPostToVeiwModel(existingPost, allCategories);

            return(View(model));
        }
Example #7
0
        public BlogPostVM GetSinglePostVM(int id)
        {
            BlogPostVM populatedBlogPost = new BlogPostVM();

            populatedBlogPost.BlogPost            = _blogPostRepo.GetBlogPost(id);
            populatedBlogPost.BlogPost.BlogPostId = id;
            populatedBlogPost.Categories          = _categoryRepo.GetAllCategories();
            populatedBlogPost.Tags = _tagRepo.GetAllTags();
            return(populatedBlogPost);
        }
Example #8
0
 public IHttpActionResult Update(BlogPostVM toUpdate)
 {
     if (posts.All(x => x.Id != toUpdate.Id))
     {
         return(StatusCode(HttpStatusCode.NotFound));
     }
     posts.Single(x => x.Id == toUpdate.Id).Text  = toUpdate.Text;
     posts.Single(x => x.Id == toUpdate.Id).Title = toUpdate.Title;
     return(Ok());
 }
Example #9
0
        public ActionResult UpdateBlogPost(int id)
        {
            BlogPost   bp  = db.BlogPosts.FirstOrDefault(x => x.ID == id); //hangi post olduğunu belirliyoruz
            BlogPostVM mdl = new BlogPostVM();                             //dbden postu çekip içeriği doldurma işlemini yapıyoruz

            mdl.CategoryID    = bp.CategoryID;
            mdl.Title         = bp.Title;
            mdl.Content       = bp.Content;
            mdl.drpCategories = DrpServices.getDrpCategries();
            return(View(mdl));
        }
Example #10
0
        public ActionResult Edit(BlogPostVM editedBlogPostVM)
        {
            if (ModelState.IsValid)
            {
                BlogPost postToBeProcessed = WebServices.ConvertBlogPostVMToBlogPost(editedBlogPostVM);
                _blogServices.ProcessEditedBlogPost(postToBeProcessed);

                return(RedirectToAction("AdminPanel", "Admin"));
            }
            return(View(editedBlogPostVM));
        }
Example #11
0
        //
        // GET: /Admin/BlogPost/
        public ActionResult AddBlogPost()
        {
            BlogPostVM model = new BlogPostVM();

            model.drpCategories = db.Categories.Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.ID.ToString()
            }).ToList();
            return(View(model));
        }
        public ActionResult UpdateBlogPost(int id)
        {
            var blogpost = db.BlogPosts.FirstOrDefault(x => x.ID == id);
            var model    = new BlogPostVM();

            model.CategoryID    = blogpost.CategoryID;
            model.Title         = blogpost.Title;
            model.Content       = blogpost.Content;
            model.drpCategories = DrpServices.getDrpCategories();

            return(View(model));
        }
Example #13
0
        BlogPostVM drpCategories()
        {
            BlogPostVM model = new BlogPostVM();

            model.drpCategories = db.Categories.Where(x => x.IsDeleted == false).Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.ID.ToString()
            }).ToList();

            return(model);
        }
        public ActionResult UpdateBlogPost(int id)
        {
            Blog       blog  = db.Blogs.FirstOrDefault(x => x.ID == id);
            BlogPostVM model = new BlogPostVM();

            model.CategoryID         = blog.CategoryID;
            model.Title              = blog.Title;
            model.Content            = blog.Content;
            model.DropdownCategories = DropDownServices.getDropDownCategories();


            return(View(model));
        }
Example #15
0
        private BlogPostVM PopulatedCategorySelectListItem(BlogPostVM returnedBlogPost)
        {
            var categoryListItems = _categoryRepo.GetAllCategories();

            foreach (var category in categoryListItems)
            {
                SelectListItem categoryList = new SelectListItem()
                {
                    Text  = category.CategoryName,
                    Value = category.CategoryId.ToString()
                };
                returnedBlogPost.CategoryList.Add(categoryList);
            }

            return(returnedBlogPost);
        }
Example #16
0
        public ActionResult AddBlogPost()
        {
            BlogPostVM model = new BlogPostVM();

            //Aşağıdaki 1. yolda dropdownliste kategori çekmeyi yazdık. Sonra bir çok yerde ihtiyacımız olabilir diye Model klasörü içinde services/Html..../DrpServices içerisinde tanımladık ve 2. yol ile çağırdık
            #region 1.yol
            //model.drpCategories = db.Categories.Select(x => new SelectListItem()
            //{
            //    Text = x.Name,
            //    Value = x.ID.ToString()
            //}).ToList();
            #endregion//1.yol
            //2. yol
            model.drpCategories = DrpServices.getDrpCategries();

            return(View(model));
        }
Example #17
0
        public ActionResult UpdateBlogPost(BlogPostVM mdl, HttpPostedFileBase PostImage)
        {
            try
            {
                mdl.drpCategories = DrpServices.getDrpCategries();//işlem yapıldıktan sonra droplar dolu gelsin die
                if (ModelState.IsValid)
                {
                    BlogPost bp       = db.BlogPosts.FirstOrDefault(x => x.ID == mdl.ID);
                    string   filename = "";
                    if (PostImage != null)
                    {
                        string ext = Path.GetExtension(PostImage.FileName);
                        if (ext == ".jpg" || ext == ".jpeg" || ext == ".png") //bu formatlarda ise al
                        {
                            string uniqenum = Guid.NewGuid().ToString();      //aynı isimli resim gelme ihtimalinden dolayı..
                            filename = uniqenum + PostImage.FileName;         //benzersiz uniq isim verdik resme.
                            PostImage.SaveAs(Server.MapPath("~/Areas/Admin/Content/img/BlogPost/" + filename));
                        }

                        bp.ImagePath = filename;
                    }
                    else
                    {
                        bp.ImagePath = bp.ImagePath;
                    }

                    bp.CategoryID = mdl.CategoryID;
                    bp.Title      = mdl.Title;
                    bp.Content    = mdl.Content;

                    db.SaveChanges();
                    ViewBag.IslemDurum = 1;
                    return(View(mdl));
                }
                else
                {
                    ViewBag.IslemDurum = 2;
                    return(View(mdl));
                }
            }
            catch (Exception)
            {
                ViewBag.IslemDurum = 2;
                return(View(mdl));
            }
        }
Example #18
0
        public static BlogPostVM ConvertBlogPostToVeiwModel(BlogPost blogPost, List <Category> allCategories)
        {
            BlogPostVM newBlogPostVM = new BlogPostVM();

            newBlogPostVM.BlogPost      = blogPost;
            newBlogPostVM.AllCategories = allCategories;
            newBlogPostVM.CategorySelectListItemList = CreateSelectListItemList(allCategories);
            if (newBlogPostVM.BlogPost.BlogPostId > 0)
            {
                newBlogPostVM.TagString = string.Join(" ", blogPost.AssignedTags.Select(assignedTag => assignedTag.TagName));
            }
            else
            {
                newBlogPostVM.TagString = string.Empty;
            }

            return(newBlogPostVM);
        }
 public IActionResult Posts([FromBody] BlogPostVM blogPost)
 {
     try
     {
         BlogPost   blogPosted     = _blogLogic.PostBlog(blogPost.blogPost);
         BlogPostVM blogPostToSend = new BlogPostVM();
         blogPostToSend.blogPost = blogPosted;
         return(Ok(blogPostToSend));
     }
     catch (ArgumentOutOfRangeException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult AddBlogPost(BlogPostVM model)
        {
            BlogPostVM vmodel = new BlogPostVM();

            vmodel.drpCategories = DrpServices.getDrpCategories();

            if (ModelState.IsValid)
            {
                string filename = "";

                foreach (string name in Request.Files)
                {
                    model.PostImage = Request.Files[name];
                    string ext = Path.GetExtension(model.PostImage.FileName);

                    if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")
                    {
                        string uniqnumber = Guid.NewGuid().ToString();
                        filename = uniqnumber + model.PostImage.FileName;
                        model.PostImage.SaveAs(Server.MapPath("~/Content/Img/BlogPostResim/" + filename));
                    }
                    else
                    {
                        ViewBag.hata = "resim formatı uygun degildir.";
                    }
                }

                BlogPost blogpost = new BlogPost();
                blogpost.CategoryID = model.CategoryID;
                blogpost.Title      = model.Title;
                blogpost.Content    = model.Content;
                blogpost.ImagePath  = filename;

                db.BlogPost.Add(blogpost);
                db.SaveChanges();
                ViewBag.IslemDurum = 1;
                return(View(vmodel));
            }
            else
            {
                ViewBag.IslemDurum = 2;
                return(View(vmodel));
            }
        }
        public ActionResult AddBlogPost(BlogPostVM model)
        {
            BlogPostVM vmodel = new BlogPostVM();

            vmodel.drpCategories = DrpServices.getDrpCategories();

            if (ModelState.IsValid)
            {
                var blogpost = new BlogPost();
                blogpost.Title      = model.Title;
                blogpost.CategoryID = model.CategoryID;
                blogpost.Content    = model.Content;

                foreach (string name in Request.Files)
                {
                    model.PostImage = Request.Files[name];

                    string ext = Path.GetExtension(model.PostImage.FileName);

                    if (ext == ".jpg" || ext == ".jpeg" || ext == "*.png" || ext == "*.gif")
                    {
                        string uniqnumber = Guid.NewGuid().ToString().Replace("-", "");
                        string filename   = uniqnumber + model.PostImage.FileName;
                        string TamYol     = "~/Areas/Admin/Content/Site/images/blogpost/" + filename;
                        //Request.Files[0].SaveAs(Server.MapPath(TamYol));

                        model.PostImage.SaveAs(Server.MapPath(TamYol));
                        blogpost.ImagePath = filename;
                    }
                }

                db.BlogPosts.Add(blogpost);
                db.SaveChanges();
                ViewBag.IslemDurum = 1;
                return(View(vmodel));
            }
            else
            {
                ViewBag.IslemDurum = 2;
                return(View(vmodel));
            }
        }
Example #22
0
        public ActionResult AddBlogPost(BlogPostVM model, HttpPostedFileBase PostImage)
        {
            //--dropdownlist 2.yöntem içindir. View döndürülen vmodel buna dahildir.
            BlogPostVM vmodel = new BlogPostVM();

            vmodel.drpCategories = DrpServices.getDrpCategries();


            if (ModelState.IsValid)
            {
                string filename = "";
                foreach (string name in Request.Files)//birden fazla resim seçilmesi durumunda
                {
                    PostImage = Request.Files[name];

                    string ext = Path.GetExtension(PostImage.FileName);
                    if (ext == ".jpg" || ext == ".jpeg" || ext == ".png") //bu formatlarda ise al
                    {
                        string uniqenum = Guid.NewGuid().ToString();      //aynı isimli resim gelme ihtimalinden dolayı..
                        filename = uniqenum + PostImage.FileName;         //benzersiz uniq isim verdik resme.
                        PostImage.SaveAs(Server.MapPath("~/Areas/Admin/Content/img/BlogPost/" + filename));
                    }
                }

                BlogPost bp = new BlogPost();
                bp.CategoryID = model.CategoryID;
                bp.Title      = model.Title;
                bp.Content    = model.Content;

                bp.ImagePath = filename;

                db.BlogPosts.Add(bp);
                db.SaveChanges();
                ViewBag.IslemDurum = 1;
                return(RedirectToAction("index"));
            }
            else
            {
                ViewBag.IslemDurum = 2;
                return(View(vmodel));
            }
        }
Example #23
0
        public ActionResult Post(BlogPostVM newBlogPost)
        {
            if (ModelState.IsValid)
            {
                BlogPost newPost = WebServices.ConvertBlogPostVMToBlogPost(newBlogPost);
                int      blogId  = _blogServices.AddNewBlogPost(newPost);

                _blogServices.AddCategoriesToBlogPost(blogId, newPost.AssignedCategories);

                List <Tag> newTags = _blogServices.AddCreatedTags(newPost.AssignedTags);

                _blogServices.AddTagsToBlog(blogId, newTags);

                return(RedirectToAction("AdminPanel", "Admin"));
            }
            List <Category> allCategories = _blogServices.GetAllCategories();
            var             model         = WebServices.ConvertBlogPostToVeiwModel(newBlogPost.BlogPost, allCategories);

            return(View(model));
        }
        public ActionResult UpdateBlogPost(BlogPostVM model)
        {
            model.DropdownCategories = DropDownServices.getDropDownCategories();
            if (ModelState.IsValid)
            {
                Blog blog = db.Blogs.FirstOrDefault(x => x.ID == model.ID);
                blog.CategoryID = model.CategoryID;
                blog.Title      = model.Title;
                blog.Content    = model.Content;

                db.SaveChanges();
                ViewBag.islemDurum = 1;
                return(View(model));
            }
            else
            {
                ViewBag.islemDurum = 2;
                return(View(model));
            }
        }
Example #25
0
        public IActionResult DisplayFullBlogPost(int id)
        {
            //returns only one blog
            var getSpecificBlog = (from b in _assignment1DataContext.BlogPosts
                                   where b.BlogPostId == id
                                   select b
                                   ).FirstOrDefault();

            //list of comments
            var comments = (from c in _assignment1DataContext.Comments where c.BlogPostId == id select c).ToList();

            var photos = (from c in _assignment1DataContext.Photos where c.BlogPostId == id select c).ToList();

            /* */
            var blogPostVM = new BlogPostVM();

            blogPostVM.BlogPost = getSpecificBlog;
            blogPostVM.Comments = comments;
            blogPostVM.Photos   = photos;
            return(View(blogPostVM)); //returning getSpecificUser instead of getSpecificBlog
        }
        public ActionResult UpdateBlogPost(BlogPostVM model)
        {
            model.drpCategories = DrpServices.getDrpCategories();

            if (ModelState.IsValid)
            {
                BlogPost blogpost = db.BlogPost.FirstOrDefault(m => m.ID == model.ID);
                blogpost.CategoryID = model.CategoryID;
                blogpost.Title      = model.Title;
                blogpost.Content    = model.Content;

                db.SaveChanges();
                ViewBag.IslemDurum = 1;
                return(View(model));
            }
            else
            {
                ViewBag.IslemDurum = 2;
                return(View(model));
            }
        }
        public ActionResult AddBlogPost(BlogPostVM model)
        {
            BlogPostVM vmodel = new BlogPostVM();

            vmodel.DropdownCategories = DropDownServices.getDropDownCategories();

            if (ModelState.IsValid)
            {
                string fileName = "";
                foreach (string name in Request.Files)
                {
                    model.PostImage = Request.Files[name];
                    string extension = Path.GetExtension(Request.Files[name].FileName);
                    if (extension == "jpg" || extension == "png" || extension == "jpeg")
                    {
                        string imageNumber = Guid.NewGuid().ToString();
                        fileName = imageNumber + model.PostImage.FileName;
                        model.PostImage.SaveAs(Server.MapPath("~/Areas/Admin/Content/Site/Images/blogpost/" + fileName));
                    }
                }

                Blog blog = new Blog();
                blog.CategoryID = model.CategoryID;
                blog.Title      = model.Title;
                blog.Content    = model.Content;
                blog.ImagePath  = fileName;

                db.Blogs.Add(blog);
                db.SaveChanges();
                ViewBag.islemDurum = 1;

                return(View(vmodel));
            }
            else
            {
                ViewBag.islemDurum = 2;

                return(View(vmodel));
            }
        }
 public ActionResult GetBlogPost(string slug)
 {
     try
     {
         BlogPost blogPost = _blogLogic.GetBlogBySlug(slug);
         if (blogPost == null)
         {
             return(new BadRequestResult());
         }
         BlogPostVM blogPostToSend = new BlogPostVM();
         blogPostToSend.blogPost = blogPost;
         return(Ok(blogPostToSend));
     }
     catch (KeyNotFoundException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #29
0
        public ActionResult AddBlogPost(BlogPostVM model)
        {
            if (ModelState.IsValid)
            {
                BlogPost blogpost = new BlogPost();
                blogpost.Title      = model.Title;
                blogpost.Content    = model.Content;
                blogpost.CategoryID = model.CategoryID;
                blogpost.Slug       = Slugify.Generate(model.Title);


                foreach (string name in Request.Files)
                {
                    string number = Guid.NewGuid().ToString();
                    string ext    = Path.GetExtension(model.AnaResim.FileName);
                    model.AnaResim = Request.Files[name];

                    if (ext == ".jpg" || ext == ".png" || ext == ".jpeg")
                    {
                        string filename = number + model.AnaResim.FileName;
                        blogpost.ImagePath = filename;
                        model.AnaResim.SaveAs(Server.MapPath("~/Areas/Admin/Content/images/BlogPost/" + number + model.AnaResim.FileName));
                    }
                }


                db.BlogPost.Add(blogpost);
                db.SaveChanges();

                ViewBag.IslemDurum = 1;

                return(View(drpCategories()));
            }
            else
            {
                ViewBag.IslemDurum = 3;
                return(View(drpCategories()));
            }
        }
Example #30
0
        public ActionResult Post(BlogPostVM newBlogPost)
        {
            if (ModelState.IsValid)
            {
                var blogId = _blogPostRepo.AddBlogPost(newBlogPost.BlogPost);

                foreach (var category in newBlogPost.CategoryArray)
                {
                    _blogCategoryRepo.AddCategoryToBlog(blogId, int.Parse(category));
                }

                string[] postTags = newBlogPost.Tag.TagName.ToLower().Split(' ');
                newBlogPost.Tags = _tagRepo.SelectAllTags(postTags);

                foreach (var tag in newBlogPost.Tags)
                {
                    _blogTagRepo.AddTagToBlog(blogId, tag.TagId);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View(PopulatedCategorySelectListItem(newBlogPost)));
        }