Пример #1
0
        public void AddGood(Server.Model.Store.Store store, Good good, int count = 1)
        {
            try
            {
                if (store.Id == 0)
                {
                    throw new ArgumentException("store must be created");
                }
                var sg = Db.Set <StoreGood>().SingleOrDefault(it => it.GoodId == good.Id && it.StoreId == store.Id);
                if (sg != null)
                {
                    sg.StoreQuantity += count;
                }
                else
                {
                    var storeGood = new StoreGood
                    {
                        Articul = good.Articul,
                        //SerialNumber = good.SerialNumber,
                        StoreQuantity = count,
                        StoreId       = store.Id
                    };
                    var goodExists = GetById <int, Good>(good.Id);
                    if (goodExists == null)
                    {
                        //TODO:move upper good should be updated. Or create a method for update good.
                        _goodRepo.Save(good);
                        storeGood.Good = good;
                    }
                    else
                    {
                        storeGood.GoodId = good.Id;
                    }

                    Db.Set <StoreGood>().Add(storeGood);
                }
                Db.SaveChanges();
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex.Message, ex);
                throw;
            }
        }
Пример #2
0
    /// <summary>
    /// Adds the good.添加商品  并且引入该商品的修改价格   商店商品的价格 等于 商品的价格+修改价格(modifyprice) 
    /// </summary>
    /// <param name="myGood">My good.</param>
    private void AddGood(AGood myGood, int modifyprice=0)
    {
        bool isFind = false;
                int i = (int)(myGood.Type);
                foreach (AStoreGood storeGood in storeGoods[i]) {

                        if (storeGood.Good.EquitName == myGood .EquitName) {
                                isFind = true;
                                storeGood.Good.Number += myGood.Number;
                        }
                }
                if (!isFind) {
                        AStoreGood myStoreGood = new StoreGood (myGood);

                        GameObject go = NGUITools.AddChild (storeGoodType [i], _storeGood);

                        store_good myScript = go.GetComponent<store_good> ();

                        storeGoods [i].Add (myStoreGood);
                        AStoreGood good1 = storeGoods [i] [storeGoods [i].Count];
                        good1.StoreNumber = storeGoods [i].Count;
                        good1.ModifyPrice = modifyprice;

                        int x = (i % 3) * 80;
                        int y = (int)(i / 3) * 50;
                        go.transform.localPosition = new Vector3 (180 - x, 90 - y, 0);
                        go.GetComponent<UILabel> ().transform.localPosition = myStoreLablePosition;
                        good1.MyStoreGoodPosition = myStoreLablePosition;
                        myScript.myStoreGood = good1;
                        myScript.setSpriteAndLabel ();
                        //NGUITools.AddChild ();
                }
    }