Exemplo n.º 1
0
        public IActionResult Index(int?page = null)
        {
            var filter = new BlogFilter {
                BlogsPerPage = blogsPerPage
            };

            if (numberOfPages == 0)
            {
                numberOfPages = CountNumberOfPages();
            }

            if (page == null)
            {
                var blogs     = blogService.LoadBlogs(filter);
                var viewModel = new BlogsViewModel()
                {
                    Blogs = blogs.ToList(), CurrentPage = 1, NumberOfPages = numberOfPages
                };
                return(View(viewModel));
            }
            else
            {
                filter.CurrentPage = page;
                var blogs     = blogService.LoadBlogs(filter);
                var viewModel = new BlogsViewModel()
                {
                    Blogs = blogs.ToList(), CurrentPage = (int)page, NumberOfPages = numberOfPages
                };
                return(View(viewModel));
            }
        }
Exemplo n.º 2
0
        // GET: Blogs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(View("NotFound"));
            }


            var blog = db.Blogs.Find(id);


            var viewModel = new BlogsViewModel
            {
                Blog       = blog,
                Person     = db.Persons.SingleOrDefault(p => p.Id == blog.PersonId),
                Category   = db.Categories.SingleOrDefault(c => c.Id == blog.CategoryId),
                Comments   = db.Comments.Where(c => c.BlogId == blog.Id).ToList(),
                Comment    = null,
                Categories = null,
                People     = null
            };

            if (blog == null)
            {
                return(View("NotFound"));
            }
            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult AddBlog(BlogsViewModel model, HttpPostedFileBase file)
        {
            //var fileName = Path.GetFileName(file.FileName);
            //var path = Path.Combine(Server.MapPath("~/Images"), fileName);
            //file.SaveAs(path);
            int   id   = Convert.ToInt32(Session["ID"]);
            Blogs blog = new Blogs();

            if (file != null && blog != null)
            {
                string path     = Server.MapPath("~/Images/");
                string fileName = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
                file.SaveAs(path + fileName);
                blog.Title        = model.blog.Title;
                blog.Text         = model.blog.Text;
                blog.CategoriesID = model.blog.Categories.ID;
                blog.DefaultImage = fileName;
                blog.UsersID      = id;
                blog.AddDate      = DateTime.Now;
                blog.BlogStatus   = true;
                db.Blogs.Add(blog);
                db.SaveChanges();
                return(RedirectToAction("UserBlogs", "Blog"));
            }
            else
            {
                ViewBag.Warning = "blog ekleme başarısız.";
                ViewBag.Status  = "danger";
            }
            var list = db.Categories.ToList();

            model.categoriSelectList = new SelectList(list, "ID", "CategoriName");

            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult ReadBlog(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            int            userID = Convert.ToInt32(Session["ID"]);
            BlogsViewModel model  = new BlogsViewModel();

            model.blog = db.Blogs.Where(x => x.ID == id).FirstOrDefault();
            if (model != null)
            {
                //model.blog.Text = model.blog.Text.Replace(Environment.NewLine, @"<br />");
                model.likedBlogs = db.LikedBlogs.Where(x => x.BlogsID == id && x.UsersID == userID).FirstOrDefault();
                if (model.likedBlogs == null) //fav null ise blog kişinin favorilerinde değildir.
                {
                    model.likedBlogs           = new LikedBlogs();
                    model.likedBlogs.Favourite = false;
                    model.likedBlogs.Liked     = false;
                }
            }
            else
            {
                return(RedirectToAction("BlogCategories", "Blog"));
            }

            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult ReportBlog(BlogsViewModel model)
        {
            int?id = Convert.ToInt32(Session["ID"]);

            if (id == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                Complaints report = new Complaints();
                report.Subject = model.Report.Subject;
                report.Text    = model.Report.Text;
                report.UsersID = id;
                report.BlogsID = model.blog.ID;
                db.Complaints.Add(report);
                db.SaveChanges();
                ViewBag.Status  = "success";
                ViewBag.Warning = "Your report sent successfully.We will respond as soon as possible.";
            }



            return(View(model));
        }
Exemplo n.º 6
0
        // GET: Blogs/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            ViewBag.Gallery = _context.TopicGalleries.ToList();
            var row            = _context.Blogs.Include(x => x.BlogCategoryRelations).Where(x => x.Id == id).FirstOrDefault();
            var blogcategories = _context.BlogCategories.AsEnumerable();
            var catslist       = new SelectList(blogcategories, "Id", "Title");

            foreach (var item in catslist)
            {
                int itemValue = int.Parse(item.Value);
                item.Selected = row.BlogCategoryRelations.Where(x => x.Category.Id == itemValue).Count() > 0;
            }
            //ViewBag.Categories = selectfield;
            BlogsViewModel model = new BlogsViewModel {
                Id = row.Id, MediaType = row.MediaType, HtmlDescription = row.HtmlDescription, PostDate = row.PostDate, Title = row.Title, Categories = catslist, Gallery = row.Gallery
            };

            if (row == null)
            {
                return(NotFound());
            }
            return(View(model));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,Title,Image,HtmlDescription,PostDate,Categories")] BlogsViewModel blogsViewModel)
        {
            if (ModelState.IsValid)
            {
                string filename = "";
                if (blogsViewModel.Image != null && blogsViewModel.Image.Length > 0)
                {
                    filename = Guid.NewGuid().ToString().Substring(4) + blogsViewModel.Image.FileName;
                    UploadFile(blogsViewModel.Image, filename);
                }
                Blog row = new Blog {
                    Image = filename, MediaType = blogsViewModel.MediaType, Title = blogsViewModel.Title, HtmlDescription = blogsViewModel.HtmlDescription, PostDate = blogsViewModel.PostDate, Gallery = blogsViewModel.Gallery
                };
                string[] catIds = Request.Form["Categories"].ToString().Split(',');

                var dbcats = _context.BlogCategories.Where(x => catIds.Contains(x.Id.ToString())).ToList();
                foreach (var dbcat in dbcats)
                {
                    _context.BlogCategoryRelations.Add(new BlogCategoryRelation {
                        Category = dbcat, Blog = row
                    });
                }

                _context.Blogs.Add(row);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogsViewModel));
        }
Exemplo n.º 8
0
        public ActionResult Search(int?page, string k)
        {
            IEnumerable <Movie> list = null;
            int    total             = 0;
            string word = "";

            if (!string.IsNullOrEmpty(k))
            {
                var search = new SearchHelper();

                list = search.Search(k, page, out total, out word);

                ViewBag.PageTitle = word;

                sites.SaveKeyword(k);
            }

            var pBlogs = new Paginated <Movie>(list.AsQueryable(), page ?? 1, 24, total);
            var model  = new BlogsViewModel(pBlogs, null, null, null);

            if (page.HasValue)
            {
                ViewBag.PageTitle += "_第" + page + "页";
            }

            return(View("~/Views/Movie/Index.cshtml", model));
        }
Exemplo n.º 9
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var model = new BlogsViewModel();

            model.Blogs = new List <BlogViewModel>();

            foreach (int id in ids)
            {
                Blog blog = blogService.Find(id);
                if (blog == null)
                {
                    continue;
                }

                model.Blogs.Add(new BlogViewModel
                {
                    Id    = blog.Id,
                    Title = blog.Title,
                });
            }
            return(View(model));
        }
