Exemple #1
0
        public async Task <ActionResult> SelectBrochureTemp(string OptionsProductID, string BrochureID)
        {
            try
            {
                if (!string.IsNullOrEmpty(OptionsProductID) && !string.IsNullOrEmpty(BrochureID))
                {
                    Guid     bid  = new Guid(BrochureID);
                    Guid     opid = new Guid(OptionsProductID);
                    Brochure find = await BrochureRepository.FindAsync(b => b.BrochureID == bid);

                    find.IsTemp           = false;
                    find.AddDate          = DateTime.Now.ToLocalTime();
                    find.OptionsProductID = opid;
                    find.BrochureID       = new Brochure().BrochureID;
                    Brochure addBro = BrochureRepository.Add(find);
                    if (addBro != null)
                    {
                        bool IsExist = await BrochureRepository.ExistAsync(b => b.OptionsProductID == opid && b.BrochureID != addBro.BrochureID);

                        if (IsExist)
                        {
                            Brochure x = await BrochureRepository.FindAsync(b => b.OptionsProductID == opid && b.BrochureID != addBro.BrochureID);

                            //删除原有的正式宣传册
                            BrochureRepository.Delete(x);
                        }
                        //更新产品说明链接
                        string         BrochureURL = ConfigurationManager.AppSettings["BrochureURL"].ToString() + opid.ToString();
                        OptionsProduct findop      = await OptionsProductRepository.FindAsync(op => op.OptionsProductID == opid);

                        findop.ProductUrl = BrochureURL;
                        OptionsProductRepository.Update(findop);
                        LogRepository.Add(new EventLog()
                        {
                            Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "选择宣传册模板作为正式宣传册成功"
                        });
                        return(Json(new
                        {
                            Success = true
                        }));
                    }
                }
                return(Json(new
                {
                    Success = false
                }));
            }
            catch (Exception ex)
            {
                LogRepository.Add(new EventLog()
                {
                    Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "选择宣传册模板作为正式宣传册失败" + ex.Message
                });
                return(Json(new
                {
                    Success = false
                }));
            }
        }
        /// <summary>
        /// 补偿示例
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult> Example(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                Guid OPID = new Guid(id);
                Entities.Brochure findbr = await BrochureRepository.FindAsync(b => b.OptionsProductID == OPID);

                OptionsProduct findop = await OptionsProductRepository.FindAsync(op => op.OptionsProductID == OPID);

                if (findbr != null && findop != null)
                {
                    BrochureViewModel bvm = new BrochureViewModel();
                    bvm.AmountType      = findop.AmountType;
                    bvm.BrochureID      = findbr.BrochureID;
                    bvm.BuyBegin        = findbr.BuyBegin;
                    bvm.BuyTime         = findbr.BuyTime;
                    bvm.Contract        = findop.Contract;
                    bvm.ContractDescrip = findbr.ContractDescrip;
                    bvm.Deadline        = findop.Deadline;
                    bvm.EndDateDescrip  = findbr.EndDateDescrip;
                    bvm.ExampleDescrip  = findbr.ExampleDescrip;
                    //bvm.ExamplePic = findbr.ExamplePic;
                    bvm.FAQ = findbr.FAQ;
                    bvm.OptionsProductID     = OPID;
                    bvm.PayDescrip           = findbr.PayDescrip;
                    bvm.Price                = findop.Price;
                    bvm.PriceType            = findop.PriceType;
                    bvm.ProductName          = findop.ProductName;
                    bvm.PurchaseAgreementURL = findbr.PurchaseAgreementURL;
                    bvm.RiskAnnouncementURL  = findbr.RiskAnnouncementURL;
                    bvm.SettlementFormula    = findbr.SettlementFormula;
                    //bvm.SFPic = findbr.SFPic;
                    bvm.StartDateDescrip = findbr.StartDateDescrip;
                    bvm.TradeDateDescrip = findbr.TradeDateDescrip;
                    return(View(bvm));
                }
            }
            return(View(new BrochureViewModel()));
        }
        /// <summary>
        /// 联创获取到期日期
        /// 异步操作
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> PostDates(HttpRequestMessage request)
        {
            try
            {
                string loginjson = request.Content.ReadAsStringAsync().Result;
                if (!string.IsNullOrEmpty(loginjson))
                {
                    //return await GetResult(json);
                    return(await Task.Run(async() =>
                    {
                        RequestDateModel json = JsonConvert.DeserializeObject <RequestDateModel>(DESEncrypt.DesDecrypt(loginjson));
                        ReturnDateModel rdm = new ReturnDateModel();
                        string keyTime = ConfigurationManager.AppSettings["KeyTime"];
                        List <Dates> date = new List <Dates>();
                        foreach (RequestDate item in json.datas)
                        {
                            Guid id = new Guid(item.optionsProductId);
                            OptionsProduct op = await OptionsProductRepository.FindAsync(p => p.OptionsProductID == id);
                            int Deadline = op.Deadline;
                            string TradeDate = item.tradeDate;
                            string BeginDate = string.Empty;
                            //如果时间在14:30之前成交的
                            if (DateTime.Compare(Convert.ToDateTime(TradeDate), Convert.ToDateTime(Convert.ToDateTime(TradeDate).ToString("yyyy-MM-dd") + " " + keyTime)) <= 0)
                            {
                                string STradeDate = Convert.ToDateTime(TradeDate).ToString("yyyy-MM-dd");
                                while (true)
                                {
                                    Tday dd = await TdaysRepository.FindAsync(t => t.Tdays == STradeDate);
                                    if (dd == null)//没有查询到对应交易日,说明不是交易日,向后推一天
                                    {
                                        STradeDate = Convert.ToDateTime(STradeDate).AddDays(1).ToString("yyyy-MM-dd");
                                    }
                                    else//是交易日,设置开始时间
                                    {
                                        BeginDate = STradeDate;
                                        break;
                                    }
                                }
                            }//如果是在14:30之后成交的
                            else
                            {
                                string STradeDate = Convert.ToDateTime(TradeDate).AddDays(1).ToString("yyyy-MM-dd");
                                while (true)
                                {
                                    Tday dd = await TdaysRepository.FindAsync(t => t.Tdays == STradeDate);
                                    if (dd == null)//没有查询到对应交易日,说明不是交易日,向后推一天
                                    {
                                        STradeDate = Convert.ToDateTime(STradeDate).AddDays(1).ToString("yyyy-MM-dd");
                                    }
                                    else//是交易日,设置开始时间
                                    {
                                        BeginDate = STradeDate;
                                        break;
                                    }
                                }
                            }
                            string EndDate = string.Empty;
                            string TryEndDate = Convert.ToDateTime(BeginDate).AddDays(Deadline).ToString("yyyy-MM-dd");
                            while (true)
                            {
                                Tday dd = await TdaysRepository.FindAsync(t => t.Tdays == TryEndDate);
                                if (dd == null)//没有查询到对应交易日,说明不是交易日,向前推一天
                                {
                                    TryEndDate = Convert.ToDateTime(TryEndDate).AddDays(-1).ToString("yyyy-MM-dd");
                                }
                                else//是交易日,设置到期时间
                                {
                                    EndDate = TryEndDate;
                                    break;
                                }
                            }
                            if (!string.IsNullOrEmpty(BeginDate) && !string.IsNullOrEmpty(EndDate))
                            {
                                date.Add(new Dates {
                                    startDate = BeginDate, endDate = EndDate
                                });
                            }
                            else
                            {
                                throw new Exception("开始日期或结束日期为空。请检查数据。");
                            }
                        }


                        //testdate.Add(new Dates { startDate = DateTime.Now.ToString("yyyy-MM-dd"), endDate = DateTime.Now.ToString("yyyy-MM-dd") });
                        //rdm.datas = testdate;
                        rdm.datas = date;
                        rdm.Result = "1";
                        string str = DESEncrypt.DesEncrypt(JsonConvert.SerializeObject(rdm));
                        HttpResponseMessage result = new HttpResponseMessage {
                            Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json")
                        };
                        return result;
                    }));
                }
                else
                {
                    string str = DESEncrypt.DesEncrypt("{\"result\":\"0\",\"message\":\"传送过来的json为空\"}");
                    HttpResponseMessage result = new HttpResponseMessage {
                        Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json")
                    };
                    return(result);
                }
            }
            catch (Exception ex)
            {
                string str = DESEncrypt.DesEncrypt("{\"result\":\"0\",\"message\":\"" + ex.Message + "\"}");
                HttpResponseMessage result = new HttpResponseMessage {
                    Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json")
                };
                LogRepository.Add(new EventLog()
                {
                    Name = "第三方", Date = DateTime.Now.ToLocalTime(), Event = "获取到期日期失败" + ex.Message
                });
                return(result);
            }
        }