Exemple #1
0
        public IEnumerable <Tuple <ShoppingCart, IEnumerable <ShopProduct> > > GetUserBag()
        {
            var bag = GetGuestBagAndCreateIfNeeded(Guid);
            List <Tuple <ShoppingCart, IEnumerable <ShopProduct> > > result = new List <Tuple <ShoppingCart, IEnumerable <ShopProduct> > >();

            if (bag != null && bag.ShoppingCarts != null)
            {
                foreach (var cart in bag.ShoppingCarts)
                {
                    List <ShopProduct> products = new List <ShopProduct>();
                    var shop = _unitOfWork.ShopRepository.FindByIdOrNull(cart.ShopGuid);
                    foreach (var item in cart.PurchasedProducts)
                    {
                        //ShopProduct currProduct = shop.ShopProducts.FirstOrDefault(prod => prod.Guid.Equals(item.Item1));
                        ShopProduct currProduct = item.Item1;
                        ShopProduct product     = new ShopProduct();
                        product.Product  = new Product(currProduct.Product.Name, currProduct.Product.Category);
                        product.Guid     = currProduct.Guid;
                        product.Price    = currProduct.Price;
                        product.Quantity = item.Item2;
                        products.Add(product);
                    }
                    result.Add(new Tuple <ShoppingCart, IEnumerable <ShopProduct> >(cart, products));
                }
            }
            return(result);
        }
Exemple #2
0
 private void ResetLimitBuyDaily()
 {
     if (this._spList != null)
     {
         for (int i = 0; i < this._spList.Count; i++)
         {
             ShopProduct product = this._spList[i];
             if (((product.IsOnSale == 1) && (product.LimitCount > 0)) && (product.LimitCycle == 1))
             {
                 product.BoughtCount = 0;
             }
         }
     }
     if (this._filteredSpList != null)
     {
         for (int j = 0; j < this._filteredSpList.Count; j++)
         {
             ShopProduct product2 = this._filteredSpList[j];
             if (((product2.IsOnSale == 1) && (product2.LimitCount > 0)) && (product2.LimitCycle == 1))
             {
                 product2.BoughtCount = 0;
             }
         }
     }
     this.ManageShelf();
 }
Exemple #3
0
        public ActionResult Edit(FormCollection fc, ShopProduct shopproduct)
        {
            if (this.ModelState.IsValid)
            {
                shopproduct.Categories = new Collection <ShopCategory>();
                foreach (string field in fc)
                {
                    if (field.StartsWith("category"))
                    {
                        var catId = int.Parse(fc[field]);
                        var cat   = this.db.ShopCategories.Find(catId);
                        shopproduct.Categories.Add(cat);
                    }
                }

                var realProduct = this.db.ShopProducts.Find(shopproduct.ProductId);
                realProduct.Name        = shopproduct.Name;
                realProduct.Description = shopproduct.Description;
                realProduct.ImageUrl    = shopproduct.ImageUrl;
                realProduct.IsFeatured  = shopproduct.IsFeatured;
                realProduct.IsPublished = shopproduct.IsPublished;
                realProduct.Price       = shopproduct.Price;
                realProduct.Categories.Clear();
                realProduct.Categories = shopproduct.Categories;

                this.db.SaveChanges();
                return(this.RedirectToAction("Index"));
            }
            return(this.View(shopproduct));
        }
