Esempio n. 1
0
        public string Consumption(int id,double money,int gid,int uid)
        {
            YogaEntities ye = new YogaEntities();
            Member cc = ye.Member.FirstOrDefault((ccc) => ccc.Id == id);
            if (cc == null) return string.Format("编号为{0}的会员不存在", id);
            if (cc.CardRestMoney < money) return "余额不足";
            Goods g = ye.Goods.FirstOrDefault((gg) => gg.Id == gid);
            if (g == null) return string.Format("编号为{0}的商品不存在", gid);
            User u = ye.User.FirstOrDefault((uu) => uu.Id == uid);
            if (u == null) return string.Format("编号为{0}的操作员不存在", uid);
            cc.CardRestMoney -= money;
            cc.Score += (int)money;
            var cr = new ConsumptionRecord()
            {
                Date = DateTime.Now,
                MemberId = id,
                 MemberName = cc.Name,
                 GoodsId = gid,
                 GoodsName = g.Name,
                UserId = uid,
                Operater = u.Name
            };

            ye.AddToConsumptionRecord(cr);
            return ye.SaveChanges() == 2 ? "扣值成功" : "扣值失败";
        }