Exemple #1
0
        public ActionResult GetRoomsSearch(StatsResultVM stats)
        {
            int userId = Convert.ToInt32(stats.UserId);
            DateTime DateLow = Convert.ToDateTime(stats.DateLow);
            DateTime DateHigh = Convert.ToDateTime(stats.DateHigh);
            DateHigh = DateHigh.AddDays(1);
            var user = _repo.FindUserById(userId);
            var rooms = _service.GetAllChatRoomsByUser(userId);

            ViewBag.AdminName = user.FirstName + " " + user.LastName;
            ViewBag.DateRange = stats.DateLow + " - " + stats.DateHigh;

            var totalRooms = rooms.Where(r => r.StartTime >= DateLow && r.EndTime <= DateHigh);
            TotalItems = totalRooms.Count();

            StatsResultVM srVM = new StatsResultVM();
            srVM.DateHigh = stats.DateHigh;
            srVM.DateLow = stats.DateLow;
            srVM.RoomId = stats.RoomId;
            srVM.TotalCount = stats.TotalCount;
            srVM.UsersString = stats.UsersString;
            srVM.UserId = stats.UserId;
            srVM.PaginationInfo = new PagingInfo() { CurrentPage = stats.CurrentPage, ItemsPerPage = ItemsPerPage, TotalItems = TotalItems };

            var roomsToDisplay = totalRooms.Page(srVM.PaginationInfo.CurrentPage, srVM.PaginationInfo.ItemsPerPage);

            foreach (var r in roomsToDisplay)
            {
                StatRoomItem srI = new StatRoomItem();
                srI.ChatRoomId = r.ChatRoomId;
                srI.ChatUserId = r.ChatUserId;
                srI.EndTime = r.EndTime;
                srI.StartTime = r.StartTime;
                srVM.StatRoomItems.Add(srI);
            }

            return PartialView("GetRoomsSearch", srVM);
        }
Exemple #2
0
        public StatsResultVM GetUserStats(StatsVM stats)
        {
            var dateLow = Convert.ToDateTime(stats.DateLow);
            var dateHigh = Convert.ToDateTime(stats.DateHigh);
            dateHigh = dateHigh.AddDays(1);

            var rooms = _repo.GetAllChatRoomsByDate(dateLow, dateHigh);
            var users = _repo.GetActiveAdminChatUsers();

            string[] split = stats.UsersString.Split(',');
            int[] uId = new int[split.Length];
            List<ChatUser> usersList = new List<ChatUser>();

            if (!split.Contains("all"))
            {
                for (int i = 0; i < split.Length; i++)
                {
                    int num;
                    num = Convert.ToInt32(split[i]);
                    uId[i] = num;
                }
                foreach (var u in users)
                {
                    if (uId.Contains(u.ChatUserId))
                    {
                        usersList.Add(u);
                    }
                }
            }
            else
            {
                foreach (var u in users)
                {
                        usersList.Add(u);
                }
            }

            StatsResultVM srVM = new StatsResultVM();
            srVM.DateLow = stats.DateLow;
            srVM.DateHigh = stats.DateHigh;
            srVM.UsersString = stats.UsersString;

            foreach (var uil in usersList)
            {
                StatItem statItem = new StatItem();
                statItem.UserName = uil.FirstName + " " + uil.LastName;
                statItem.RoomCount = rooms.Where(r => r.AdminChatUserId == uil.ChatUserId).Count();
                statItem.UserId = uil.ChatUserId;
                srVM.StatItems.Add(statItem);
                srVM.TotalCount += statItem.RoomCount;
            }

             var userOrderByRoomCount = srVM.StatItems.OrderByDescending(i => i.RoomCount).ToList();
             srVM.StatItems = userOrderByRoomCount;

            return srVM;
        }
Exemple #3
0
        public ActionResult GetMessagesSearch(StatsResultVM stats)
        {
            var messages = _repo.GetMessagesByChatRoom(stats.RoomId);

            StatsResultVM srVM = new StatsResultVM();
            srVM.DateHigh = stats.DateHigh;
            srVM.DateLow = stats.DateLow;
            srVM.RoomId = stats.RoomId;
            srVM.TotalCount = stats.TotalCount;
            srVM.UsersString = stats.UsersString;
            srVM.UserId = stats.UserId;

            foreach (var m in messages)
            {
                StatMessageItem smI = new StatMessageItem();

                smI.ChatRoomId = m.ChatRoomId;
                smI.ChatUserId = m.ChatUserId;
                smI.Content = m.Content;
                smI.MessageSent = m.MessageSent;
                smI.UserName = m.UserName;

                srVM.StatMessageItems.Add(smI);
            }

            return PartialView("GetMessagesSearch",srVM);
        }