示例#1
0
        /// <summary>
        /// 取得股票資訊
        /// </summary>
        /// <param name="StockNum"></param>
        /// <returns></returns>
        public ActionResult GetStockInfo(String StockNum)
        {
            BaseResModel <StockInfoResModel> result = new BaseResModel <StockInfoResModel>();

            try
            {
                int AuthStatus = AuthServcies.Islogin(Request);
                if (AuthStatus == 2)
                {
                    result.Code = ResponseCodeEnum.AuthFail;
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                if (AuthServcies.IsOverQuery(Request))
                {
                    throw new Exception("查詢過於繁複,請稍候再試!");
                }

                using (var db = new LiteDatabase(LazyStockDBPath))
                {
                    // Get customer collection
                    var StockInfos = db.GetCollection <StockInfoResModel>("StockInfo");
                    var StockInfo  = StockInfos.FindById(StockNum);
                    if (StockInfo == null)
                    {
                        return(Json(new BaseResModel <StockInfoResModel>()
                        {
                            Code = ResponseCodeEnum.DataNotFound
                        }, JsonRequestBehavior.AllowGet));
                    }

                    result.Result = StockInfo;

                    if (AuthStatus == 0)
                    {
                        result.Result.CurrFromEPS               = null;
                        result.Result.FutureFromEPS             = null;
                        result.Result.PrevDiviFrom3YearAvgByEPS = null;
                        result.Result.EstimateStableDivi        = null;
                        result.Result.EstimateUnstableDivi      = null;
                        result.Result.EstimateStablePrice5      = null;
                        result.Result.EstimateUnstablePrice5    = null;
                        result.Result.EstimateStablePrice7      = null;
                        result.Result.EstimateUnstablePrice7    = null;
                        result.Result.EstimateStablePrice10     = null;
                        result.Result.EstimateUnstablePrice10   = null;
                    }
                }
            }
            catch (Exception e)
            {
                result.Code    = ResponseCodeEnum.Failed;
                result.Message = e.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        /// <summary>
        /// 取得股票資訊
        /// </summary>
        /// <returns></returns>
        public ActionResult GetNum()
        {
            var result = new BaseResModel <Object>();

            try
            {
                if (AuthServcies.IsOverQuery(Request))
                {
                    throw new Exception("查詢過於繁複,請稍候再試!");
                }

                MemberInfoModel MemberInfo = null;
                String          LindId     = "";
                try
                {
                    // Request.Cookies["_UserInfo"].Value
                    MemberInfo = AuthServcies.GetHeaderToMemberInfo(Request);
                    //JsonConvert.DeserializeObject<MemberInfoModel>(Request.Headers["_UserInfo"].ToGetValue<string>());
                    LindId = MemberInfo.LineId;
                }
                catch (Exception ex)
                {
                    MemberInfo = null;
                    LindId     = "";
                }

                if (String.IsNullOrEmpty(LindId))
                {
                    throw new Exception("此功能需登錄Line");
                }

                using (var conn = new LiteDatabase(LazySlotDBPath))
                {
                    var    db    = conn.GetCollection <MemberQueryRecordModel>("MemberQueryRecord");
                    String Index = DateTime.Now.ToString("yyyyMMdd") + LindId;
                    var    item  = db.FindById(Index);
                    if (item != null)
                    {
                        throw new Exception("咳~咳~今天累了~明天請早~");
                    }

                    db.Insert(Index, new MemberQueryRecordModel()
                    {
                        Index = Index
                    });
                }

                using (var conn = new LiteDatabase(LazySlotDBPath))
                {
                    // Get customer collection
                    var db    = conn.GetCollection <HighQualityResModel>("HighQualityStock");
                    int index = new Random().Next(0, db.Count());
                    var item  = db.FindAll().Select(x => new
                    {
                        x.StockNum,
                        x.StockName
                    }).ToList()[index];

                    result.Result = new
                    {
                        item.StockNum,
                        item.StockName
                    };
                }
                result.Code = ResponseCodeEnum.Success;
            }
            catch (Exception e)
            {
                result.Code    = ResponseCodeEnum.Failed;
                result.Message = e.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }