Ejemplo n.º 1
0
        public void DeleteTuijian(int tjkey)
        {
            DianDianEntities db = new DianDianEntities();

            var delList = db.dd_tuijian_link.Where(p => p.sid == tjkey).ToList();

            foreach (var delid in delList)
            {
                var delbean = db.dd_tuijian_link.Find(delid);
                db.dd_tuijian_link.Attach(delbean);
                db.dd_tuijian_link.Remove(delbean);
                db.SaveChanges();
            }

            dd_tuijian tj = new dd_tuijian();

            tj.tjid = tjkey;

            db.dd_tuijian.Attach(tj);
            db.dd_tuijian.Remove(tj);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        public void SaveTuijian(int tjkey, string items, int afternum, string liyou, List <itemTuijian> tuijianList)
        {
            try
            {
                int shopkey         = Properties.Settings.Default.shopkey;
                DianDianEntities db = new DianDianEntities();

                var tjbean = db.dd_tuijian.Find(tjkey);
                if (tjbean != null)
                {
                    tjbean.afternum = afternum;
                    tjbean.items    = items;
                    tjbean.liyou    = liyou;

                    db.dd_tuijian.Attach(tjbean);
                    var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(tjbean);
                    stateEntity.SetModifiedProperty("afternum");
                    stateEntity.SetModifiedProperty("items");
                    stateEntity.SetModifiedProperty("liyou");
                    db.SaveChanges();

                    List <int> keepList = new List <int>();
                    foreach (var tuijian in tuijianList)
                    {
                        var tjLink = db.dd_tuijian_link.Where(p => p.itemkey == tuijian.itemkey && p.guigeid == tuijian.guigeid && p.tuijianid == tjbean.tjid).FirstOrDefault();
                        if (tjLink == null)
                        {
                            tjLink           = new dd_tuijian_link();
                            tjLink.guigeid   = tuijian.guigeid;
                            tjLink.itemkey   = tuijian.itemkey;
                            tjLink.name      = tuijian.name;
                            tjLink.num       = tuijian.num;
                            tjLink.price     = tuijian.price;
                            tjLink.thumb     = tuijian.thumb;
                            tjLink.tuijianid = tjbean.tjid;
                            db.dd_tuijian_link.Add(tjLink);
                        }
                        else
                        {
                            tjLink.name  = tuijian.name;
                            tjLink.num   = tuijian.num;
                            tjLink.price = tuijian.price;
                            tjLink.thumb = tuijian.thumb;
                            db.dd_tuijian_link.Attach(tjLink);
                            var stateEntity2 = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(tjLink);
                            stateEntity.SetModifiedProperty("name");
                            stateEntity.SetModifiedProperty("num");
                            stateEntity.SetModifiedProperty("price");
                            stateEntity.SetModifiedProperty("thumb");
                            db.SaveChanges();
                            keepList.Add(tjLink.sid);
                        }
                    }
                    var delList = db.dd_tuijian_link.Where(p => !keepList.Contains(p.sid)).ToList();
                    foreach (var delid in delList)
                    {
                        var delbean = db.dd_tuijian_link.Find(delid.sid);
                        db.dd_tuijian_link.Attach(delbean);
                        db.dd_tuijian_link.Remove(delbean);
                        db.SaveChanges();
                    }
                }
                else
                {
                    tjbean            = new dd_tuijian();
                    tjbean.afternum   = afternum;
                    tjbean.createdate = DateTime.Now;
                    tjbean.items      = items;
                    tjbean.liyou      = liyou;
                    tjbean.peoplenum  = 1;
                    tjbean.timesbyday = -1;
                    tjbean.shopkey    = shopkey;
                    tjbean.operater   = BizLoginController.userid;

                    db.dd_tuijian.Add(tjbean);
                    db.SaveChanges();

                    foreach (var tuijian in tuijianList)
                    {
                        dd_tuijian_link tdl = new dd_tuijian_link();
                        tdl.guigeid   = tuijian.guigeid;
                        tdl.itemkey   = tuijian.itemkey;
                        tdl.name      = tuijian.name;
                        tdl.num       = tuijian.num;
                        tdl.price     = tuijian.price;
                        tdl.thumb     = tuijian.thumb;
                        tdl.tuijianid = tjbean.tjid;
                        db.dd_tuijian_link.Add(tdl);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                log.Error("SaveTuijian error. msg=" + e.Message);
                throw;
            }
        }