Exemplo n.º 10
0
        public ActionResult AddBlog()
        {
            BlogsViewModel blogModel = new BlogsViewModel();
            var            list      = db.Categories.ToList();

            blogModel.categoriSelectList = new SelectList(list, "ID", "CategoriName");
            return(View(blogModel));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnGet()
        {
            ViewModel       = new BlogsViewModel();
            ViewModel.Blogs = new List <Blog>();
            ViewModel.Blogs = await _blogService.BlogsAsync();

            return(Page());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> OnGet()
        {
            ViewModel = new BlogsViewModel
            {
                Blogs = await _blogServices.BlogsAsync()
            };

            return(Page());
        }
Exemplo n.º 13
0
        public ActionResult Index()
        {
            var blog  = blogService.FindAll().ToList();
            var model = new BlogsViewModel
            {
                Blogs = Mapper.Map <List <BlogViewModel> >(blog)
            };

            return(View(model));
        }
Exemplo n.º 14
0
        public ServiceResult Edit(BlogsViewModel model, int Id)
        {
            var entity = _blogs.Find(Id);

            Mapper.Map(model, entity);

            _blogs.Update(entity);
            _Context.SaveChanges();
            return(ServiceResult.Okay());
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Index(int page = 1)
        {
            pageCounter.UpdatePage(page);

            var blogsViewModel = new BlogsViewModel();

            blogsViewModel.pageCounter = pageCounter;
            blogsViewModel.blogs       = await blogService.GetForPage(pageCounter.Skip, pageCounter.BlogsOnPage);

            return(View(blogsViewModel));
        }
Exemplo n.º 16
0
        public ActionResult UserBlogs()
        {
            if (Session["ID"] == null)
            {
                return(RedirectToAction("index", "Home"));
            }
            int            id    = Convert.ToInt32(Session["ID"]);
            BlogsViewModel blogs = new BlogsViewModel();

            blogs.blogList = db.Blogs.Where(x => x.UsersID == id && x.BlogStatus == true).ToList();
            return(View(blogs));
        }
Exemplo n.º 17
0
        // GET: Blogs/Create
        public ActionResult Create()
        {
            //ViewBag.CategoryId = new SelectList(db.Categories, "Id", "CategoryName");
            //ViewBag.PersonId = new SelectList(db.Persons, "Id", "FirstName");
            var viewModel = new BlogsViewModel
            {
                Blog       = new Blog(),
                Categories = db.Categories.ToList(),
                People     = db.Persons.ToList(),
            };

            return(View(viewModel));
        }
Exemplo n.º 18
0
        public ActionResult ReportBlog(int?blogID)
        {
            int?id = Convert.ToInt32(Session["ID"]);

            if (id == null || id == 0)
            {
                return(RedirectToAction("Login", "Account"));
            }
            BlogsViewModel model = new BlogsViewModel();

            model.blog = db.Blogs.Where(x => x.ID == blogID).FirstOrDefault();
            return(View(model));
        }
Exemplo n.º 19
0
        public IActionResult Edit(BlogsViewModel model, int Id, IFormFile NewImage)
        {
            if (NewImage != null)
            {
                var imageName = FileHelper.SaveFile(NewImage, _fileConfig, FileType.Image, _environment.WebRootPath);
                //FileHelper.DeleteFile(model.Image, _fileConfig, FileType.Image, _environment.WebRootPath);
                model.Image = imageName;
            }

            var result = _blogsRepository.Edit(model, Id);

            TempData.AddResult(result);
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 20
0
        public ActionResult BlogCategories(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Categories     categori = db.Categories.Where(x => x.ID == id).FirstOrDefault();
            BlogsViewModel model    = new BlogsViewModel();

            model.blogList = db.Blogs.Where(x => x.CategoriesID == categori.ID && x.BlogStatus == true).ToList();//categori ye ait bloglar


            ViewBag.CategoriName = categori.CategoriName;

            return(View(model));
        }
Exemplo n.º 21
0
        // GET: Home
        public ActionResult Index(int?page)
        {
            var blogs = bs.GetBlogs().Where(m => m.IsPublic == true);

            var pBlogs = new Paginated <Movie>(blogs, page ?? 1, 24);

            var model = new BlogsViewModel(pBlogs, null, null, null);

            ViewBag.PageTitle = "很好记bt";

            if (page.HasValue)
            {
                ViewBag.PageTitle += "_第" + page.Value + "页";
            }

            return(View("~/Views/Movie/Index.cshtml", model));
        }
Exemplo n.º 22
0
        public ActionResult Star(string id, int?page)
        {
            var blogs = bs.GetBlogs().Where(m => m.Stars.Contains(id));

            //ViewBag.Count = blogs.Select(m => m.MovieID).Count();

            var pBlogs = new Paginated <Movie>(blogs, page ?? 1, 24);

            //var popularTags = bs.GetPopularTags().Take(10).ToList();

            var model = new BlogsViewModel(pBlogs, null, null, null);

            ViewBag.PageTitle = "明星: " + id;
            ViewBag.Blog      = "current";

            return(View("Index", model));
        }
Exemplo n.º 23
0
        public ActionResult Tags(string id, int?page)
        {
            var blogs = bs.GetBlogsByTag(id).Where(m => m.IsPublic == true);

            //ViewBag.Count = blogs.Select(m => m.MovieID).Count();

            var pBlogs = new Paginated <Movie>(blogs, page ?? 1, 24);

            //var categories = bs.GetBlogCategories().ToList();
            //var popularTags = bs.GetPopularTags().Take(10).ToList();
            //var archives = bs.GetArchives().ToList();

            var model = new BlogsViewModel(pBlogs, null, null, null);

            ViewBag.PageTitle = "标签: " + id;
            ViewBag.Blog      = "current";

            return(View("Index", model));
        }
Exemplo n.º 24
0
        public ArticlesPage(string blogApp) : base()
        {
            InitializeComponent();
            BindingContext = new BlogsViewModel(blogApp);
            this.ArticlesListView.ItemSelected += async delegate
            {
                var articles = ArticlesListView.SelectedItem as Articles;
                if (articles == null)
                {
                    return;
                }

                var articlesDetails = new ArticlesDetailsPage(articles);

                await NavigationService.PushAsync(Navigation, articlesDetails);

                this.ArticlesListView.SelectedItem = null;
            };
        }
Exemplo n.º 25
0
        public ActionResult FavouriteBlogs()
        {
            if (Session["ID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            int               id       = Convert.ToInt32(Session["ID"]);
            List <Blogs>      blogList = new List <Blogs>();
            List <LikedBlogs> liked    = db.LikedBlogs.Where(x => x.UsersID == id).ToList();

            foreach (LikedBlogs item in liked)
            {
                Blogs b = new Blogs();
                b = db.Blogs.Where(x => x.ID == item.BlogsID).FirstOrDefault();
                blogList.Add(b);
            }
            BlogsViewModel model = new BlogsViewModel();

            model.blogList = blogList;
            return(View(model));
        }
Exemplo n.º 26
0
        public ArticlesPage(string blogApp) : base()
        {
            InitializeComponent();
            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);

            BindingContext = new BlogsViewModel(blogApp);
            this.ArticlesListView.ItemSelected += async delegate
            {
                var articles = ArticlesListView.SelectedItem as Articles;
                if (articles == null)
                {
                    return;
                }

                var articlesDetails = new ArticlesDetailsPage(articles);

                await NavigationService.PushAsync(Navigation, articlesDetails);

                this.ArticlesListView.SelectedItem = null;
            };
        }
Exemplo n.º 27
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var model = new BlogsViewModel();
            model.Blogs = new List<BlogViewModel>();

            foreach (int id in ids)
            {
                Blog blog = blogService.Find(id);
                if (blog == null) continue;

                model.Blogs.Add(new BlogViewModel
                {
                    Id = blog.Id,
                    Title = blog.Title,
                });
            }
            return View(model);
        }
        public IActionResult Index(string keywork, int?pageSize, int page = 1)
        {
            var blog = new BlogsViewModel();

            if (pageSize == null)
            {
                pageSize = _configuration.GetValue <int>("PageSize");
            }
            blog.PageSize = pageSize;
            var data          = _blogService.GetAllPaging(keywork, page, pageSize.Value);
            var listData      = data.Results.Select(a => BlogViewModel.form(a)).ToList();
            var paginationSet = new PagedResult <BlogViewModel>()
            {
                Results     = listData,
                CurrentPage = page,
                RowCount    = data.RowCount,
                PageSize    = data.PageSize,
            };

            blog.Data = paginationSet;
            return(View(blog));
        }
Exemplo n.º 29
0
        public ActionResult Index(int?id, int?page)
        {
            var blogs = bs.GetBlogs().Where(m => m.IsPublic == true);

            //根据分类搜索
            if (id.HasValue)
            {
                blogs = (from l in blogs
                         where l.MovieCategoryJoins.Any(m => m.CategoryID == id.Value)
                         select l);
            }

            var pBlogs = new Paginated <Movie>(blogs, page ?? 1, 24);

            var model = new BlogsViewModel(pBlogs, null, null, null);

            if (id.HasValue)
            {
                ViewBag.Category  = bs.GetBlogCategory(id.Value);
                ViewBag.PageTitle = "最新" + ViewBag.Category.CategoryName;

                if (id != 3 && id != 4 && id != 38)
                {
                    ViewBag.PageTitle += "电影电视剧";
                }
            }
            else
            {
                ViewBag.PageTitle = "所有影片";
            }

            if (page.HasValue)
            {
                ViewBag.PageTitle += "_第" + page + "页";
            }

            return(View(model));
        }
Exemplo n.º 30
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            if (!hasInitialization)
            {
                BindingContext = new BlogsViewModel(blogApp);
                this.ArticlesListView.ItemSelected += async delegate
                {
                    var articles = ArticlesListView.SelectedItem as Articles;
                    this.ArticlesListView.SelectedItem = null;
                    if (articles == null)
                    {
                        return;
                    }

                    var articlesDetails = new ArticlesDetailsPage(articles);

                    await NavigationService.PushAsync(Navigation, articlesDetails);
                };
                hasInitialization = true;
            }
            UpdatePage();
        }
Exemplo n.º 31
0
 public ActionResult Index()
 {
     var blog = blogService.FindAll().ToList();
     var model = new BlogsViewModel
     {
         Blogs = Mapper.Map<List<BlogViewModel>>(blog)
     };
     return View(model);
 }