示例#1
0
 public static Product GetProduct(Guid id)
 {
     using (Entities ctx = new Entities())
     {
         return ctx.Products.SingleOrDefault(p => p.Id == id);
     }
 }
示例#2
0
 public static CoinDealHistory GetCoinDealHistory(Guid Id)
 {
     using (Entities ctx = new Entities())
     {
         return ctx.CoinDealHistories.SingleOrDefault(x => x.Id == Id);
     }
 }
示例#3
0
 public static Coin GetCoin(Guid id)
 {
     using (Entities ctx = new Entities())
     {
         return ctx.Coins.SingleOrDefault(x=>x.Id == id);
     }
 }
示例#4
0
        public static string CreateOrder(OrderModel orderModel)
        {
            var order = new Order();
            order.Id = Guid.NewGuid();
            order.Total = orderModel.Total;

            foreach (var orderItemModel in orderModel.OrderItems)
            {
                order.OrderItems.Add(OrderItem.CreateOrderItem(
                    Guid.NewGuid(), orderItemModel.Item.Id, orderItemModel.Quantity, order.Id
                ));
            }

            using (Entities ctx = new Entities())
            {
                var orderType =
                    Convert.ToInt16(ConfigurationManager.AppSettings["ENTITY_ORDER_TYPE"]);
                var orderCounter =
                    ctx.EntityNumberCounters.SingleOrDefault(
                    p => p.EntityType == orderType);

                order.RefNumber = (orderCounter.Counter + 1).ToString();
                ctx.Orders.AddObject(order);

                orderCounter.Counter++;
                ctx.SaveChanges();
            }

            return order.RefNumber;
        }
示例#5
0
 public static void CreateProduct(Product product)
 {
     using (Entities ctx = new Entities())
     {
         ctx.Products.AddObject(product);
         ctx.SaveChanges();
     }
 }
示例#6
0
 public static void DeleteProduct(Guid id)
 {
     using (Entities ctx = new Entities())
     {
         ctx.Products.DeleteObject
             (ctx.Products.SingleOrDefault(p => p.Id == id));
         ctx.SaveChanges();
     }
 }
示例#7
0
        public static IList<PCGSMSPR6070> GetPCGSS()
        {
            using (Entities ctx = new Entities())
            {
                var pcgss = (from x in ctx.PCGSMSPR6070 select x).ToList();

                return pcgss;
            }
        }
示例#8
0
        public static IList<Product> GetProducts()
        {
            IList<Product> products = new List<Product>();
            using (Entities ctx = new Entities())
            {
                if (ctx.Products != null)
                    products = ctx.Products.ToList();
            }

            return products;
        }
示例#9
0
        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;
        }
示例#10
0
        public static IList<ProductModel> GetHottestProducts()
        {
            using (Entities ctx = new Entities())
            {
                var hottestProducts =
                    (from x in
                        (from o in ctx.OrderItems
                        group o by o.ProductId into p
                        select new { Id = p.Key, SoldCount = p.Sum(o => o.Quantity) })
                    orderby x.SoldCount descending
                    select x).ToList();

                if (hottestProducts != null)
                {
                    var products = new List<ProductModel>();
                    var count = 0;

                    foreach (var hottestProduct in hottestProducts)
                    {
                        var product =
                            (ctx.Products.SingleOrDefault
                                (p => p.Id == hottestProduct.Id));

                        products.Add(new ProductModel(product,
                            hottestProduct.SoldCount));
                        count++;

                        // TODO: improve the magic number in future.
                        if (count >= 5)
                            break;
                    }

                    return products;
                }
                else
                    return null;
            }
        }
示例#11
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;
            }
        }
示例#12
0
        internal static View_CoinWithLastDealHistory GetCoinWithLastCoinDealHistory(Guid coinId)
        {
            using (Entities ctx = new Entities())
            {
                var coinWithLastCoinDealHistory = (from p in ctx.View_CoinWithLastDealHistory
                                       where p.Id == coinId
                                       select p).FirstOrDefault();

                return coinWithLastCoinDealHistory;
            }
        }
