/// <summary>
        /// 重置热门产品
        /// </summary>
        public void ResetHotProducts(int count = 6)
        {
            try
            {
                //删除热门产品
                var data = context.HotProducts.Where(p => p.Id != null || p.Id == "");
                foreach (var item in data)
                {
                    context.HotProducts.Remove(item);
                }
                //从订单按数量插入数据
                //var temp = from p in context.OrderDetails
                //           group p by p.ProductId into g
                //           select g;

                var temp = (from a in context.OrderDetails
                            join p in context.Products
                            on a.ProductId equals p.Id
                            where p.IsDeleted != 1 && p.SaleStatus == 1 &&
                            p.Type != CommonRules.OtherProductTypeDicValue
                            group a by a.ProductId into g
                            select new
                {
                    ProductID = g.Key,
                    Num = g.Sum(t => t.Num)
                }).OrderByDescending(a => a.Num).Take(count);
                foreach (var item in temp)
                {
                    var hot = new HotProduct();
                    hot.ProductID = item.ProductID;
                    hot.Num       = item.Num;
                    hot.Id        = FCake.Core.Common.DataHelper.GetSystemID();
                    hot.CreatedOn = DateTime.Now;
                    context.HotProducts.Add(hot);
                }
                //如果数量不足,则从产品表插入剩余数量的产品(不在热门产品中)
                //优先取推荐产品
                if (temp.Count() < count)
                {
                    var pro = from a in context.Products.Where(p => p.IsDeleted != 1 && p.SaleStatus == 1 && p.Type != CommonRules.OtherProductTypeDicValue)
                              .OrderByDescending(p => p.IsRecommend).ThenByDescending(p => p.SortNo).Take(count - temp.Count()) select new { ProductID = a.Id, Num = 1 };
                    foreach (var item in pro)
                    {
                        var hotPro = new HotProduct();
                        hotPro.ProductID = item.ProductID;
                        hotPro.Num       = item.Num;
                        hotPro.Id        = FCake.Core.Common.DataHelper.GetSystemID();
                        hotPro.CreatedOn = DateTime.Now;
                        //item.CreatedBy = UserCache.CurrentUser.Id;
                        context.HotProducts.Add(hotPro);
                    }
                }
                //数据更新保存
                context.SaveChanges();
            }
            catch
            {
            }
        }
示例#2
0
        public ActionResult Product_AddOrEdit(int id = 0)
        {
            if (id == 0)
            {
                HotProduct Product = new HotProduct();

                return(View(Product));
            }
            else
            {
                MasterContext dbContext = new MasterContext();
                var           Product   = dbContext.Product.First(q => q.Id == id);

                return(View(Product));
            }
        }
示例#3
0
        /// <summary>
        /// Updates the Local DbSet to be in sync with the Cosmos DB collection
        /// </summary>
        /// <param name="db"> a DbSet instance of the DbContext that constains Best Selling Items</param>

        public void UpdateHotItems(DbSet <HotProduct> db)
        {
            DocumentClient    Client = new DocumentClient(_endpointUri, _primaryKey);
            Uri               collectionSelfLink3 = UriFactory.CreateDocumentCollectionUri(ConfigurationManager.AppSettings["database"], ConfigurationManager.AppSettings["hotItemsCollection"]);
            List <dynamic>    topItems            = ReadAllDocumentsInCollectionAsync(Client, collectionSelfLink3);
            List <HotProduct> hotItems            = new List <HotProduct>();

            foreach (dynamic popular in topItems)
            {
                HotProduct hot = popular;
                if (!hotItems.Contains(hot))
                {
                    hotItems.Add(hot);
                }
            }
            hotItems.ForEach(z => db.Add(z));
        }
示例#4
0
        public ActionResult Product_AddOrEdit(HotProduct model)
        {
            try
            {
                if (model.Id == 0)
                {
                    MasterContext Product_Add = new MasterContext();

                    HotProduct hotProduct = new HotProduct()
                    {
                        Code                 = model.Code,
                        Name                 = model.Name,
                        Stok_No              = model.Stok_No,
                        Fiyat_No             = model.Fiyat_No,
                        Adet_No              = model.Adet_No,
                        Info                 = model.Info,
                        rlt_Product_Group_Id = model.rlt_Product_Group_Id,
                    };

                    Product_Add.Product.Add(hotProduct);
                    Product_Add.SaveChanges();
                    ViewBag.message = "Yeni Ürün Eklendi";
                    ModelState.Clear();
                    return(Redirect("/Product/Product_List"));
                }
                else
                {
                    MasterContext Product = new MasterContext();

                    Product.Entry(model).State = System.Data.Entity.EntityState.Modified;
                    Product.SaveChanges();

                    return(Redirect("/Product/Product_List"));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }