public static IList<Coin> GetCoinData() { CoinType coinType1 = new CoinType(); coinType1.Id = 1; coinType1.Name = "cointype_name"; CoinLevel coinLevel1 = new CoinLevel(); coinLevel1.Id = 1; coinLevel1.Name = "coinlevel_name"; IList<Coin> coins = new List<Coin>(); Coin coin1 = new Coin(); coin1.Id = Guid.NewGuid(); coin1.Name = "coin1_name"; coin1.Description = "coin1_description"; coin1.AppraisalInstitute = "coin1_appraisalInstitute"; coin1.AppraisalScore = "75"; coin1.Memo = "coin1_memo"; coin1.Image = "coin1_image"; //coin1.CoinType = coinType1; //coin1.CoinLevel = coinLevel1; coins.Add(coin1); return coins; }
public static Guid CreateCoin(Coin coin) { coin.Id = coin.Id == null || coin.Id == Guid.Empty ? Guid.NewGuid() : coin.Id; coin.CreateDate = coin.ModifyDate = DateTime.Now; using (Entities ctx = new Entities()) { ctx.Coins.AddObject(coin); ctx.SaveChanges(); } return coin.Id; }
internal static Guid SplitCoinHistory(Guid Id) { using (Entities ctx = new Entities()) { var coinHistory = ctx.CoinDealHistories.SingleOrDefault(x => x.Id == Id); if (coinHistory != null) { var oldCoin = ctx.Coins.SingleOrDefault(x => x.Id == coinHistory.CoinId); if (oldCoin != null) { Coin newCoin = new Coin(); newCoin.Id = Guid.NewGuid(); newCoin.Image = oldCoin.Image; newCoin.Memo = oldCoin.Memo; newCoin.ModifyDate = DateTime.Now; newCoin.Name = oldCoin.Name; newCoin.PCGSNo = oldCoin.PCGSNo; newCoin.AppraisalInstitute = oldCoin.AppraisalInstitute; newCoin.AppraisalScore = oldCoin.AppraisalScore; newCoin.CoinLevelId = oldCoin.CoinLevelId; newCoin.CoinTypeId = oldCoin.CoinTypeId; newCoin.CreateDate = oldCoin.CreateDate; newCoin.Description = oldCoin.Description; ctx.Coins.AddObject(newCoin); // 保存以前的货币ID,用于下面的代码 var oldCoinId = coinHistory.CoinId; coinHistory.CoinId = newCoin.Id; coinHistory.ModifyDate = DateTime.Now; var coinRealtime = ctx.CoinDealRealtimes.SingleOrDefault(x => x.Id == Id); if (coinRealtime != null) { coinRealtime.CoinId = newCoin.Id; coinRealtime.ModifyDate = DateTime.Now; // 由于Realtime记录被移走,故需要重新添加最后的拍卖纪录从历史库中 var lastCoinDealHistory = (from p in ctx.CoinDealHistories where p.CoinId == oldCoinId && p.Id != Id orderby p.CreateDate descending select p).FirstOrDefault(); if (lastCoinDealHistory != null) { var newCoinDealRealtime = new CoinDealRealtime(); newCoinDealRealtime.Id = lastCoinDealHistory.Id; newCoinDealRealtime.Image1 = lastCoinDealHistory.Image1; newCoinDealRealtime.Image2 = lastCoinDealHistory.Image2; newCoinDealRealtime.Image3 = lastCoinDealHistory.Image3; newCoinDealRealtime.Image4 = lastCoinDealHistory.Image4; newCoinDealRealtime.ModifyDate = lastCoinDealHistory.ModifyDate; newCoinDealRealtime.CoinId = lastCoinDealHistory.CoinId; newCoinDealRealtime.CreateDate = lastCoinDealHistory.CreateDate; newCoinDealRealtime.DealCompany = lastCoinDealHistory.DealCompany; newCoinDealRealtime.DealDate = lastCoinDealHistory.DealDate; newCoinDealRealtime.DealPrice = lastCoinDealHistory.DealPrice; newCoinDealRealtime.DealPriceUSD = lastCoinDealHistory.DealPriceUSD; newCoinDealRealtime.Description = lastCoinDealHistory.Description; newCoinDealRealtime.Lot = lastCoinDealHistory.Lot; ctx.CoinDealRealtimes.AddObject(newCoinDealRealtime); } } else { // 创建新的拍卖实时记录 CoinDealRealtime coinDealRealtime = new CoinDealRealtime(); coinDealRealtime.Id = coinHistory.Id; coinDealRealtime.Image1 = coinHistory.Image1; coinDealRealtime.Image2 = coinHistory.Image2; coinDealRealtime.Image3 = coinHistory.Image3; coinDealRealtime.Image4 = coinHistory.Image4; coinDealRealtime.ModifyDate = coinHistory.ModifyDate; coinDealRealtime.CoinId = coinHistory.CoinId; coinDealRealtime.CreateDate = coinHistory.CreateDate; coinDealRealtime.DealCompany = coinHistory.DealCompany; coinDealRealtime.DealDate = coinHistory.DealDate; coinDealRealtime.DealPrice = coinHistory.DealPrice; coinDealRealtime.DealPriceUSD = coinHistory.DealPriceUSD; coinDealRealtime.Description = coinHistory.Description; coinDealRealtime.Lot = coinHistory.Lot; ctx.CoinDealRealtimes.AddObject(coinDealRealtime); } ctx.SaveChanges(); return newCoin.Id; } } } return Guid.Empty; }
internal static int ModifyCoin(Coin coinModel) { using (Entities ctx = new Entities()) { var coin = ctx.Coins.SingleOrDefault(x => x.Id == coinModel.Id); if (coin != null) { coin.Name = coinModel.Name; coin.AppraisalInstitute = coinModel.AppraisalInstitute; coin.AppraisalScore = coinModel.AppraisalScore; coin.CoinLevelId = coinModel.CoinLevelId; coin.PCGSNo = coinModel.PCGSNo; coin.ModifyDate = DateTime.Now; return ctx.SaveChanges(); } } return 0; }
internal static CoinDealHistory GetLastCoinDealHistory(Coin coin) { using (Entities ctx = new Entities()) { var coinDealHistory = (from p in ctx.CoinDealHistories where p.CoinId == coin.Id orderby p.DealDate descending select p).FirstOrDefault(); return coinDealHistory; } }
internal static IList<CoinDealHistory> GetCoinDealHistories(Coin coin) { using (Entities ctx = new Entities()) { var coinDealHistories = (from p in ctx.CoinDealHistories where p.CoinId == coin.Id orderby p.DealDate ascending select p).ToList(); return coinDealHistories; } }
/// <summary> /// Create a new Coin object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="description">Initial value of the Description property.</param> /// <param name="coinTypeId">Initial value of the CoinTypeId property.</param> /// <param name="image">Initial value of the Image property.</param> /// <param name="createDate">Initial value of the CreateDate property.</param> /// <param name="modifyDate">Initial value of the ModifyDate property.</param> public static Coin CreateCoin(global::System.Guid id, global::System.String name, global::System.String description, global::System.Int32 coinTypeId, global::System.String image, global::System.DateTime createDate, global::System.DateTime modifyDate) { Coin coin = new Coin(); coin.Id = id; coin.Name = name; coin.Description = description; coin.CoinTypeId = coinTypeId; coin.Image = image; coin.CreateDate = createDate; coin.ModifyDate = modifyDate; return coin; }
/// <summary> /// Deprecated Method for adding a new object to the Coins EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCoins(Coin coin) { base.AddObject("Coins", coin); }
public ActionResult Edit(Coin coin) { CoinManager.ModifyCoin(coin); return RedirectToAction("Details", new { id = coin.Id }); }
public ActionResult Create(Coin coin, CoinDealHistory coinDealHistory, HttpPostedFileBase imageFile1, HttpPostedFileBase imageFile2, HttpPostedFileBase imageFile3, HttpPostedFileBase imageFile4, string rate) { try { if (!String.IsNullOrEmpty(rate)) { HttpCookie myCookie = new HttpCookie("FYCoins"); myCookie["RateUSD"] = rate; myCookie["DealDate"] = coinDealHistory.DealDate.ToString("yyyy-MM-dd"); myCookie["DealCompany"] = coinDealHistory.DealCompany; myCookie.Expires = DateTime.Now.AddDays(365d); Response.Cookies.Add(myCookie); } coin.Id = Guid.NewGuid(); coin.CoinTypeId = 1; coin.Image = String.Empty; if (String.IsNullOrEmpty(coin.Description)) coin.Description = String.Empty; CoinManager.CreateCoin(coin); if (!String.IsNullOrWhiteSpace(coinDealHistory.DealCompany)) { coinDealHistory.CoinId = coin.Id; coinDealHistory.Image1 = saveDealImage(imageFile1); coinDealHistory.Image2 = saveDealImage(imageFile2); coinDealHistory.Image3 = saveDealImage(imageFile3); coinDealHistory.Image4 = saveDealImage(imageFile4); CoinManager.CreateCoinDealHistory(coinDealHistory); } return RedirectToAction("Create", new { result = "保存成功" }); //return RedirectToAction("Index"); } catch (Exception e) { return RedirectToAction("Create", new { result = "保存失败:" + e.Message }); } }