Пример #1
0
        public async Task <News> Update(NewsVM newsVM)
        {
            var news = _mapper.Map(newsVM, await _context.Newss.SingleAsync(n => n.NewsId == newsVM.NewsId));
            await _context.SaveChangesAsync();

            return(news);
        }
Пример #2
0
        public HomePage()
        {
            this.InitializeComponent();
            this.userVM = new UserVM();
            login_Controll logincontroll = new login_Controll();

            this.news = new NewsVM();
            news.RetrieveAll();
            // Login login = new Login();
            Authentication auth = new Authentication();

            if (auth.isUserLogin())
            {
                loginU.Visibility  = Visibility.Collapsed;
                logoutm.Visibility = Visibility.Visible;
            }
            if (islogout)
            {
                logoutm.Visibility = Visibility.Collapsed;
                loginU.Visibility  = Visibility.Visible;
            }
            if (isAd)
            {
                Addnews.Visibility = Visibility.Visible;
                newlist.Visibility = Visibility.Visible;
            }
        }
Пример #3
0
        public IActionResult Index()
        {
            NewsVM vm = new NewsVM();

            vm.Comments = _db.Comment.Include(a => a.Applicant).ThenInclude(b => b.ApplicationUser).Where(y => y.AdministratorId == null && y.Seen == false).OrderByDescending(x => x.CommentTime).ToList();
            return(View(vm));
        }
Пример #4
0
        public ActionResult Details(int id)
        {
            NewsVM vm = new NewsVM();
            News   u  = vm.Find(id);

            return(View(u));
        }