示例#13
0
        internal static IList<ProductModel> GetRecommendProducts()
        {
            using (Entities ctx = new Entities())
            {
                var recommendProducts = (from o in ctx.Products
                                         where o.Recommendation == true
                                         select o).ToList();

                if (recommendProducts != null)
                {
                    var products = new List<ProductModel>();

                    foreach (var recommendProduct in recommendProducts)
                    {
                        products.Add(new ProductModel(recommendProduct));
                    }

                    return products;
                }
                else
                    return null;
            }
        }
示例#14
0
 internal static IList<Coin> GetCoins()
 {
     using (Entities ctx = new Entities())
     {
         return ctx.Coins.ToList();
     }
 }
示例#15
0
        internal static CoinLevel GetCoinLevel(int coinLevelId)
        {
            using (Entities ctx = new Entities())
            {
                var coinLevel = (from p in ctx.CoinLevels
                                 where p.Id == coinLevelId
                                 select p).SingleOrDefault();

                return coinLevel;
            }
        }
示例#16
0
        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;
            }
        }
示例#17
0
        internal static int DeleteCoinDealHistory(Guid Id)
        {
            using (Entities ctx = new Entities())
            {
                var coinDealHistory = ctx.CoinDealHistories.SingleOrDefault(x => x.Id == Id);
                if (coinDealHistory != null)
                    ctx.CoinDealHistories.DeleteObject(coinDealHistory);

                var coinDealRealtime = ctx.CoinDealRealtimes.SingleOrDefault(x => x.Id == Id);
                if (coinDealRealtime != null)
                {
                    ctx.CoinDealRealtimes.DeleteObject(coinDealRealtime);
                    // 由于Realtime记录被删除,故需要重新添加最后的拍卖纪录从历史库中
                    var lastCoinDealHistory = (from p in ctx.CoinDealHistories
                                               where p.CoinId == coinDealHistory.CoinId
                                                    && 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);
                    }
                }

                return ctx.SaveChanges();
            }
        }
示例#18
0
        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;
        }
示例#19
0
        public static int ImportPCGSMSPR6070()
        {
            HtmlWeb webClient = new HtmlWeb();
            HtmlAgilityPack.HtmlDocument doc =
                webClient.Load("http://www.pcgs.com/pop/detail.aspx?c=4207&t=3");

            IList<PCGSMSPR6070> pcgss = new List<PCGSMSPR6070>();

            foreach (var tr in doc.DocumentNode.SelectNodes("//tr"))
            {
                HtmlAgilityPack.HtmlDocument trDoc = new HtmlAgilityPack.HtmlDocument();
                trDoc.LoadHtml(tr.InnerHtml);

                var tds = trDoc.DocumentNode.SelectNodes("//td");
                if (tds != null)
                {
                    PCGSMSPR6070 pcgs = new PCGSMSPR6070();
                    pcgs.Id = Guid.NewGuid();

                    for (int i = 0; i < tds.Count; i++)
                    {
                        switch (i)
                        {
                            case 0:
                                pcgs.PCGSNo = tds[i].InnerText.Trim();
                                break;
                            case 1:
                                pcgs.Description = tds[i].InnerText.
                                    Replace("Shop", "").Replace("\n", "").Trim();
                                break;
                            case 2:
                                pcgs.Desig = tds[i].InnerText.Replace("\n", "").Trim();
                                break;
                            case 3:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S60 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 4:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S61 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 5:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S62 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 6:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S63 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 7:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S64 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 8:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S65 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 9:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S66 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 10:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S67 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 11:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S68 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 12:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S69 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 13:
                                {
                                    var score = Regex.Split(tds[i].InnerHtml, "<br>");
                                    foreach (var s in score)
                                        pcgs.S70 += s.Replace("\n", "").Replace("&nbsp;", "").Trim() + " ";
                                }
                                break;
                            case 14:
                                pcgs.Total = tds[i].InnerText.Replace("\n", "").Replace("&nbsp;", "").Trim();
                                break;
                        }
                    }

                    if (!pcgs.PCGSNo.ToLower().Contains("total"))
                        pcgss.Add(pcgs);
                }
            }

            using (Entities ctx = new Entities())
            {
                foreach (var pcgs in pcgss)
                {
                    ctx.PCGSMSPR6070.AddObject(pcgs);
                }

                ctx.SaveChanges();
            }

            return pcgss.Count;
        }
