Пример #1
0
        public ActionResult Index()
        {
            if (!_permissionService.Authorize("ManageDashboard"))
            {
                return(AccessDeniedView());
            }

            var model = new DashboardModel();

            prepareRegisteredUsers(model);
            prepareFeedbacks(model);
            prepareActiveInactiveUsers(model);
            prepareEvents(model);

            model.ActiveSettings    = "";
            model.VisitsToday       = _userService.GetUserCountByLoginDate(DateTime.Now);
            model.EventsToday       = _eventService.GetEventCountByCreatedDate(DateTime.Now);
            model.CommentsToday     = _commentService.GetCommentCountByCreatedDate(DateTime.Now);
            model.FeedbacksToday    = _feedbackService.GetFeedbackCountByCreatedDate(DateTime.Now);
            model.PendingUsersCount = _userService.GetPendingUserCount();
            model.LogsCount         = _systemLogService.GetLogCountTillDate();
            //model.ReturnUsers = _userService.GetAllUserLocations().GroupBy(j => j.UserId).Where(g => g.Count() > 1 && g.FirstOrDefault().UserId != 0).Select(u => new IPAddress() {
            //	Address = u.FirstOrDefault().Address,
            //	CreatedOn = u.FirstOrDefault().CreatedOn,
            //	Location = u.FirstOrDefault().Location.Trim().Replace(",", ""),
            //	Latitude = u.FirstOrDefault().Latitude,
            //	Longitude = u.FirstOrDefault().Longitude,
            //	Id = u.FirstOrDefault().Id,
            //	UserId = u.FirstOrDefault().UserId
            //}).ToList();

            //model.UniqueUsers = _userService.GetAllUserLocations().GroupBy(j => j.UserId).Where(g => g.Count() == 1 || g.FirstOrDefault().UserId == 0).Select(u => new IPAddress()
            //{
            //	Address = u.FirstOrDefault().Address,
            //	CreatedOn = u.FirstOrDefault().CreatedOn,
            //	Location = u.FirstOrDefault().Location.Trim().Replace(",",""),
            //	Latitude = u.FirstOrDefault().Latitude,
            //	Longitude = u.FirstOrDefault().Longitude,
            //	Id = u.FirstOrDefault().Id,
            //	UserId = u.FirstOrDefault().UserId
            //}).ToList();

            //var lstAddresses = new List<IPAddress>();
            //lstAddresses.AddRange(model.ReturnUsers);
            //lstAddresses.AddRange(model.UniqueUsers);
            //model.ConsolidateUserModel = lstAddresses.GroupBy(mu => mu.CreatedOn.Date).Select(mu => new ConsolidateUserModel() {
            //	ReturnCount = mu.Intersect(model.ReturnUsers).Count(),
            //	UniqueCount = mu.Intersect(model.UniqueUsers).Count(),
            //	Date = mu.Key,
            //}).ToList();

            model.Comments = _commentService.GetCommentsByDate(DateTime.Now).Select(c => new AdminCommentsModel()
            {
                CommentDate  = c.CreatedOn.Value,
                CommentHtml  = c.CommentHtml,
                DisplayOrder = c.DisplayOrder,
                UserId       = c.UserId,
                UserName     = c.Username,
                Replies      = _replyService.GetAllRepliesByComment(c.Id).Select(r => new ReplyModel()
                {
                    DisplayOrder = r.DisplayOrder,
                    Id           = r.Id,
                    CommentId    = r.CommentId,
                    CreatedOn    = r.CreatedOn,
                    ReplyHtml    = r.ReplyHtml,
                    UserId       = r.UserId,
                }).OrderBy(r => r.DisplayOrder).ToList()
            }).OrderByDescending(c => c.CommentDate).ToList();

            //model.MergedUsers = lstAddresses;
            return(View(model));
        }