public async Task PublishUserDeal(MarketDeal deal) { if (deal != null) { string userId = this.GetUserId(); if (!string.IsNullOrEmpty(userId)) { string oldDealId = deal.DealId; if (!deal.IsActive) { deal.DealId = (string)null; } string json = await Task.Factory.StartNew <string>((Func <string>)(() => JsonConvert.SerializeObject((object)deal))); byte[] key = DataKey.GetCurrentKey(); byte[] data = await Task.Factory.StartNew <byte[]>((Func <byte[]>)(() => new SimpleAES(key).Encrypt(json))); string dealId = await this.PostWebString(new Uri("http://berlox.com/finance/api?action=publishuserdeal&uid=" + userId + "&x=" + this.GetSecurityToken() + DataContext.UrlRnd()), data); if (!string.IsNullOrEmpty(dealId) && dealId.Length == 32) { deal.DealId = dealId; deal.Timestamp = DateTime.Now; List <MarketDeal> mydeals = await this.GetMyDealsAsync(); if (!string.IsNullOrEmpty(oldDealId)) { mydeals.RemoveAll((Predicate <MarketDeal>)(d => d.DealId == oldDealId)); } mydeals.RemoveAll((Predicate <MarketDeal>)(d => d.DealId == dealId)); mydeals.Add(deal); await this.SaveMyDealsAsync(mydeals); } } } }
public async Task RemoveUserDeal(MarketDeal deal) { if (deal != null && !string.IsNullOrEmpty(deal.DealId)) { string userId = this.GetUserId(); if (!string.IsNullOrEmpty(userId)) { if (deal.IsActive) { string result = await this.PostWebString(new Uri("http://berlox.com/finance/api?action=removeuserdeal&dealid=" + DataContext.UriEncode(deal.DealId) + "&uid=" + userId + "&x=" + this.GetSecurityToken() + DataContext.UrlRnd()), (byte[])null); if (result != "OK") { goto label_8; } } List <MarketDeal> mydeals = await this.GetMyDealsAsync(); mydeals.RemoveAll((Predicate <MarketDeal>)(d => d.DealId == deal.DealId)); await this.SaveMyDealsAsync(mydeals); } } label_8 :; }
private async Task writetoDb(DateTime updateTime, MarketType market, string strVal) { string val = ""; float mulfactor = 1.0f; if (strVal.Contains("万")) { val = strVal.Replace("万", ""); mulfactor = 0.01f; //数据库中存储的是数据单位是百万。 } else if (strVal.Contains("亿")) { val = strVal.Replace("亿", ""); mulfactor = 100f; //数据库中存储的是数据单位是百万。 } var tempFloat = Utility.convertToFloat(val); if (tempFloat == null) { throw new Exception("东方财富 深沪港通数据解析错误!"); } using (var db = new StockContext()) { var query = from i in db.MarketDeal where i.MarketType == market && i.Date == updateTime orderby i.Date descending select i; var itemIndb = await query.FirstOrDefaultAsync(); if (itemIndb == null) { //数据库中没有相应的数据,需要求加到数据库中 var newItem = new MarketDeal() { MarketType = market, Date = updateTime, DRZJLR = tempFloat.Value * mulfactor, Permanent = false, }; db.MarketDeal.Add(newItem); } else { if (itemIndb.Permanent == true) { //数据库中已存在,且数据为永久数据 //直接退出。 return; } else { itemIndb.DRZJLR = tempFloat.Value * mulfactor; } } await db.SaveChangesAsync(); } }