示例#1
0
        public async Task <string> Create(string stock)
        {
            using (db = new testEntities())
            {
                if (StockRealTimeTicker.CheckExistStock(stock))
                {
                    ApplicationUser currentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                    var followrStockByUser = await db.FollowStocks.FirstOrDefaultAsync(f => f.UserId == currentUser.UserExtentLogin.Id && f.StockFollowed == stock);

                    if (followrStockByUser == null)
                    {
                        var stockfollow = new FollowStock {
                            UserId = currentUser.UserExtentLogin.Id, StockFollowed = stock, CreatedDate = DateTime.Now
                        };
                        db.FollowStocks.Add(stockfollow);
                        await db.SaveChangesAsync();

                        return("A");
                    }
                    else
                    {
                        db.FollowStocks.Remove(followrStockByUser);
                        await db.SaveChangesAsync();

                        return("R");
                    }
                }
                else
                {
                    return("E");
                }
            }
        }
示例#2
0
 public HomeController(StockRealTimeTicker stockTicker, UserManager <ApplicationUser> userManager)
 {
     //_keyword = KeyworkSing;
     _stockRealtime = stockTicker;
     UserManager    = userManager;
 }
示例#3
0
 public LienheController(StockRealTimeTicker stockTicker, UserManager <ApplicationUser> userManager)
 {
     _stockRealtime = stockTicker;
     UserManager    = userManager;
 }
