Esempio n. 1
0
        public ActionResult Detail(int id)
        {
            Goods item = this.GoodsRepository.Get(id);

            if (item == null)
            {
                item = new Goods();
            }

            ViewData["Category"] = this.GoodsTypeRepository.GetGoodsTypes(item.Id);

            return View(GoodsModel.From(item));
        }
Esempio n. 2
0
        public ActionResult Edit(int? id)
        {
            Goods item = null;

            if (id.HasValue)
            {
                item = this.GoodsRepository.Get(id.Value);
            }

            if (item == null)
            {
                item = new Goods();
            }

            return View(item);
        }
Esempio n. 3
0
        public GoodsModel(Goods goods)
        {
            this.Id = goods.Id;
            this.CodeNo = goods.CodeNo;
            this.BarCode = goods.BarCode;
            this.Name = goods.Name;
            this.Pinyin = goods.Pinyin;
            this.Picture = goods.Picture;
            this.Model = goods.Model;

            if (goods.Unit != null)
                this.UnitName = goods.Unit.Name;

            this.Quantity = goods.Quantity;
            this.MinQuantity = goods.MinQuantity;
            this.MaxQuantity = goods.MaxQuantity;
            this.IsMinWarning = goods.IsMinWarning;
            this.IsMaxWarning = goods.IsMaxWarning;

            if (goods.Brand != null)
                this.BrandName = goods.Brand.Name;

            if (goods.DisplayStands != null)
                this.DisplayStandsName = goods.DisplayStands.Name;

            this.PurchasePrice = goods.PurchasePrice;
            this.RetailPrice = goods.RetailPrice;
            this.MinPrice = goods.MinPrice;
            this.IsBarginStr = goods.IsBargin.ToString();
            this.BarginPrice = goods.BarginPrice;
            this.IsFreePriceStr = goods.IsFreePrice.ToString();
            this.PointBase = goods.PointBase;
            this.GoodsStatusStr = goods.GoodsStatus.ToString();
            this.Note = goods.Note;
            this.CreateTimeStr = goods.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
        }
Esempio n. 4
0
 public static GoodsModel From(Goods goods)
 {
     return new GoodsModel(goods);
 }
Esempio n. 5
0
        public ActionResult SaveOrUpdate(Goods obj,int[] categorys)
        {
            try
            {
                if (obj.Id > 0)
                {
                    obj = this.GoodsRepository.Get(obj.Id);
                    TryUpdateModel(obj);
                }

                if (obj.Pinyin.IsNullOrEmpty() && !obj.Name.IsNullOrEmpty())
                {
                    obj.Pinyin = ChineseToSpell.GetChineseSpell(obj.Name);
                }

                obj = this.GoodsRepository.SaveOrUpdate(obj);

                if (categorys != null)
                {
                    IList<GoodsType> types = this.GoodsTypeRepository.GetGoodsTypes(obj.Id);
                    IList<int> ids = categorys.ToList();

                    //
                    //每个商品可以属于多个类别
                    //先删除新类别中不存在的类别
                    int nLen = types.Count - 1;
                    for (int i = nLen; i >= 0; i--)
                    {
                        GoodsType goodsType = types[nLen];

                        if (ids.IndexOf(goodsType.Type.Id) >= 0)
                        {
                            ids.Remove(goodsType.Type.Id);
                        }
                        else
                        {
                            this.GoodsTypeRepository.Delete(goodsType);
                        }
                    }

                    foreach (var id in ids)
                    {
                        this.GoodsTypeRepository.SaveOrUpdate(new GoodsType()
                        {
                            Goods = obj,
                            Type = this.CommonCodeRepository.Get(id)
                        });
                    }
                }

                return JsonSuccess(obj);

            }
            catch (Exception ex)
            {
                return JsonError(ex.Message);
            }
        }