Exemple #4
0
        public void BuyShopProduct(ShopProduct shopProduct, uint count, bool needConfirm, CUIEvent uiEvent = null)
        {
            CUseable  useable  = CUseableManager.CreateUseable(shopProduct.Type, shopProduct.ID, 0);
            enPayType payType  = CMallSystem.ResBuyTypeToPayType((int)shopProduct.CoinType);
            uint      payValue = 0;

            if ((shopProduct != null) && shopProduct.m_bChangeGiftPrice)
            {
                payValue = shopProduct.m_newGiftPrice * count;
            }
            else
            {
                payValue = shopProduct.ConvertWithRealDiscount(useable.GetBuyPrice(shopProduct.CoinType) * count);
            }
            if (uiEvent == null)
            {
                uiEvent = Singleton <CUIEventManager> .GetInstance().GetUIEvent();

                uiEvent.m_eventID         = enUIEventID.Mall_Product_Confirm_Buy;
                uiEvent.m_eventParams.tag = (int)shopProduct.Key;
                uiEvent.m_eventParams.commonUInt32Param1 = count;
            }
            else
            {
                uiEvent.m_eventParams.commonUInt32Param1 = count;
            }
            CMallSystem.TryToPay(enPayPurpose.Buy, string.Format("{0}{1}", useable.m_name, (count <= 1) ? string.Empty : ("x" + count)), payType, payValue, uiEvent.m_eventID, ref uiEvent.m_eventParams, enUIEventID.None, needConfirm, true, false);
        }
Exemple #5
0
        public static bool HasSufficientMaterials(this TSPlayer player, ShopProduct product, int quantity)
        {
            var tplayer   = player.TPlayer;
            var inventory = tplayer.inventory;

            foreach (var requiredItem in product.RequiredItems)
            {
                var total = 0;

                foreach (var playerItem in inventory)
                {
                    if (playerItem.active && playerItem.type == requiredItem.ItemId)
                    {
                        total += playerItem.stack;
                    }
                }

                if (total < requiredItem.StackSize * quantity)
                {
                    return(false);
                }
            }

            return(true);
        }
 public Tuple <ShopProduct, int> ApplyPolicy(ShoppingCart cart, Guid productGuid, int quantity
                                             , BaseUser user, IUnitOfWork unitOfWork)
 {
     foreach (Tuple <ShopProduct, int> sp in cart.PurchasedProducts)
     {
         if (!CheckPolicyHelper(cart, sp.Item1.Guid, sp.Item2, user, unitOfWork))
         {
             continue;
         }
         Product p = null;
         Shop    s = unitOfWork.ShopRepository.FindByIdOrNull(cart.ShopGuid);
         double  shopProductPrice = 0;
         foreach (ShopProduct shopProduct in s.ShopProducts)
         {
             if (shopProduct.Guid.CompareTo(sp.Item1.Guid) == 0)
             {
                 p = shopProduct.Product;
                 shopProductPrice = shopProduct.Price;
                 break;
             }
         }
         double discountValue = -(DiscountPercentage / 100.0) * shopProductPrice;
         if (discountValue == 0)
         {
             return(null);
         }
         Product     discountProduct = new Product("Discount - " + p.Name, "Discount");
         ShopProduct discountRecord  = new ShopProduct(discountProduct, discountValue, 1);
         return(new Tuple <ShopProduct, int>(discountRecord, quantity));
     }
     return(null);
 }
Exemple #7
0
        /// <summary>
        /// 添加点赞记录
        /// </summary>
        /// <param name="productid"></param>
        /// <returns></returns>
        public string Praise(int productid)
        {
            try
            {
                //判断是否登录
                if (User_Shop.IsLogin() == false)
                {
                    throw new Exception("请登陆后点赞");
                }
                string curUserID = User_Shop.GetMemberID();
                //判断是否赞过
                if (DB.PraiseRecord.Any(q => q.ProductID == productid && q.MemberID == curUserID))
                {
                    throw new Exception("亲,当前商品已经赞过了");
                }

                PraiseRecord record = new PraiseRecord();
                record.ProductID  = productid;
                record.MemberID   = curUserID;
                record.CreateTime = DateTime.Now;
                DB.PraiseRecord.Insert(record);

                //累计点赞数
                ShopProduct product = DB.ShopProduct.FindEntity(productid);
                product.PraiseCount++;
                DB.ShopProduct.Update(product);

                return("1");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemple #8
0
        public async Task <IActionResult> Create(ShopProduct shopProduct)
        {
            if (!ModelState.IsValid)
            {
                return(View(shopProduct));
            }

            if (shopProduct.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo should be selected");
                return(View(shopProduct));
            }

            if (!shopProduct.Photo.ContentType.Contains("image/"))
            {
                ModelState.AddModelError("Photo", "File type is not valid");
                return(View(shopProduct));
            }

            if (shopProduct.Photo.Length / 1024 / 1024 > 2)
            {
                ModelState.AddModelError("Photo", "File size can not be more than 2 mb");
                return(View(shopProduct));
            }

            shopProduct.Image = await shopProduct.Photo.SaveAsync(_env.WebRootPath, "shopProducts");

            await _db.shopProducts.AddAsync(shopProduct);

            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Shop)));
        }
Exemple #9
0
 public IActionResult PostEditItem(ShopProduct product, string ShopId)
 {
     try
     {
         ViewData["ShopId"] = ShopId;
         _serviceFacade.EditProductInShop(new Guid(HttpContext.Session.Id), new Guid(ShopId), product.Guid, product.Price, product.Quantity);
         return(RedirectToAction("Products", "Seller", new { ShopId = ShopId }));
     }
     catch (NoPrivilegesException)
     {
         var redirect = this.Url.Action("Index", "Seller");
         var message  = new UserMessage(redirect, "You haven't sufficient priviliges. Cannot complete the request.");
         return(View("UserMessage", message));
     }
     catch (IllegalArgumentException)
     {
         var redirect = this.Url.Action("Index", "Seller");
         var message  = new UserMessage(redirect, "Please fill in all required fields in a valid manner.");
         return(View("UserMessage", message));
     }
     catch (GeneralServerError)
     {
         var redirect = this.Url.Action("Index", "Seller");
         var message  = new UserMessage(redirect, "An error has occured. Please refresh and try again.");
         return(View("UserMessage", message));
     }
     catch (DatabaseConnectionTimeoutException)
     {
         var redirect = this.Url.Action("Index", "Seller");
         var message  = new UserMessage(redirect, "An error has occured. Please refresh and try again. (Database connection lost).");
         return(View("UserMessage", message));
     }
 }
        public List <ShopProduct> ShowSuperShopInfo()
        {
            connection.Open();
            string             querry       = string.Format("SELECT * FROM t_Shop ,t_Product");
            SqlCommand         command      = new SqlCommand(querry, connection);
            SqlDataReader      aReader      = command.ExecuteReader();
            List <ShopProduct> shopProducts = new List <ShopProduct>();


            if (aReader.HasRows)
            {
                int serial = 1;
                while (aReader.Read())
                {
                    ShopProduct aShopProduct = new ShopProduct();
                    aShopProduct.Shop_Id          = serial;
                    aShopProduct.Shop_Name        = aReader[1].ToString();
                    aShopProduct.Shop_Address     = aReader[2].ToString();
                    aShopProduct.Product_Id       = aReader[4].ToString();
                    aShopProduct.Product_Quantity = aReader[5].ToString();
                    shopProducts.Add(aShopProduct);
                    serial++;
                }
            }

            connection.Close();
            return(shopProducts);;
        }
Exemple #11
0
        public ActionResult Create(ViewProductPriceCreate model)
        {
            if (ModelState.IsValid)
            {
                ShopProduct       product = db.ShopProducts.Include(p => p.ShopProductsPrices).Where(p => p.Id == model.Id).SingleOrDefault();
                ShopProductsPrice price   = db.ShopProductsPrices.Where(p => p.ShopProduct.Id == product.Id && p.CurrentPrice).SingleOrDefault();
                if (price != null)
                {
                    price.CurrentPrice    = false;
                    db.Entry(price).State = EntityState.Modified;
                    db.SaveChanges();
                }

                price = new ShopProductsPrice
                {
                    Price        = decimal.Parse(model.Price),
                    CurrentPrice = true,
                    DateSet      = DateTime.Now,
                    ShopProduct  = product
                };
                db.ShopProductsPrices.Add(price);

                db.SaveChanges();
                return(Redirect(model.URL));
                //return RedirectToAction("Details", "Products", new { id = product.Id });
            }

            return(View(model));
        }