Пример #5
0
        public ActionResult Index(string query = null)
        {
            try
            {
                var allNews = _context.News.Include(n => n.Category)
                              .Include(n => n.Author);

                if (!String.IsNullOrWhiteSpace(query))
                {
                    allNews = allNews.
                              Where(n => n.Content.Contains(query) ||
                                    n.Author.UserName.Contains(query) ||
                                    n.Title.Contains(query));
                }

                var viewModel = new NewsVM
                {
                    News = allNews
                };


                return(View(viewModel));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public NewsPage()
        {
            InitializeComponent();
            NewsVM newVM = new NewsVM(pageIndex: 0);

            BindingContext = newVM;
        }
Пример #7
0
 /// <summary>
 /// Updates news information
 /// </summary>
 /// <param name="oldNews">Current entity</param>
 /// <param name="news">Updated view model</param>
 /// <returns></returns>
 public void UpdateNews(News oldNews, NewsVM news)
 {
     oldNews.Title      = news.Title;
     oldNews.Annotation = news.Annotation;
     oldNews.Text       = news.Text;
     oldNews.ChangeDate = DateTime.UtcNow;
 }
Пример #8
0
        public ActionResult AddNews()
        {
            NewsVM mdl = new NewsVM();

            mdl = (NewsVM)UserToMdl(mdl);
            return(View(mdl));
        }
Пример #9
0
        public IActionResult MergeNews(MergeNewsVM mergeNews)
        {
            var result  = true;
            var message = string.Empty;

            try
            {
                var news = new NewsVM
                {
                    Id = mergeNews.Id.GetValueOrDefault(),
                    DatePublication = DateTime.Now,
                    Description     = mergeNews.Description,
                    Header          = mergeNews.Header,
                    Image           = mergeNews.Image,
                    Link            = mergeNews.Url
                };

                if (!mergeNews.Updated.GetValueOrDefault() && mergeNews.Id.HasValue)
                {
                    var _news = UnitOfWork.News.GetNewsById(mergeNews.Id.Value);
                    news.Image = _news.Image;
                }

                result = UnitOfWork.News.MergeNews(news);
            }
            catch (System.Exception ex)
            {
                result  = false;
                message = ex.ToString();
            }

            return(Json(new { result, message }));
        }
Пример #10
0
        public ActionResult NewsEdit(NewsVM news)
        {
            var newsTitlewiseid = db.NewsMasters.Where(x => x.NewsTitle == news.NewsTitle).Select(x => x.NewsId).FirstOrDefault();

            if (newsTitlewiseid == news.NewsId || newsTitlewiseid == 0)
            {
                if (news.NewsURL == null)
                {
                    var newsurl = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(news.NewsTitle);
                    news.NewsURL = newsurl;
                }
                var newsUrlwiseid = db.NewsMasters.Where(x => x.NewsUrl == news.NewsURL).Select(x => x.NewsId).FirstOrDefault();

                if (newsUrlwiseid == news.NewsId || newsUrlwiseid == 0)
                {
                    _ObjNewsRepository.EditpostNews(news);
                    return(RedirectToAction("NewsIndex"));
                }
                else
                {
                    ViewBag.NewsURL = "Duplicate News Url ....";
                    return(View(news));
                }
            }
            else
            {
                ViewBag.DuplicateNewsTitle = "Duplicate News Title ....";
                return(View(news));
            }
        }
Пример #11
0
        public ActionResult AddNews(NewsVM model)
        {
            if (ModelState.IsValid)
            {
                NewsDTO newNews = new NewsDTO
                {
                    Slug       = model.Headline.Replace(" ", "-").ToLower(),
                    Headline   = model.Headline,
                    Heading    = model.Heading,
                    NewsBody   = model.NewsBody,
                    NewsCaster = User.Identity.GetUserId <int>(),
                    UploadDate = DateTime.UtcNow,
                    TypeId     = model.TypeId
                };

                using (DbContext db = new DbContext())
                {
                    db.News.Add(newNews);
                    db.SaveChanges();
                }

                TempData["SM"] = "News added successfully, awaiting approval.";
                return(RedirectToAction("add-news"));
            }

            // if we get this far, there is an error
            model.NewsTypeList = new SelectList(NewsContext.GetAllNewsType(), "TypeId", "Description");
            return(View("AddNews", model));
        }
Пример #12
0
        public ActionResult BaseNews(string id_news)
        {
            if (_sessionHelper.Temp == true)
            {
                News        n    = new News();
                List <News> News = new List <News>();
                int         id;

                int.TryParse(id_news, out id);

                if (id != 0)
                {
                    NewsVM nvm;
                    Admin  a;

                    n = _newsBLL.NewSelect(id);
                    a = _adminBLL.SelectByNick(n.Author);

                    nvm = new NewsVM(n, a);

                    return(View("News", nvm));
                }
                else
                {
                    News = _newsBLL.NewsBaseList();

                    return(View("index", News));
                }
            }
            else
            {
                return(View("../Home/Login"));
            }
        }
Пример #13
0
        public ActionResult NewsDetail(int?id)
        {
            News   news   = _newsService.Get(id.GetValueOrDefault());
            NewsVM newsVM = Mapper.Map <News, NewsVM>(news);

            return(View(newsVM));
        }
Пример #14
0
        public bool IsValidNewsData(NewsVM news)
        {
            bool flag            = false;
            var  newsTitlewiseid = db.NewsMasters.Where(x => x.NewsTitle == news.NewsTitle).Select(x => x.NewsId).FirstOrDefault();

            if (newsTitlewiseid == news.NewsId)
            {
                flag = true;
                var newsUrlwiseid = db.NewsMasters.Where(x => x.NewsUrl == news.NewsURL).Select(x => x.NewsId).FirstOrDefault();
                if (newsUrlwiseid == news.NewsId)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                    NewsUrlDuplicatError();
                }
            }
            else
            {
                flag = false;
                NewsTitleDuplicatError();
            }

            return(flag);
        }
Пример #15
0
        public NewsVM GetNews(NewsFilterVM filter, int page)
        {
            NewsVM model    = new NewsVM();
            int    pageSize = 2;
            var    query    = _newsRepo.GetAll();

            if (!string.IsNullOrEmpty(filter.Name))
            {
                query = query.Where(x => x.Name.Contains(filter.Name));
            }
            if (filter.Id != 0)
            {
                query = query.Where(x => x.Id == filter.Id);
            }

            int pageNo = page - 1;

            model.list = query.OrderBy(x => x.Id)
                         .Skip(pageNo * pageSize)
                         .Take(pageSize)
                         .ToList();

            int allCount = query.Count();

            model.Page    = page;
            model.maxPage = (int)Math.Ceiling((double)allCount / pageSize);

            model.NewsFilter = filter;

            return(model);
        }
Пример #16
0
        public async Task <IActionResult> EditNews(NewsVM mdl)
        {
            db.NewsMdls.Update(mdl.NewsMdl);
            await db.SaveChangesAsync();

            return(RedirectToAction("News"));
        }
Пример #17
0
        public ActionResult Category(int id, string sortByTitle = "", string sortByDate = "desc")
        {
            var news = _repository.Find(n => n.NewsCategoryId == id);

            var result = news.Include("User").Include("NewsCategory");

            news = result.Where(n => n.Status == "Approved");

            IQueryable <News> newsLocal = news;

            if (!String.IsNullOrEmpty(sortByDate))
            {
                if (sortByDate == "asc")
                {
                    newsLocal = news.OrderBy(n => n.ModifiedOn);
                }
                else
                {
                    newsLocal = news.OrderByDescending(n => n.ModifiedOn);
                }

                news = newsLocal;
            }

            if (!String.IsNullOrEmpty(sortByTitle))
            {
                if (sortByTitle == "asc")
                {
                    newsLocal = news.OrderBy(n => n.Title);
                }
                else
                {
                    newsLocal = news.OrderByDescending(n => n.Title);
                }

                news = newsLocal;
            }


            GlobalRepository <NewsCategory> _categoriesRepository = new GlobalRepository <NewsCategory>();
            var categories = _categoriesRepository.Find(c => c.Id == id);

            var titlu = categories.Select(c => c.Name).FirstOrDefault();

            ViewBag.Name = titlu;

            ViewBag.Pages = (int)news.Count() / pageSize + 1;
            if (news.Count() % pageSize == 0)
            {
                ViewBag.Pages = ViewBag.Pages - 1;
            }

            var newsVM = new NewsVM
            {
                News = news
            };

            return(View(newsVM));
        }
Пример #18
0
        public ActionResult EditNews(int id)
        {
            NewsVM mdl = new NewsVM();

            mdl         = (NewsVM)UserToMdl(mdl);
            mdl.NewsMdl = db.NewsMdls.First(nm => nm.Id == id);
            return(View(mdl));
        }
Пример #19
0
        public ActionResult Delete(int id)
        {
            NewsVM vm = new NewsVM();

            // dodać usuwanie w repo
            vm.Delete(id);
            return(RedirectToAction("Index"));
        }
Пример #20
0
        public ActionResult Edit(int id)
        {
            NewsVM      vm    = new NewsVM();
            List <News> lista = vm.Get_list();
            News        a     = lista.Where(s => s.NewsID == id).FirstOrDefault();

            return(View(a));
        }
Пример #21
0
        public ActionResult Add(int id = 0)
        {
            News   b   = new News();
            NewsVM vm2 = new NewsVM();

            b.Date = DateTime.Now;
            return(View(b));
        }
Пример #22
0
        // GET: News
        public ActionResult Index()
        {
            NewsVM      vm        = new NewsVM();
            List <News> list_news = vm.Get_list().ToList();

            ViewBag.News = list_news;
            return(View(list_news));
        }
Пример #23
0
        // GET: NewsController
        public IActionResult Index()
        {
            NewsVM newsVM = new NewsVM();

            newsVM.AllNews = _context.News.OrderBy(n => n.Created).ToList();

            return(View(newsVM));
        }
Пример #24
0
        public ActionResult AddNews()
        {
            NewsVM model = new NewsVM();

            model.NewsTypeList = new SelectList(NewsContext.GetAllNewsType(), "TypeId", "Description");

            return(View("AddNews", model));
        }
Пример #25
0
        public IActionResult Edit(NewsVM model, int authorid, int categoryid)
        {
            News editarticle = _newscontext.News.FirstOrDefault(q => q.ID == model.ID);

            List <string> paths = new List <string>();

            string imgpath = "";

            if (model.articleimages != null)
            {
                foreach (var item in model.articleimages)
                {
                    var guid = Guid.NewGuid().ToString();

                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        "wwwroot/adminsite/assets/articleimg", guid + ".jpg");
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        item.CopyTo(stream);
                    }

                    imgpath = guid + ".jpg";

                    paths.Add(imgpath);
                }
            }

            model.MainImagePath = paths;

            if (ModelState.IsValid)
            {
                editarticle.Content    = model.Content;
                editarticle.Title      = model.Title;
                editarticle.SubTitle   = model.SubTitle;
                editarticle.AuthorID   = authorid;
                editarticle.CategoryID = categoryid;

                _newscontext.SaveChanges();

                int articleid = editarticle.ID;

                foreach (var item in model.MainImagePath)
                {
                    Pictures images = new Pictures();
                    images.ImagePath = item;
                    images.NewsId    = articleid;
                    _newscontext.Pictures.Add(images);
                }

                _newscontext.SaveChanges();
            }
            else
            {
                return(View(GetNewsVMForEdit(model.ID)));
            }
            return(Redirect("/Admin/News/Index/"));
        }
