Пример #1
0
        public void Send(string chat_id, string speaker, string from, string to, string message)
        {
            // Call the addNewMessageToPage method to update clients.
            //Clients.User(name).Send(message);
            chatEntities db = new chatEntities();
            chat_table   c  = new chat_table()
            {
                id        = GetHashString(chat_id),
                char_text = message,
                time      = DateTime.Now,
                speaker   = from
            };

            db.chat_table.Add(c);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
            }
            var user_list = chat_id.Split(',');

            foreach (var u in user_list)
            {
                if (u.Length == 0)
                {
                    continue;
                }
                Clients.User(u).addNewMessageToPage(speaker, message);
            }
        }
Пример #2
0
        public string Post([FromBody] dynamic value)
        {
            chatEntities db       = new chatEntities();
            string       username = value["username"];

            if ((from u in db.user_table where u.username == username select u).Count() != 0)
            {
                return("用户名已存在");
            }
            user_table usrModel = new user_table()
            {
                id        = Guid.NewGuid().ToString(),
                username  = value["username"],
                password  = value["password"],
                privilege = 1,
                sex       = value["sex"],
                age       = value["age"],
                info      = value["info"]
            };

            db.user_table.Add(usrModel);
            int resCount = db.SaveChanges();

            return(usrModel.id);
        }
Пример #3
0
        public ActionResult Info()
        {
            string       id   = Session["id"].ToString().Trim();
            chatEntities db   = new chatEntities();
            var          user = (from u in db.user_table
                                 where u.id == id
                                 select u).First();

            ViewBag.password = user.password.Trim();
            ViewBag.sex      = user.sex;
            ViewBag.age      = user.age;
            ViewBag.info     = user.info;
            string from    = Session["id"].ToString();
            string chat_id = from.CompareTo(id) < 0 ? $"{from},{id}" : $"{id},{from}";
            var    history = from h in db.chat_table
                             join u in db.user_table
                             on h.speaker equals u.id
                             where h.id == chat_id
                             orderby h.time
                             select new History()
            {
                speaker = u.username, content = h.char_text, time = h.time
            };
            List <History> list = history.ToList();

            ViewData["history"] = list;
            return(View());
        }
        public OperatorReportItems GetOperatorsReport()
        {
            OperatorReportItems ProductivityReport = new OperatorReportItems();

            ProductivityReport.OperatorProductivity = new List <OperatorReportViewModel>();
            ProductivityReport.Visitors             = new List <Visitor>();
            ProductivityReport.WebSite    = new List <string>();
            ProductivityReport.DateModels = new List <DateModel>();

            try
            {
                //SqlConnection conn = new SqlConnection("Data Source=FAISALHABIB\\SQLEXPRESS;Initial Catalog=chat;User id=chat;Password=chat;");
                //SqlCommand sqlcomm = new SqlCommand("exec dbo. ", conn);

                using (var db = new chatEntities())
                {
                    GetProductivityReport(ProductivityReport, db);
                    GetVisitors(ProductivityReport, db);
                    GetWebsites(ProductivityReport, db);
                    GetDates(ProductivityReport);
                }
            }
            catch (Exception e)
            {
                //some message on window
            }
            return(ProductivityReport);
        }
Пример #5
0
        public ActionResult Login(string username, string password)
        {
            updateState();
            chatEntities db   = new chatEntities();
            var          user = from u in db.user_table
                                where (u.username == username && u.password == password)
                                select u;

            if (user.Count() == 0)
            {
                return(Json(false));
            }
            Session["login"]     = true;
            Session["id"]        = user.First().id.Trim();
            Session["username"]  = user.First().username.Trim();
            Session["privilege"] = user.First().privilege.Value;
            var context = HttpContext;

            //唯一的登陆ID,作为连接ID
            context.Response.Cookies.Add(new HttpCookie("srconnectionid")
            {
                Value = user.First().id.Trim()
            });
            return(Json(Session["id"]));
        }
        public OperatorReportItems GetOperatorsReport(string device, string web, string startDate, string endDate)
        {
            OperatorReportItems ProductivityReport = new OperatorReportItems();

            ProductivityReport.OperatorProductivity = new List <OperatorReportViewModel>();
            //ProductivityReport.Visitors = new List<Visitor>();
            //ProductivityReport.WebSite = new List<string>();
            //ProductivityReport.DateModels = new List<DateModel>();

            try
            {
                using (var db = new chatEntities())
                {
                    // Get filters data
                    DateTime?startDateTime = null;
                    if (startDate != "null")
                    {
                        var tt = startDate.Replace("0:0:0", "00:00:00");
                        // startDateTime = DateTime.ParseExact(startDate.Replace(' ','-'), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); // DateTime.Parse(startDate);
                        startDateTime = DateTime.ParseExact(tt, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                    }

                    DateTime?endDateTime = null;
                    if (endDate != "null")
                    {
                        endDateTime = DateTime.ParseExact(endDate, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                    }

                    if (web == "null")
                    {
                        web = null;
                    }

                    if (device == "null")
                    {
                        device = null;
                    }

                    var reports = db.OperatorProductivity(website: web, device: device, startDate: startDateTime, endDate: endDateTime).ToList();
                    GetProductivityReport(ProductivityReport, reports);
                    //GetVisitors(ProductivityReport, db);
                    //GetWebsites(ProductivityReport, db);
                    //GetDates(ProductivityReport);
                }
            }
            catch (Exception e)
            {
                // will some message on window
            }

            return(ProductivityReport);
        }
Пример #7
0
 void updateState()
 {
     if (!(Session["login"] is null))
     {
         string       id   = Session["id"].ToString();
         chatEntities db   = new chatEntities();
         var          user = from u in db.user_table
                             where (u.id == id)
                             select u;
         user.First().last_app = DateTime.Now;
         db.SaveChanges();
     }
 }
Пример #8
0
        private void GetDevices(OperatorReportFilter operatorReportFilter, chatEntities db)
        {
            var devicesDB = db.Visitor.Select(x => x.Device).Distinct();
            var visitor   = db.Visitor;

            foreach (var device in devicesDB)
            {
                operatorReportFilter.Devices.Add(new Device()
                {
                    Name = device,
                    Ids  = visitor.Where(x => x.Device == device).Select(x => x.VisitorID).ToList()
                });
            }
        }
Пример #9
0
        public ActionResult Control()
        {
            updateState();
            if (Session["login"] is null)
            {
                return(View("LoginFirst"));
            }
            chatEntities db   = new chatEntities();
            var          user = from u in db.user_table
                                select u;

            ViewData["UserList"] = user.ToList();
            return(View());
        }
Пример #10
0
        public OperatorReportFilter GetOperatorReportFilter()
        {
            OperatorReportFilter operatorReportFilter = new OperatorReportFilter();

            operatorReportFilter.WebSite    = new List <string>();
            operatorReportFilter.DateModels = new List <DateModel>();
            operatorReportFilter.Devices    = new List <Device>();
            using (var db = new chatEntities())
            {
                // Get filters data

                GetWebsites(operatorReportFilter, db);
                GetDates(operatorReportFilter);
                GetDevices(operatorReportFilter, db);
            }
            return(operatorReportFilter);
        }
Пример #11
0
        public string Post([FromBody] dynamic value)
        {
            if ((int)value["type"] == 1)
            {
                chatEntities db   = new chatEntities();
                string       id   = value["id"];
                var          list = from u in db.user_table where u.id == id select u;

                if ((list.Count() == 0))
                {
                    return("用户名不存在");
                }
                var user = list.First();
                user.password  = value["password"];
                user.privilege = value["privilege"];
                user.sex       = value["sex"];
                user.age       = value["age"];
                user.info      = value["info"];
                int resCount = db.SaveChanges();
                return(user.id);
            }
            else
            {
                chatEntities db       = new chatEntities();
                string       username = value["username"];
                var          list     = from u in db.user_table where u.username == username select u;

                if ((list.Count() == 0))
                {
                    return("用户名不存在");
                }
                var user = list.First();
                user.password = value["password"];
                user.sex      = value["sex"];
                user.age      = value["age"];
                user.info     = value["info"];
                int resCount = db.SaveChanges();
                return(user.id);
            }
        }
Пример #12
0
        public ActionResult Chat(string id)
        {
            var id_list = id.Split(',');

            Array.Sort(id_list);

            chatEntities  db        = new chatEntities();
            var           user_list = new List <user_table>();
            StringBuilder sb        = new StringBuilder();

            for (int i = 0; i < id_list.Length; i++)
            {
                var s    = id_list[i];
                var user = from u in db.user_table
                           where u.id == s
                           select u;
                user_list.Add(user.First());
                sb.Append(user.First().username + " ");
            }

            string from    = Session["id"].ToString();
            string chat_id = string.Join(",", id_list);
            string hash_id = GetHashString(chat_id);
            var    history = from h in db.chat_table
                             join u in db.user_table
                             on h.speaker equals u.id
                             where h.id == hash_id
                             orderby h.time
                             select new History()
            {
                speaker = u.username, content = h.char_text, time = h.time
            };
            List <History> list = history.ToList();

            ViewData["history"] = list;
            ViewData["users"]   = user_list;
            ViewBag.chat_id     = chat_id;
            ViewBag.usernames   = sb.ToString();
            return(View());
        }
Пример #13
0
        public ActionResult Ground()
        {
            updateState();
            if (Session["login"] is null)
            {
                return(View("LoginFirst"));
            }
            chatEntities db   = new chatEntities();
            var          user = from u in db.user_table
                                select u;
            List <User> list = new List <User>();

            foreach (var u in user)
            {
                list.Add(new User()
                {
                    username = u.username, info = u.info, age = u.age.Value, id = u.id, sex = u.sex.Value, state = (timeDiff(u.last_app.Value) < 1.0)
                });
            }
            ViewData["UserList"] = list;
            return(View());
        }
        private static void GetProductivityReport(OperatorReportItems ProductivityReport, chatEntities db)
        {
            var reports = db.OperatorProductivity(website: null, visitorID: null, startDate: null, endDate: null).ToList();

            //   var starters = db.Messages.GroupBy(x => x.ConversationID);

            // SqlDataReader dr = sqlcomm.ExecuteReader();
            //  if (dr.Read())
            foreach (var dr in reports)
            {
                OperatorReportViewModel opVM = new Models.OperatorReportViewModel();
                opVM.ID   = Convert.ToInt32(dr.OperatorID);
                opVM.Name = Convert.ToString(dr.Name);
                opVM.ProactiveAnswered     = Convert.ToInt32(dr.ProactiveAnswered);
                opVM.ProactiveSent         = Convert.ToInt32(dr.ProactiveSent);
                opVM.ProactiveResponseRate = Convert.ToInt32(dr.ProactiveResponseRate);
                opVM.ReactiveAnswered      = Convert.ToInt32(dr.ReactiveAnswered);
                opVM.ReactiveReceived      = Convert.ToInt32(dr.ReactiveReceived);
                opVM.ReactiveResponseRate  = Convert.ToInt32(dr.ReactiveResponseRate);
                opVM.AverageChatLength     = Convert.ToString(dr.AverageChatLength) + "mm";
                //  opVM.TotalChatLength = Convert.ToString(dr.TotalChatLength)+"mm";
                TimeSpan t = TimeSpan.FromMinutes(Convert.ToDouble(dr.TotalChatLength));

                string answer = string.Format("{0:D2}d:{1:D2}h:{2:D2}m",
                                              t.Days,
                                              t.Hours,
                                              t.Minutes);
                opVM.TotalChatLength = answer;
                ProductivityReport.OperatorProductivity.Add(opVM);
            }
        }
        private void GetVisitors(OperatorReportItems productivityReport, chatEntities db)
        {
            var visitors = db.Visitor.ToList();

            productivityReport.Visitors = visitors;
        }
 private void GetWebsites(OperatorReportItems productivityReport, chatEntities db)
 {
     productivityReport.WebSite = db.Conversation.Select(x => x.Website).Distinct().ToList();
 }
Пример #17
0
 private void GetWebsites(OperatorReportFilter operatorReportFilter, chatEntities db)
 {
     operatorReportFilter.WebSite = db.Conversation.Select(x => x.Website).Distinct().ToList();
 }