Exemplo n.º 1
0
        protected override bool Edit(VD_SalesOrder entity, List <VD_SalesOrderDetail> list)
        {
            var Tentity = ObjectContext.Query <SalesOrder>().FirstOrDefault(w => w.Id == entity.Id);

            ObjectContext.TrackEntity(Tentity);
            Tentity = mapMain.Resolve(entity, Tentity);
            ActionBag.PushUpdate(Tentity);

            List <SalesOrderDetail> sourceItems = ObjectContext.Query <SalesOrderDetail>().Where(w => w.MainID.Equals(Tentity.Id)).ToList();

            foreach (var item in list)
            {
                bool isnew      = true;
                var  sourceItem = sourceItems.FirstOrDefault(w => w.Id.Equals(item.Id));
                //原来就存在
                if (sourceItem != null)
                {
                    ObjectContext.TrackEntity(sourceItem);
                    isnew = false;
                }
                else
                {
                    //新增的明细
                    sourceItem = new SalesOrderDetail();
                    if (item.Id.Equals(Guid.Empty))
                    {
                        item.Id = Guid.NewGuid();
                    }
                }
                sourceItem.MainID = Tentity.Id;
                if (mapDetail.Compare(item, sourceItem))
                {
                    sourceItem = mapDetail.Model;
                    if (isnew)
                    {
                        ActionBag.PushInsert(sourceItem);
                    }
                    else
                    {
                        ActionBag.PushUpdate(sourceItem);
                    }
                }
                sourceItems.Remove(sourceItem);
            }
            //剩下的是删除的数据
            if (sourceItems.Count() > 0)
            {
                foreach (var item in sourceItems)
                {
                    ActionBag.PushDelete(item);
                    // DbActions.Add(() => ObjectContext.Delete(item));
                }
            }
            return(SaveChanges() > 0);
        }
Exemplo n.º 2
0
        protected override bool Create(VD_SalesOrder entity, List <VD_SalesOrderDetail> list)
        {
            var Tentity = mapMain.Resolve(entity);

            Tentity.Id       = Guid.NewGuid();
            Tentity.Maker    = entity.Maker;
            Tentity.MakeDate = entity.MakeDate ?? DateTime.Now;
            ActionBag.PushInsert(Tentity);
            foreach (var item in list)
            {
                //新增的明细
                var detail = new SalesOrderDetail();
                detail        = mapDetail.Resolve(item, detail);
                detail.MainID = Tentity.Id;
                ActionBag.PushInsert(detail);
            }
            var r = SaveChanges() > 0;

            if (r)
            {
                entity.Id = Tentity.Id;
            }
            return(r);
        }