예제 #1
0
        public Fund SaveFund(Fund fund)
        {
            if (fund == null)
            {
                return(null);
            }

            /*
             *          if (fund.MonthlyPerformanceList != null)
             *              fund.MonthlyPerformanceAsString = JsonConvert.SerializeObject(fund.MonthlyPerformanceList);
             *
             *          fund.VolatilityArrayAsString = (fund.VolatilityArray != null) ? string.Join(";", fund.VolatilityArray) : "";
             *          fund.SharpRateArrayAsString = (fund.SharpRateArray != null) ? string.Join(";", fund.SharpRateArray) : "";
             *          fund.BestMonthArrayAsString = (fund.BestMonthArray != null) ? string.Join(";", fund.BestMonthArray) : "";
             *          fund.WorstMonthArrayAsString = (fund.WorstMonthArray != null) ? string.Join(";", fund.WorstMonthArray) : "";
             *          fund.MaxLossArrayAsString = (fund.MaxLossArray != null) ? string.Join(";", fund.MaxLossArray) : "";
             *          fund.OverFulFilmentArrayAsString = (fund.OverFulFilmentArray != null) ? string.Join(";", fund.VolatilityArray) : "";
             */
            fund.FillStringProperties();

            IEnumerable <Fund> fundList = GetFundList();

            if (fundList != null)
            {
                fundList.Append(fund);
            }

            SaveFundList(fundList.ToList());

            return(fund);
        }
예제 #2
0
        public IEnumerable <Fund> SaveFundList(List <Fund> fundList)
        {
            if (fundList == null)
            {
                return(null);
            }

            List <Fund> dbFundList = GetFundList().ToList();

            List <string> isinNumberList = dbFundList.Select(b => b.ISINNumber).ToList();

            for (int i = 0; i < fundList.Count; i++)
            {
                Fund fund = fundList[i];

                if (fund == null)
                {
                    continue;
                }

                /*
                 *              if (fund.MonthlyPerformanceList != null)
                 *                  fund.MonthlyPerformanceAsString = JsonConvert.SerializeObject(fund.MonthlyPerformanceList);
                 *
                 *              fund.VolatilityArrayAsString = (fund.VolatilityArray != null) ? string.Join(";", fund.VolatilityArray) : "";
                 *              fund.SharpRateArrayAsString = (fund.SharpRateArray != null) ? string.Join(";", fund.SharpRateArray) : "";
                 *              fund.BestMonthArrayAsString = (fund.BestMonthArray != null) ? string.Join(";", fund.BestMonthArray) : "";
                 *              fund.WorstMonthArrayAsString = (fund.WorstMonthArray != null) ? string.Join(";", fund.WorstMonthArray) : "";
                 *              fund.MaxLossArrayAsString = (fund.MaxLossArray != null) ? string.Join(";", fund.MaxLossArray) : "";
                 *              fund.OverFulFilmentArrayAsString = (fund.OverFulFilmentArray != null) ? string.Join(";", fund.VolatilityArray) : "";
                 */

                fund.FillStringProperties();

                if (!isinNumberList.Contains(fund.ISINNumber))
                {
                    dbFundList.Add(fund);
                    isinNumberList.Add(fund.ISINNumber);
                }
                else
                {
                    Fund actFund = dbFundList.Where(b => b.ISINNumber == fund.ISINNumber).FirstOrDefault();
                    if (actFund != null)
                    {
                        fund = actFund;
                    }
                }
            }

            if (!Directory.Exists(_contentDirectoryPath))
            {
                Directory.CreateDirectory(_contentDirectoryPath);
            }

            File.WriteAllText(_fundTargetFilePath, JsonConvert.SerializeObject(fundList));

            return(GetFundList());
        }