示例#4
0
        public async Task <string> AddPost(Post post, byte nhanDinh, string chartImage, long?userpageid)
        {
            using (db = new testEntities())
            {
                #region user login
                string resultString = string.Empty;
                // get info login (Lấy thông tin đăng nhập)
                var userlogin = await(from ul in db.UserLogins
                                      where ul.UserNameCopy == Context.User.Identity.Name
                                      select new { ul.Id, ul.BrokerVIP, ul.UserNameCopy, ul.AvataImage, ul.DisableUser }).FirstOrDefaultAsync();
                if (userlogin == null || userlogin.DisableUser == true) // user khong tim thay hoac bi disable
                {
                    return(resultString = "L");                         // user is disable
                }
                #endregion

                #region format message
                string messagedefault = "";
                string stockTag       = ""; // dinh dang stock|stock|stock de tim co phieu lien quan
                messagedefault = post.Message;
                string[] listMessege       = post.Message.Replace("\n", " <br> ").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   messageFromatHTML = "";
                foreach (var item in listMessege)
                {
                    if (item.Length > 0 && item.Length < 2000)
                    {
                        if (item.IndexOf("$", 0, 1) != -1)                        // tag ma co phieu
                        {
                            string ticker = item.RemoveSpecialString().ToUpper(); //item.Replace("$", "").Replace(",", "").Replace(".", "").Replace("!", "").Replace("?", "").Trim().ToUpper();
                            messageFromatHTML += "<b><a onclick=selectMe(event,\"#\") target='_blank' href='/ticker/" + ticker + "'>" + item + "</a></b>" + " ";
                        }
                        else if (item.IndexOf("@", 0, 1) != -1) // tag nguoi dung
                        {
                            string user = item.RemoveSpecialString().ToLower();
                            messageFromatHTML += "<a onclick=selectMe(event,\"#\") target='_blank' href='/" + user + "'>" + item + "</a>" + " ";
                        }
                        else if ((item.Contains("http") || item.Contains("www.")) && item.Length >= 4)
                        {
                            if (item.IndexOf("http", 0, 4) != -1 || item.IndexOf("www.", 0, 4) != -1)
                            {
                                URLTiny tu = new URLTiny();
                                tu.URLName    = item;
                                tu.PostedDate = DateTime.Now;
                                dbtinyURL.URLTinies.Add(tu);
                                try
                                {
                                    await dbtinyURL.SaveChangesAsync();
                                }
                                catch (Exception)
                                {
                                    // log
                                }
                                messageFromatHTML += "Nguồn tại <a onclick=selectMe(event,\"#\") target='_blank' href='" + hostURL + "/" + tu.Id + "'>" + AppHelper.GetDomain(item) + "...</a>" + " ";
                            }
                            else
                            {
                                messageFromatHTML += item + " ";
                            }
                        }
                        else
                        {
                            messageFromatHTML += item + " ";
                        }
                    }
                }

                #endregion

                #region explan this passing messege to stockcode and username list
                //messageFromatHTML += "</a>";

                var           listStock           = new List <string>();
                var           listUsersendMessege = new List <string>();
                string        replyRelated        = string.Empty;
                string        replyRelatedUser    = string.Empty;
                List <string> listMessegeSplit    = messagedefault.Replace("\n", " ").Split(' ').ToList().FindAll(p => p.Contains("$") || p.Contains("@"));

                #endregion

                #region gui message co phieu và user lien quan
                string[] userReplyRelated = new string[2];
                userReplyRelated[0] = string.Empty;
                userReplyRelated[1] = string.Empty;

                foreach (var item in listMessegeSplit)
                {
                    if (item.Length > 0)
                    {
                        string stockcode = item.RemoveSpecialString().ToUpper();
                        if (item.IndexOf("$", 0, 1) != -1 && !listStock.Contains(stockcode) && StockRealTimeTicker.CheckExistStock(stockcode)) // find the stock with $
                        {
                            stockTag += stockcode + "|";
                            listStock.Add(stockcode);           // group of hub for client
                        }
                        else if (item.IndexOf("@", 0, 1) != -1) //find the user with @
                        {
                            string user     = item.RemoveSpecialString().ToLower();
                            var    finduser = await db.UserLogins.FirstOrDefaultAsync(ul => ul.UserNameCopy == user);

                            if (finduser != null)
                            {
                                NotificationMessege nM = new NotificationMessege {
                                    UserPost = userlogin.Id, UserReciver = finduser.Id, PostId = post.PostId, NumNoti = 1, TypeNoti = "U", CreateDate = DateTime.Now, XemYN = true
                                };
                                db.NotificationMesseges.Add(nM);
                                listUsersendMessege.Add(user); // add user to send notification
                                userReplyRelated = AppHelper.StringUserSlipt(userReplyRelated, user, finduser.Id.ToString());
                            }
                        }
                    }
                }
                #endregion

                #region luu vao db
                /* add stockrelate */
                post.Message          = AppHelper.FilteringWord(messageFromatHTML); // Filteringword lọc từ khóa bậy
                post.PostedBy         = userlogin.Id;
                post.PostedDate       = DateTime.Now;
                post.NhanDinh         = nhanDinh;
                post.SumLike          = 0;
                post.ReplyRelated     = AppHelper.StringUserSlipt(userReplyRelated, userlogin.UserNameCopy, userlogin.Id.ToString())[0];  // thong bao cho toan user voi tag user|user|user
                post.ReplyRelatedUser = AppHelper.StringUserSlipt(userReplyRelated, userlogin.UserNameCopy, userlogin.Id.ToString())[1];; // thong bao cho toan user voi tag id|id|id
                if (!string.IsNullOrWhiteSpace(chartImage))
                {
                    post.ChartYN       = true;
                    post.ChartImageURL = chartImage.Replace("?width=50&height=50&mode=crop", "");
                }
                post.StockPrimary = stockTag; // lấy các stock #tag cuối GAS!PAS
                try
                {
                    db.Posts.Add(post);
                    await db.SaveChangesAsync();
                }
                catch (Exception)
                {
                    // log
                }

                var ret = new
                {
                    Message        = post.Message,
                    Chart          = post.ChartImageURL,
                    PostedByName   = userlogin.UserNameCopy,
                    PostedByAvatar = string.IsNullOrEmpty(userlogin.AvataImage) == true ? AppHelper.ImageURLAvataDefault : AppHelper.ImageURLAvata + userlogin.AvataImage,
                    PostedDate     = post.PostedDate,
                    PostId         = post.PostId,
                    StockPrimary   = post.StockPrimary,
                    Stm            = post.NhanDinh,
                    ChartYN        = post.ChartYN,
                    PostBy         = post.PostedBy,
                    SumLike        = 0,
                    SumReply       = 0,
                    BrkVip         = userlogin.BrokerVIP
                };

                #endregion

                #region gui message
                if (listStock.Count > 0)
                {
                    await Clients.All.addPostGlobal(ret); // add message vào profile va home

                    resultString = "S";                   // post thanh cong len trang home va profile
                }
                else
                {
                    resultString = "O"; // chi post o trang ca nhan
                }

                if (userpageid > 0) // gửi cho cùng 1 nhóm đag mở cùng 1 user page
                {
                    listStock.Add(userpageid.ToString());
                }

                await Clients.Groups(listStock).addPost(ret); // ad group co phieu lien quan

                if (listUsersendMessege.Count > 0)
                {
                    await Clients.Users(listUsersendMessege).MessegeOfUserPost(1); // gui tin bao cho user nao có @
                }
                return(resultString);

                #endregion
            }
        }
示例#5
0
 public RealTimePriceHub(StockRealTimeTicker stockTicker)
 {
     _stockRealtime = stockTicker;
 }
示例#6
0
 public HuongdansudungController(StockRealTimeTicker stockTicker, UserManager <ApplicationUser> userManager)
 {
     _stockRealtime = stockTicker;
     UserManager    = userManager;
 }