Exemplo n.º 1
0
        /// <summary>
        /// 将事件源进行反序列化
        /// </summary>
        /// <param name="storedEvents"></param>
        private static void HistoryDeserializer(IEnumerable <Infrastructure.Entitys.StoredEvent> userEvents)
        {
            foreach (var e in userEvents)
            {
                var     slot = new UserHistoryModel();
                dynamic values;

                var classes       = Assembly.Load("Domain.Models").GetTypes();
                var NamespaceList = classes.Where(x => x.Namespace == "Domain.Models.EventModels.User").ToList();
                foreach (var item in NamespaceList)
                {
                    Console.WriteLine(item.Name);
                    if (e.MessageType == item.Name)
                    {
                        values      = JsonConvert.DeserializeObject <dynamic>(e.Data);
                        slot.Email  = values["Email"];
                        slot.Phone  = values["Phone"];
                        slot.Name   = values["Name"];
                        slot.Action = "Registered";
                        slot.When   = values["Timestamp"];
                        slot.Id     = values["UserId"];
                        slot.Who    = e.CreateName;
                        HistoryData.Add(slot);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // 将数据从事件源中获取到list中
        public static IList <Domain.Models.HistoryModels.UserHistoryModel> ToJavaScriptStudentHistory(IList <Infrastructure.Entitys.StoredEvent> storedEvents)
        {
            HistoryData = new List <Domain.Models.HistoryModels.UserHistoryModel>();
            HistoryDeserializer(storedEvents);

            var sorted = HistoryData.OrderBy(c => c.When);
            var list   = new List <UserHistoryModel>();
            var last   = new UserHistoryModel();

            foreach (var change in sorted)
            {
                var jsSlot = new UserHistoryModel
                {
                    Id     = change.Id == Guid.Empty.ToString() || change.Id == last.Id? "": change.Id,
                    Name   = string.IsNullOrWhiteSpace(change.Name) || change.Name == last.Name? "": change.Name,
                    Email  = string.IsNullOrWhiteSpace(change.Email) || change.Email == last.Email? "": change.Email,
                    Phone  = string.IsNullOrWhiteSpace(change.Phone) || change.Phone == last.Phone? "": change.Phone,
                    Action = string.IsNullOrWhiteSpace(change.Action) ? "" : change.Action,
                    When   = change.When,
                    Who    = change.Who
                };

                list.Add(jsSlot);
                last = change;
            }
            return(list);
        }
Exemplo n.º 3
0
        public ActionResult Index(int?page)
        {
            UserHistoryModel     userHistoryModel = new UserHistoryModel();
            UserHistoryViewModel viewModel        = new UserHistoryViewModel();
            var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1)

            Guid userId = (Guid)Membership.GetUser().ProviderUserKey;

            viewModel.AllUserHistoryPaged = userHistoryModel.GetAllUserHistoryPagedByUser(pageNumber, 10, userId);
            return(View(viewModel));
        }
Exemplo n.º 4
0
        public ActionResult Delete(int historyId)
        {
            UserHistoryModel userHistoryModel = new UserHistoryModel();
            int result = userHistoryModel.DeleteUserHistory(historyId);

            if (result > 0)
            {
                return(Json(new { message = "SUCCESS" }));
            }
            else
            {
                return(Json(new { message = "FAIL" }));
            }
        }
Exemplo n.º 5
0
        // GET: api/Login
        public IEnumerable <UserHistoryModel> Get(int limit)
        {
            var history = new List <UserHistoryModel>();

            using (OdbcConnection conn = new OdbcConnection(connectionString))
            {
                OdbcCommand cmd = new OdbcCommand();
                cmd.Connection = conn;

                try
                {
                    conn.Open();
                    cmd.CommandText = $"SELECT ID, IP, TIME FROM HISTORY_SIGN_ON ORDER BY TIME DESC LIMIT {limit}";

                    OdbcDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var model = new UserHistoryModel();
                        model.ID   = (string)reader[0];
                        model.IP   = (string)reader[1];
                        model.Time = (DateTime)reader[2];
                        history.Add(model);
                    }

                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Error Get login History", ex);
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Dispose();
                    }
                }
            }

            return(history);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> AgentSummary()
        {
            try
            {
                var onlineEmails = NotificationHub.OnlineAgents();
                var KeyValues    = NotificationHub.GetConnections();
                var Campaigns    = await db.Campaigns.Where(x => !x.IsDeleted).ToListAsync();

                var entities = await db.Users.Where(x => !x.IsDeleted && x.Roles.Any(y => y.RoleId.Equals("2") || y.RoleId.Equals("3"))).ToListAsync();

                var onlineUsers = onlineEmails.Select(c => entities.Where(x => x.Email.Equals(c)).FirstOrDefault()).Where(z => z != null).ToList();


                var onlineModel = KeyValues.Select(c => new OnlineUser
                {
                    User           = entities.FirstOrDefault(x => x.Email.Equals(c.UserName)),
                    Campaign       = Campaigns.FirstOrDefault(x => x.Id == c.CampaignId),
                    ConnectionTime = (DateTime.Now - db.UsersHistory.FirstOrDefault(x => x.Id == c.UserHistoryId)?.LoggedIn) ?? TimeSpan.FromSeconds(0)
                }
                                                   ).Where(z => z != null).ToList();


                var offlineUsers = entities.Except(onlineUsers).ToList();

                var model = new UserHistoryModel
                {
                    OnlineUsers  = onlineModel.Where(x => x.User != null).ToList(),
                    OfflineUsers = offlineUsers
                };

                return(View(model));
            }
            catch (Exception e)
            {
                AddAlert($"Oops! something went wrong. Error code: {e.HResult}", "Index", this.GetType().ToString(), AlertType.error, e);
                return(View());
            }
        }
        //
        // GET: /Result/

        public ActionResult Index(string keyword)
        {
            // If keyword is null or empty then system will redirect to home page
            if (keyword == null || keyword.Trim().Equals(""))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // Instance model layer
            ResultModel resultModel = new ResultModel();

            // Instance view model for result
            ResultViewModel resultViewModel = new ResultViewModel();

            // Get entry by keyword
            WordIndex entry = resultModel.GetEntryByKeyword(keyword);

            // Property of search history
            bool isExistData = true;

            // Check has entry
            if (entry != null)
            {
                //set view model
                resultViewModel.Entry = entry;

                // List result
                if (entry.Synsets.Where(x => x.Category == "n").Count() > 0)
                {
                    ViewBag.Noun = entry.Synsets.Where(x => x.Category == "n");
                }
                if (entry.Synsets.Where(x => x.Category == "v").Count() > 0)
                {
                    ViewBag.Verb = entry.Synsets.Where(x => x.Category == "v");
                }

                //add history
                isExistData = true;
            }
            else
            {
                isExistData = false;
            }

            //add history
            SearchHistoryModel searchHistoryModel = new SearchHistoryModel();

            searchHistoryModel.AddSearchHistory(keyword, isExistData);

            //add user history
            if (Request.IsAuthenticated)
            {
                UserHistoryModel userHistoryModel = new UserHistoryModel();
                userHistoryModel.AddUserHistory(keyword);
            }


            //---------------------------------------
            // Store 5 recent keywords
            if (Session["Recent"] == null)
            {
                Session["Recent"] = new List <string>();
            }

            int countRecent = ((List <string>)Session["Recent"]).Count;


            if (((List <string>)Session["Recent"]).Contains(keyword))
            {
                ((List <string>)Session["Recent"]).Remove(keyword);
            }
            else if (countRecent >= 5)
            {
                ((List <string>)Session["Recent"]).RemoveAt(0);
            }
            ((List <string>)Session["Recent"]).Add(keyword);

            //((List<string>)Session["Recent"]).Reverse();
            //string[] arraySuggest = new string[((List<string>)Session["Recent"]).Count];
            //((List<string>)Session["Recent"]).CopyTo(arraySuggest);
            //ViewBag.Recent = arraySuggest;
            //((List<string>)Session["Recent"]).Reverse();
            //---------------------------------------

            //ViewBag.Title
            ViewBag.Title = "Kết quả tra cứu cho '" + keyword + "'";

            // add suggest terms
            EntriesModel entryModel = new EntriesModel();

            resultViewModel.SuggestTerm = entryModel.SuggestTerm(keyword);

            // get questions
            QAModel qaModel = new QAModel();

            resultViewModel.Questions = qaModel.GetQuestionPaged(1, 10);

            return(View(resultViewModel));
        }