示例#20
0
        internal static void MergeCoins(string coins)
        {
            using (Entities ctx = new Entities())
            {
                Guid firstCoinId = Guid.NewGuid();
                // 将历史拍卖记录转移到第一个钱币
                for (int i = 0; i < coins.Split(',').Length; i++)
                {
                    Guid coinId = Guid.Parse(coins.Split(',')[i]);
                    if (i == 0)
                        firstCoinId = coinId;

                    var coinHistories = (from p in ctx.CoinDealHistories
                            where p.CoinId == coinId
                            select p).ToList();
                    foreach (var coinHistory in coinHistories)
                        coinHistory.CoinId = firstCoinId;

                    ctx.SaveChanges();
                }

                // 删除除了第一个之外的所有钱币
                for (int i = 1; i < coins.Split(',').Length; i++)
                {
                    Guid coinId = Guid.Parse(coins.Split(',')[i]);

                    var coin = ctx.Coins.SingleOrDefault(x => x.Id == coinId);
                    if (coin != null)
                        ctx.Coins.DeleteObject(coin);
                }
                ctx.SaveChanges();
            }
        }
示例#21
0
        public static int GetCount(MarketSearchBoxModel marketSearchBox)
        {
            using (Entities ctx = new Entities())
            {
                var whereClause = PredicateBuilder.False<Coin>();
                if (marketSearchBox.AppraisalInstitute_PCGS)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("PCGS"));
                if (marketSearchBox.AppraisalInstitute_NGC)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("NGC"));
                if (marketSearchBox.AppraisalInstitute_ANA)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("ANA"));

                if (!marketSearchBox.AppraisalInstitute_PCGS &&
                    !marketSearchBox.AppraisalInstitute_NGC &&
                    !marketSearchBox.AppraisalInstitute_ANA)
                    whereClause = whereClause.Or(x => 1 == 1);

                if (marketSearchBox.CoinLevelId != 0)
                    whereClause = whereClause.And(x => x.CoinLevelId == marketSearchBox.CoinLevelId);

                if (!String.IsNullOrWhiteSpace(marketSearchBox.AppraisalScore))
                    whereClause = whereClause.And
                        (x => x.AppraisalScore == marketSearchBox.AppraisalScore.Trim());

                var nameWhereClause = PredicateBuilder.False<Coin>();
                if (!String.IsNullOrWhiteSpace(marketSearchBox.Description))
                {
                    nameWhereClause = nameWhereClause.Or
                        (x => x.Name.Contains(marketSearchBox.Description.Trim()));
                    nameWhereClause = nameWhereClause.Or
                        (x => x.Description.Contains(marketSearchBox.Description.Trim()));
                    ctx.Coins.AsExpandable().Where(nameWhereClause);
                }
                else
                    nameWhereClause = nameWhereClause.Or(x => 1 == 1);

                return ctx.Coins.AsExpandable().Where(whereClause).Where(nameWhereClause).Count();
            }
        }
示例#22
0
        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;
        }
示例#23
0
        public static int RemoveAppraisal()
        {
            using (Entities ctx = new Entities())
            {
                var allCoins = ctx.Coins.ToList();
                foreach (var coin in allCoins)
                {
                    int spacePosition = coin.Name.LastIndexOf(' ');
                    var name = coin.Name.Remove(0, spacePosition + 1);
                    coin.Name = name;
                }

                return ctx.SaveChanges();
            }
        }
示例#24
0
        internal static int ModifyCoinHistory(CoinDealHistory coinDealHistory)
        {
            using (Entities ctx = new Entities())
            {
                var coinHistory = ctx.CoinDealHistories.SingleOrDefault(x => x.Id == coinDealHistory.Id);

                if (coinDealHistory != null)
                {
                    coinHistory.DealCompany = coinDealHistory.DealCompany;
                    coinHistory.DealDate = coinDealHistory.DealDate;
                    coinHistory.DealPrice = coinDealHistory.DealPrice;
                    coinHistory.DealPriceUSD = coinDealHistory.DealPriceUSD;
                    coinHistory.Description = coinDealHistory.Description;
                    coinHistory.Lot = coinDealHistory.Lot;
                    coinHistory.ModifyDate = DateTime.Now;
                    if (coinDealHistory.Image1 != String.Empty)
                        coinHistory.Image1 = coinDealHistory.Image1;
                    if (coinDealHistory.Image2 != String.Empty)
                        coinHistory.Image2 = coinDealHistory.Image2;
                    if (coinDealHistory.Image3 != String.Empty)
                        coinHistory.Image3 = coinDealHistory.Image3;
                    if (coinDealHistory.Image4 != String.Empty)
                        coinHistory.Image4 = coinDealHistory.Image4;
                }

                var coinRealtime = ctx.CoinDealRealtimes.SingleOrDefault(x => x.Id == coinDealHistory.Id);
                if (coinRealtime != null)
                {
                    coinRealtime.DealCompany = coinDealHistory.DealCompany;
                    coinRealtime.DealDate = coinDealHistory.DealDate;
                    coinRealtime.DealPrice = coinDealHistory.DealPrice;
                    coinRealtime.DealPriceUSD = coinDealHistory.DealPriceUSD;
                    coinRealtime.Description = coinDealHistory.Description;
                    coinRealtime.Lot = coinDealHistory.Lot;
                    coinRealtime.ModifyDate = DateTime.Now;
                    if (coinDealHistory.Image1 != String.Empty)
                        coinRealtime.Image1 = coinDealHistory.Image1;
                    if (coinDealHistory.Image2 != String.Empty)
                        coinRealtime.Image2 = coinDealHistory.Image2;
                    if (coinDealHistory.Image3 != String.Empty)
                        coinRealtime.Image3 = coinDealHistory.Image3;
                    if (coinDealHistory.Image4 != String.Empty)
                        coinRealtime.Image4 = coinDealHistory.Image4;
                }

                return ctx.SaveChanges();
            }
        }
示例#25
0
        internal static Guid CreateCoinDealHistory(CoinDealHistory coinDealHistory)
        {
            coinDealHistory.Id =
                coinDealHistory.Id == null || coinDealHistory.Id == Guid.Empty ?
                Guid.NewGuid() : coinDealHistory.Id;
            coinDealHistory.CreateDate = coinDealHistory.ModifyDate = DateTime.Now;

            using (Entities ctx = new Entities())
            {
                ctx.CoinDealHistories.AddObject(coinDealHistory);
                // 删除历史的拍卖纪录,保存表中只保留最新的一条拍卖纪录
                ctx.CoinDealRealtimes.Where(w => w.CoinId == coinDealHistory.CoinId)
                    .ToList().ForEach(ctx.CoinDealRealtimes.DeleteObject);
                // 创建新的拍卖实时记录
                CoinDealRealtime coinDealRealtime = new CoinDealRealtime();
                coinDealRealtime.Id = coinDealHistory.Id;
                coinDealRealtime.Image1 = coinDealHistory.Image1;
                coinDealRealtime.Image2 = coinDealHistory.Image2;
                coinDealRealtime.Image3 = coinDealHistory.Image3;
                coinDealRealtime.Image4 = coinDealHistory.Image4;
                coinDealRealtime.ModifyDate = coinDealHistory.ModifyDate;
                coinDealRealtime.CoinId = coinDealHistory.CoinId;
                coinDealRealtime.CreateDate = coinDealHistory.CreateDate;
                coinDealRealtime.DealCompany = coinDealHistory.DealCompany;
                coinDealRealtime.DealDate = coinDealHistory.DealDate;
                coinDealRealtime.DealPrice = coinDealHistory.DealPrice;
                coinDealRealtime.DealPriceUSD = coinDealHistory.DealPriceUSD;
                coinDealRealtime.Description = coinDealHistory.Description;
                coinDealRealtime.Lot = coinDealHistory.Lot;

                ctx.CoinDealRealtimes.AddObject(coinDealRealtime);

                ctx.SaveChanges();
            }

            return coinDealHistory.Id;
        }