Пример #26
0
        public IActionResult Index(int page = 1)
        {
            List <News>   news  = newsRepository.GetAllNews();
            List <NewsVM> model = new List <NewsVM>();

            const int PageSize = 10;

            var count = model.Count();

            if (page == 1)
            {
                news = news.Skip(0).Take(PageSize).ToList();
            }
            else
            {
                news = news.Skip((page - 1) * PageSize).Take(PageSize).ToList();
            }

            if (count <= 10)
            {
                ViewBag.MaxPage = 1;
            }
            else
            {
                if (count % PageSize == 0)
                {
                    ViewBag.MaxPage = (count / PageSize);
                }
                else
                {
                    ViewBag.MaxPage = (count / PageSize) + 1;
                }
            }
            ViewBag.Page = page;

            ViewBag.NextPage = page + 1;

            foreach (News x in news)
            {
                NewsVM vm = new NewsVM();

                vm.Id    = x.Id;
                vm.Date  = x.Date;
                vm.Image = imageRepository.GetNewsImage(x.Id);
                if (vm.Image != null)
                {
                    vm.ImageId = vm.Image.Id;
                }
                vm.Museum   = x.Museum.Name;
                vm.Subtitle = x.SubTitle;
                vm.Text     = x.Text;
                vm.Title    = x.Title;

                model.Add(vm);
            }

            return(View(model));
        }
Пример #27
0
 public MemberController()
 {
     news_repo    = new NewsRepository();
     cat_repo     = new CategoryRepository();
     col_repo     = new ColumnistRepository();
     article_repo = new ArticleRepository();
     nvm          = new NewsVM();
     comment_repo = new CommentRepository();
 }
Пример #28
0
        public ActionResult NewsList()
        {
            NewsVM vm = new NewsVM()
            {
                NewsList = db.News.ToList(),
            };

            return(View(vm));
        }
Пример #29
0
        public ActionResult EditingNews_Create(NewsVM news)
        {
            news.Content = HttpUtility.HtmlDecode(news.Content);
            var    value = HttpContext.Session.GetString("SessionUser");
            UserVM user  = JsonConvert.DeserializeObject <UserVM>(value);

            _newsBusiness.CreateNews(news, user);
            return(Content(""));
        }
Пример #30
0
        public ActionResult Edit(News m)
        {
            NewsVM vm = new NewsVM();

            m.Date = DateTime.Now;
            vm.Update(m);
            ViewBag.Succesmessage = "Edycja pomyślna!";
            return(RedirectToAction("Index"));
        }