예제 #1
0
 /// <summary>
 /// 删除单据
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public override bool Delete(VD_SalesOrder entity)
 {
     ActionBag.PushDelete <SalesOrder>(w => w.Id == entity.Id);
     ActionBag.PushDelete <SalesOrderDetail>(w => w.MainID == entity.Id);
     //DbActions.Add(() => ObjectContext.Delete<SalesOrder>(w => w.Id == entity.Id));
     //DbActions.Add(() => ObjectContext.Delete<SalesOrderDetail>(w => w.MainID == entity.Id));
     return(SaveChanges() > 0);
 }
예제 #2
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);
        }