Exemple #12
0
        public void AddProductToCart(ShoppingBag bag, Guid shopGuid, ShopProduct actualProduct, int quantity)
        {
            var cart = bag.GetShoppingCartAndCreateIfNeededForGuestOnlyOrInBagDomain(shopGuid);

            cart.AddProductToCart(actualProduct, quantity);
            _unitOfWork.BagRepository.Update(bag);
        }
 public void InitData()
 {
     if (!this._inited)
     {
         this._inited = true;
         this._spDict = new DictionaryView <uint, ShopProduct>();
         this._spList = new ListView <ShopProduct>();
         DictionaryView <uint, ResSpecSale> .Enumerator enumerator = GameDataMgr.specSaleDict.GetEnumerator();
         while (enumerator.MoveNext())
         {
             KeyValuePair <uint, ResSpecSale> current = enumerator.Current;
             ResSpecSale config = current.Value;
             if (config != null)
             {
                 CUseable useable = CUseableManager.CreateUseable((COM_ITEM_TYPE)config.dwSpecSaleType, config.dwSpecSaleId, 0);
                 if ((useable != null) && (useable.m_baseID != 0))
                 {
                     ShopProduct item = new ShopProduct(config);
                     if (item.IsOnSale)
                     {
                         this._spList.Add(item);
                         this._spDict.Add(item.Key, item);
                     }
                 }
             }
         }
         if (< > f__am$cache5 == null)
         {
        public List <ShopProduct> GetShopProducts()
        {
            var productList = new List <ShopProduct>();

            var query = "SELECT * FROM `products`";

            using (var command = new MySqlCommand(query, Connection))
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var product = new ShopProduct
                        {
                            Id          = reader.GetUInt32("id"),
                            Title       = reader.GetString("name"),
                            Description = reader.GetString("description"),
                            Price       = reader.GetDouble("price"),
                            Quantity    = reader.GetByte("quantityInStock")
                        };
                        productList.Add(product);
                    }
                    reader.Close();
                }

            return(productList);
        }
Exemple #15
0
        private void OnBuyReturn(CSPkg msg)
        {
            SCPKG_CMD_SPECSALEBUY stSpecSaleBuyRsp = msg.stPkgData.stSpecSaleBuyRsp;

            if (stSpecSaleBuyRsp.iErrCode == 0)
            {
                CSDT_SPECSALEBUYINFO stSpecSaleBuyInfo = stSpecSaleBuyRsp.stSpecSaleBuyInfo;
                if (this._spDict.ContainsKey(stSpecSaleBuyInfo.dwId))
                {
                    ShopProduct sp = this._spDict[stSpecSaleBuyInfo.dwId];
                    sp.BoughtCount += stSpecSaleBuyInfo.dwNum;
                    if ((sp.Type != COM_ITEM_TYPE.COM_OBJTYPE_HERO) && (((sp.Type != COM_ITEM_TYPE.COM_OBJTYPE_ITEMPROP) || !sp.IsPropGift) || !sp.IsPropGiftUseImm))
                    {
                        CUseable   useable = CUseableManager.CreateUseable(sp.Type, sp.ID, (int)stSpecSaleBuyInfo.dwNum);
                        CUseable[] items   = new CUseable[] { useable };
                        Singleton <CUIManager> .GetInstance().OpenAwardTip(items, Singleton <CTextManager> .GetInstance().GetText("Buy_Ok"), false, enUIEventID.None, false, false, "Form_Award");
                    }
                    this.FilterProduct(sp);
                    CMallSystem instance = Singleton <CMallSystem> .GetInstance();

                    if (((instance.m_MallForm != null) && instance.m_IsMallFormOpen) && (instance.CurTab == CMallSystem.Tab.Factory_Shop))
                    {
                        this.Draw(instance.m_MallForm);
                    }
                    Singleton <EventRouter> .GetInstance().BroadCastEvent <ShopProduct>(EventID.Mall_Factory_Shop_Product_Bought_Success, sp);
                }
            }
            else
            {
                Singleton <CUIManager> .GetInstance().OpenMessageBox(string.Format("{0}(错误码{1})", Singleton <CTextManager> .GetInstance().GetText("buySpecSaleFailed"), stSpecSaleBuyRsp.iErrCode), false);
            }
        }
Exemple #16
0
        public static Shop SaveShopUsersPurchaseHistory()
        {
            var shop   = SaveShopWithName();
            var galaxy = new ShopProduct(new Product("Galaxy", "Smartphones"), 10, 10);

            shop.UsersPurchaseHistory.Add(new Tuple <Guid, ShopProduct, int>(Guid.NewGuid(), galaxy, 5));
            return(shop);
        }
Exemple #17
0
        public Guid AddProductToShop(Shop shop, Guid userGuid, Product product, double price, int quantity)
        {
            var newShopProduct = new ShopProduct(product, price, quantity);

            shop.AddProductToShop(newShopProduct);
            _unitOfWork.ShopRepository.Update(shop);
            return(newShopProduct.Guid);
        }
Exemple #18
0
 public static string GetProductPriceGouWu(ShopProduct model)
 {
     //if (model.PriceShopping == 0)
     //{
     //    return model.PriceScore.ToString();
     //}
     return(model.PriceScore.ToString());
 }
Exemple #19
0
 public ShopProcessingStatistics(DownloadInfo info, Action <string, bool> messageAdder, Logger logger)
 {
     (_addMessage, _info, _logger) = (messageAdder, info, logger);
     _product = new ShopProduct {
         ShopId   = info.ShopId,
         ShopName = info.ShopName
     };
 }
Exemple #20
0
        public ActionResult DeleteConfirmed(int id)
        {
            ShopProduct shopproduct = this.db.ShopProducts.Find(id);

            this.db.ShopProducts.Remove(shopproduct);
            this.db.SaveChanges();
            return(this.RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(ShopProduct model)
        {
            ShopProduct product = db.ShopProducts
                                  .Include(p => p.ShopProductsPrices)
                                  .Where(p => p.Id == model.Id).SingleOrDefault();

            RemoveProduct(product);
            return(RedirectToAction("Index"));
        }
Exemple #22
0
        public static Shop SaveShopProducts()
        {
            var shop = SaveShopWithName();

            var galaxy = new ShopProduct(new Product("Galaxy", "Smartphones"), 10, 10);

            shop.AddProductToShop(galaxy);
            return(shop);
        }
Exemple #23
0
 public static void VerifyShopProduct(ShopProduct expected, ShopProduct actual)
 {
     Assert.AreEqual(expected.Guid, actual.Guid);
     Assert.AreEqual(expected.Price, actual.Price);
     Assert.AreEqual(expected.Quantity, actual.Quantity);
     Assert.AreEqual(expected.Product.Name, actual.Product.Name);
     Assert.AreEqual(expected.Product.Category, actual.Product.Category);
     CollectionAssert.AreEquivalent(expected.Product.Keywords, actual.Product.Keywords);
 }
        /// <summary>
        /// Shop product
        /// </summary>
        private void DrawShopProductSection()
        {
            Event e = Event.current;

            GUILayout.Space(10);
            EditorGUILayout.LabelField("Products:", EditorStyles.boldLabel);
            _productScrollPosition =
                EditorGUILayout.BeginScrollView(_productScrollPosition, "GroupBox", GUILayout.Height(100));
            foreach (var product in _selectedAsset.Products)
            {
                Color gui = GUI.color;
                if (product == _selectedProduct)
                {
                    GUI.color = Color.red;
                }

                if (GUILayout.Button(product.Name + "    $" + product.Price + " (" + product.ProductType + ")"))
                {
                    GUI.FocusControl("");
                    if (e.button == 1)
                    {
                        _selectedAsset.Products.Remove(product);
                        return;
                    }

                    if (_selectedProduct == product)
                    {
                        _selectedProduct = null;
                        return;
                    }

                    _selectedProduct = product;
                }

                GUI.color = gui;
            }

            EditorGUILayout.EndScrollView();


            if (GUILayout.Button("Add Product"))
            {
                _selectedAsset.Products.Add(new ShopProduct());
            }

            if (_selectedProduct != null)
            {
                if (!_selectedAsset.Products.Contains(_selectedProduct))
                {
                    _selectedProduct = null;
                    return;
                }

                GUILayout.Space(10);
                _selectedProduct.ShopProductSection();
            }
        }
Exemple #25
0
        public void RequestBuy(ShopProduct shopProduct, uint count)
        {
            ShopProduct           product          = shopProduct;
            CSPkg                 msg              = NetworkModule.CreateDefaultCSPKG(0x481);
            CSPKG_CMD_SPECSALEBUY stSpecSaleBuyReq = msg.stPkgData.stSpecSaleBuyReq;

            stSpecSaleBuyReq.stSpecSaleBuyInfo.dwId  = product.Key;
            stSpecSaleBuyReq.stSpecSaleBuyInfo.dwNum = count;
            Singleton <NetworkModule> .GetInstance().SendLobbyMsg(ref msg, true);
        }
Exemple #26
0
        //
        // GET: /ShopProduct/Details/5

        public ActionResult Details(int id = 0)
        {
            ShopProduct shopproduct = this.db.ShopProducts.Find(id);

            if (shopproduct == null)
            {
                return(this.HttpNotFound());
            }
            return(this.View(shopproduct));
        }
Exemple #27
0
        /// <summary>
        /// 产品详细页面
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string GetProduct(ShopProduct model)
        {
            return(GetAction("selfproduct", "detail", model.ID));

            //判断商品是否是自营商城
            //if (model.ShopID == 1)
            //{
            //    return GetAction("selfproduct", "selfdetail", model.ID);
            //}
            //return GetAction("unionproduct", "uniondetail", model.ID);
        }
    private void AddProduct(Payments.Products.Product product)
    {
        Transform   obj        = Instantiate(itemPrefab, holder);
        ShopProduct newProduct = new ShopProduct(obj);

        newProduct.Product = product;

        Items.Add(newProduct);

        SetItem(newProduct, true);
    }
        //==========================================================

        //==========================================================
        public void RemoveProduct(ShopProduct product)
        {
            db.ShopProductsPrices.RemoveRange(product.ShopProductsPrices);
            db.SaveChanges();

            string dirPath = HttpContext.Server.MapPath("~/Content/Images/Shop/Products");

            product.PhotoName = Image.Delete(dirPath, product.PhotoName);

            db.ShopProducts.Remove(product);
            db.SaveChanges();
        }
Exemple #30
0
    public override void DeSerialize(Dictionary <string, object> elements)
    {
        foreach (var ele in (List <object>)elements["Products"])
        {
            Dictionary <string, object> prod = (Dictionary <string, object>)ele;
            ShopProduct product = CreateInstance <ShopProduct>();
            product.DeSerialize(prod);
            Products.Add(product);
        }

        base.DeSerialize(elements);
    }
Exemple #31
0
        //public ScrapeStatus Status
        //{
        //    get
        //    {
        //        return (ScrapeStatus)StatusCode;
        //    }
        //    set
        //    {
        //        StatusCode = (int)value;
        //    }
        //}
        public ShopProduct CreateShopProduct(ShopCategory shopCategory)
        {
            var shopProduct = new ShopProduct();
            shopProduct.Title = this.Title;
            shopProduct.Description = this.Description;
            shopProduct.Price = this.Price;
            shopProduct.IsSale = this.IsSale;
            shopProduct.DiscountPrice = this.DiscountPrice;

            shopProduct.Category = shopCategory;

            this.ShopProduct = shopProduct;

            Context.Inst.ShopProductSet.Add(shopProduct);
            Context.Save();

            foreach (var image in this.Images)
            {
                shopProduct.AddImage(image.LocalPath);
            }

            return shopProduct;
        }