Beispiel #1
0
        /// <summary>
        /// 保存单据
        /// </summary>
        public virtual OPResult Save()
        {
            var bill = Master;

            bill.CreatorID = VMGlobal.CurrentUser.ID;
            bill.Code      = this.GenerateBillCode();
            var details = Details;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    bill.ID = _linqOP.Add <TBill, int>(bill, b => b.ID);
                    details.ForEach(d => d.BillID = bill.ID);
                    _linqOP.Add <TDetails>(details);
                    scope.Complete();
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = e.Message
                    });
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
        public virtual OPResult AddOrUpdate(TEntity entity)
        {
            //var entity = bo as TEntity;//这样貌似不行,即使重载了类型转换符,使用as语法返回的仍然是null
            var id = entity.ID;

            try
            {
                if (id == default(int))
                {
                    entity.ID = LinqOP.Add <TEntity, int>(entity, o => o.ID);
                }
                else
                {
                    LinqOP.Update <TEntity>(entity);
                }
            }
            catch (Exception e)
            {
                entity.ID = id;
                return(new OPResult {
                    IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                });
            }

            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
Beispiel #3
0
        public OPResult AddOrUpdate(SoftVersionTrackBO version)
        {
            int id = version.ID;//临时变量,当保存出错时还原

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    if (id == default(int))
                    {
                        version.CreateTime = DateTime.Now;
                        version.SoftID     = this.ID;
                        version.ID         = _linqOP.Add <SoftVersionTrack, int>(version, o => o.ID);
                    }
                    else
                    {
                        _linqOP.Update <SoftVersionTrack>(version);
                        _linqOP.Delete <SoftVersionCustomerMapping>(o => o.SoftVersionID == version.ID);
                    }
                    var mapping = version.Customers.Select(o => new SoftVersionCustomerMapping {
                        SoftVersionID = version.ID, CustomerID = o.ID
                    });
                    _linqOP.Add(mapping);
                    scope.Complete();
                }
                catch (Exception e)
                {
                    version.ID = id;
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
            if (id == default(int))
            {
                this.VersionTracks.Insert(0, version);
            }
            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
Beispiel #4
0
        public OPResult AddOrUpdate(SoftToUpdateBO soft)
        {
            var id = soft.ID;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    if (id == default(int))
                    {
                        soft.IdentificationKey = Guid.NewGuid().ToString();
                        soft.ID = _linqOP.Add <SoftToUpdate, int>(soft, o => o.ID);
                    }
                    else
                    {
                        _linqOP.Update <SoftToUpdate>(soft);
                        _linqOP.Delete <SoftCustomerMapping>(o => o.SoftID == soft.ID);
                    }
                    var mapping = soft.Customers.Select(o => new SoftCustomerMapping {
                        SoftID = soft.ID, CustomerID = o.ID
                    });
                    _linqOP.Add(mapping);
                    scope.Complete();
                }
                catch (Exception e)
                {
                    soft.ID = id;
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
            return(new OPResult {
                IsSucceed = true, Message = "保存成功."
            });
        }
Beispiel #5
0
 public OPResult AddOrUpdate(CustomerBO customer)
 {
     try
     {
         if (customer.ID == default(int))
         {
             customer.IdentificationKey = Guid.NewGuid().ToString();
             customer.ID = _linqOP.Add <Customer, int>(customer, o => o.ID);
         }
         else
         {
             _linqOP.Update <Customer>(customer);
         }
         return(new OPResult {
             IsSucceed = true, Message = "保存成功."
         });
     }
     catch (Exception e)
     {
         return(new OPResult {
             IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
         });
     }
 }