示例#26
0
        public static IList<View_CoinWithLastDealHistory> GetCoinsByMarketSearch(MarketSearchBoxModel marketSearchBox, string sortingExpression, int pageIndex)
        {
            using (Entities ctx = new Entities())
            {
                var whereClause = PredicateBuilder.False<View_CoinWithLastDealHistory>();
                if (marketSearchBox.AppraisalInstitute_PCGS)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("PCGS"));
                if (marketSearchBox.AppraisalInstitute_NGC)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("NGC"));
                if (marketSearchBox.AppraisalInstitute_ANA)
                    whereClause = whereClause.Or(x => x.AppraisalInstitute.Contains("ANA"));

                if (!marketSearchBox.AppraisalInstitute_PCGS &&
                    !marketSearchBox.AppraisalInstitute_NGC &&
                    !marketSearchBox.AppraisalInstitute_ANA)
                    whereClause = whereClause.Or(x => 1 == 1);

                //if (marketSearchBox.CoinLevelId != 0)
                //    whereClause = whereClause.And(x => x.CoinLevelId == marketSearchBox.CoinLevelId);

                if (!String.IsNullOrWhiteSpace(marketSearchBox.AppraisalScore))
                    whereClause = whereClause.And
                        (x => x.AppraisalScore == marketSearchBox.AppraisalScore.Trim());

                if (!String.IsNullOrWhiteSpace(marketSearchBox.LOT))
                    whereClause = whereClause.And
                        (x => x.LOTS.Contains(marketSearchBox.LOT));

                var nameWhereClause = PredicateBuilder.False<View_CoinWithLastDealHistory>();
                if (!String.IsNullOrWhiteSpace(marketSearchBox.Description))
                {
                    nameWhereClause = nameWhereClause.Or
                        (x => x.Name.Contains(marketSearchBox.Description.Trim()));
                    //nameWhereClause = nameWhereClause.Or
                    //    (x => x.Description.Contains(marketSearchBox.Description.Trim()));

                    ctx.View_CoinWithLastDealHistory.AsExpandable().Where(nameWhereClause);
                }
                else
                nameWhereClause = nameWhereClause.Or(x => 1 == 1);

                var result = ctx.View_CoinWithLastDealHistory.AsExpandable().
                    Where(whereClause).
                    Where(nameWhereClause).
                    OrderBy(sortingExpression).Skip(pageIndex * 10).Take(10).ToList();
                //if (!String.IsNullOrWhiteSpace(marketSearchBox.Price))
                //{
                //    IList<Coin> coins = new List<Coin>();
                //    foreach (var coin in result)
                //    {
                //        var lastDeal = GetLastCoinDealHistory(coin);
                //        if (lastDeal != null && lastDeal.DealPrice == marketSearchBox.Price.Trim())
                //        {
                //            coins.Add(coin);
                //        }
                //    }

                //    return coins;
                //}
                //else
                //    return result;
                return result;
            }
        }
示例#27
0
        internal static bool DeleteCoin(Guid coinId)
        {
            using (Entities ctx = new Entities())
            {
                ctx.Coins.DeleteObject(ctx.Coins.SingleOrDefault(x => x.Id == coinId));

                return ctx.SaveChanges() != 0;
            }
        }