public ActionResult GetAllRecentComplaints()
        {
            HtmlToText    convert   = new HtmlToText();
            HomeViewModel homeModel = new HomeViewModel();

            IQueryable <Report> reports = _applicationDbContext.Reports
                                          .OrderByDescending(d => d.DateCreated)
                                          .Take(10);
            var reportList = new List <IndexReportViewModel>();

            foreach (var report in reports)
            {
                var reportModel = new IndexReportViewModel();
                reportModel.ReportId = report.ReportId;
                var User        = UserManager.FindByIdAsync(report.UserId);
                var ReportOwner = User.Result.NameExtension;
                reportModel.DisplayName = ReportOwner;

                string myString     = convert.Convert(report.ReportText).Substring(0, 90);
                int    index        = myString.LastIndexOf(' ');
                string outputString = myString.Substring(0, index);

                reportModel.ReportText  = outputString;
                reportModel.DateCreated = report.DateCreated;

                reportList.Add(reportModel);
            }
            homeModel.IndexReportViewModels = reportList;
            //return View("Index", homeModel);
            return(PartialView("_RecentComplaints", homeModel));
        }
Beispiel #2
0
        public ActionResult Index(string id, string syear)
        {
            List <SelectListItem> finyears = new List <SelectListItem>();


            for (int i = 2015; i <= DateTime.Now.Year; i++)
            {
                finyears.Add(new SelectListItem
                {
                    Text  = i.ToString(),
                    Value = i.ToString()
                });
            }



            var model = new IndexReportViewModel
            {
                FinYears = finyears
            };

            return(View(model));
        }
        public async Task <ActionResult> Index()
        {
            var mainModel    = new FeedbackWithBlog();
            var listFeedback = new List <FeedbackViewModel>();
            var listBlog     = new List <BlogViewModel>();
            var homeModel    = new HomeViewModel();
            var convert      = new HtmlToText();

            var blogs = _applicationDbContext.Blogs.OrderByDescending(d => d.DateCreated).Take(10).ToList();

            foreach (var i in blogs)
            {
                var blogModel = new BlogViewModel();
                blogModel.BlogId      = i.BlogId;
                blogModel.Title       = i.Title;
                blogModel.DateCreated = i.DateCreated;
                listBlog.Add(blogModel);
            }

            var feedbacks = _applicationDbContext.Feedbacks.OrderByDescending(d => d.DateCreated).Take(10).ToList();

            foreach (var i in feedbacks)
            {
                var User     = UserManager.FindByIdAsync(i.UserId);
                var userName = User.Result.NameExtension;

                var model = new FeedbackViewModel()
                {
                    DateCreated = i.DateCreated,
                    Message     = i.Message,
                    UserName    = userName
                };

                listFeedback.Add(model);
            }

            IQueryable <Report> reports = _applicationDbContext.Reports
                                          .OrderByDescending(d => d.DateCreated)
                                          .Take(10);
            var reportList = new List <IndexReportViewModel>();

            foreach (var report in reports)
            {
                var reportModel = new IndexReportViewModel();
                reportModel.ReportId = report.ReportId;
                var User        = UserManager.FindByIdAsync(report.UserId);
                var ReportOwner = User.Result.NameExtension;
                reportModel.DisplayName = ReportOwner;

                string myString     = convert.Convert(report.ReportText).Substring(0, 90);
                int    index        = myString.LastIndexOf(' ');
                string outputString = myString.Substring(0, index);

                reportModel.ReportText  = outputString;
                reportModel.DateCreated = report.DateCreated;

                reportList.Add(reportModel);
            }

            IQueryable <Question> questions = _applicationDbContext.Questions
                                              .OrderByDescending(d => d.DateAsked)
                                              .Take(10);

            var questionList = new List <IndexQuestionViewModel>();

            foreach (var question in questions)
            {
                var questionModel = new IndexQuestionViewModel();
                questionModel.QuestionId = question.QuestionId;
                var User        = UserManager.FindByIdAsync(question.UserId);
                var ReportOwner = User.Result.NameExtension;
                questionModel.DisplayName = ReportOwner;

                questionModel.QuestionText  = question.QuestionText;
                questionModel.DateAsked     = question.DateAsked;
                questionModel.QuestionTitle = question.Title;

                questionList.Add(questionModel);
            }

            ViewBag.Questions = questionList;

            ViewBag.Complaints = reportList;

            mainModel.Posts        = listBlog;
            mainModel.Testimonials = listFeedback;
            return(View(mainModel));
        }