Esempio n. 1
0
        public ActionResult Update(string categoryNO, string categoryName, int isService)
        {
            Category category = _categoryBLL.GetCategoryByCategoryNo(categoryNO);

            if (category == null)
            {
                return(Json("False", JsonRequestBehavior.AllowGet));
            }
            else if (string.IsNullOrEmpty(categoryName))
            {
                return(Json("False", JsonRequestBehavior.AllowGet));
            }
            else
            {
                category.Name      = categoryName;
                category.IsService = isService == 1 ? true : false;
                if (_categoryBLL.Save(category))
                {
                    return(Json("True", JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("False", JsonRequestBehavior.AllowGet));
                }
            }
        }
Esempio n. 2
0
        public ActionResult Add(GoodsModel model)
        {
            // 判断传递的值是否为空
            if (model == null)
            {
                // 是空 则直接返回
                return(RedirectToAction("Add", new { msg = "提交的数据为空,请重新提交" }));
            }

            // 构造 Goods 对象
            #region 构造 Goods 对象

            Goods goods = new Goods();
            goods.Id           = Guid.NewGuid();
            goods.IsDeleted    = false;
            goods.Name         = model.Name;
            goods.Price        = model.Price;
            goods.Code         = "Goods_" + TimeManager.GetCurrentTimestamp();
            goods.CreatedTime  = DateTime.Now.Date;
            goods.Description  = model.Description;
            goods.ServiceCount = model.ServiceCount;
            goods.DeletedTime  = DateTime.MinValue.AddHours(8);

            // 商品新家字段  OriginalPrice  原价

            // 该字段不影响原来商品添加的逻辑
            goods.OriginalPrice = model.OriginalPrice;


            #endregion

            // 添加新的Goods 对象

            if (_goodsBLL.Add(goods))
            {
                #region 此处应该用事务来做 但是现在简易版就随意一点 将来这里必须用事务

                #endregion

                // 添加成功后 构造 goodsimage 对象
                // 并添加到数据库

                LogHelper.Log.Write("添加商品成功,现在正在构造goodsImage");

                GoodsImage gi = new GoodsImage();
                gi.Id          = Guid.NewGuid();
                gi.ImagePath   = model.PicturePath;
                gi.CreatedTime = DateTime.Now.Date;
                gi.GoodsId     = goods.Id;
                gi.IsDeleted   = false;
                gi.DeletedTime = DateTime.MinValue.AddHours(8);

                _goodsImagesBLL.Add(gi);

                LogHelper.Log.Write("添加商品图片成功");

                // 添加成功 则 遍历传递过来的分类列表
                // 并添加到数据库
                foreach (var item in model.CategoryList)
                {
                    if (item == null)
                    {
                        LogHelper.Log.Write("获取商品分类列表失败");
                    }
                    // 构造 GoodsCategory 对象
                    GoodsCategory gc = new GoodsCategory();
                    gc.Id          = Guid.NewGuid();
                    gc.CreatedTime = DateTime.Now.Date;
                    gc.CategoryId  = _categoryBLL.GetCategoryByCategoryNo(item).Id;
                    gc.IsDeleted   = false;
                    gc.GoodsId     = goods.Id;
                    gc.DeletedTime = DateTime.MinValue.AddHours(8);

                    _goodsCategoryBLL.Add(gc);
                }

                Thread.Sleep(2000);

                return(RedirectToAction("Add", new { msg = "添加成功" }));
            }
            else
            {
                return(RedirectToAction("Add", new { msg = "添加失败" }));
            }
        }
Esempio n. 3
0
        public ActionResult GetGoodsList(string categoryCode)
        {
            // 先取出当前vip等级会员折扣
            Member member   = _memberBLL.GetMemberByOpenId(System.Web.HttpContext.Current.Session["member"].ToString());
            double discount = _rulesBLL.GetDiscountByVIP(member.Vip);

            List <GoodsModel> goodsList = new List <GoodsModel>();

            // 判断传递进来的categoryCode 是否为空

            // 如果为空 则搜索出所有没有标记为删除的Goods对象

            if (categoryCode == null)
            {
                // 得到所有Goods对象之后  遍历  构造出 GoodsModel list
                foreach (var item in _goodsBLL.GetAllNoDeteledGoods())
                {
                    GoodsModel gm = new GoodsModel(item);
                    gm.PicturePath = _goodsImagesBLL.GetPictureByGoodsId(gm.Id).ImagePath;
                    gm.Discount    = discount;
                    goodsList.Add(gm);
                }
            }
            else
            {
                // 如果传进来的categoryCode 不为空

                // 则要根据这个categoryCode 找到对应的Category对象

                // 然后通过找到的category对象 得到  GoodsCategoryList

                Category             category          = _categoryBLL.GetCategoryByCategoryNo(categoryCode);
                List <GoodsCategory> goodsCategoryList = _goodsCategoryBLL.GetGoodsCategoryListByCategoryId(category.Id).ToList();

                // 最后再构造 GoodModelList
                foreach (var item in goodsCategoryList)
                {
                    GoodsModel gm = new GoodsModel(_goodsBLL.GetGoodsById(item.GoodsId));
                    gm.PicturePath = _goodsImagesBLL.GetPictureByGoodsId(item.GoodsId).ImagePath;
                    gm.Discount    = discount;
                    goodsList.Add(gm);
                }
            }

            // 由于这个方法需要与前端传递 List对象

            // 所以要将等到的 GoodsModel List 序列化为 json字符串 传递到前端

            string jsonResult = string.Empty;

            try
            {
                // 序列化
                jsonResult = ObjToJson <List <GoodsModel> >(goodsList);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Write(ex.Message);
                LogHelper.Log.Write(ex.StackTrace);
                throw;
            }

            return(Content(jsonResult));
        }