public virtual OPResult Delete(TEntity entity)
        {
            if (entity.ID == default(int))
            {
                return new OPResult {
                           IsSucceed = true, Message = "删除成功!"
                }
            }
            ;
            try
            {
                LinqOP.Delete <TEntity>(entity);

                return(new OPResult {
                    IsSucceed = true, Message = "删除成功!"
                });
            }
            catch (Exception e)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "删除失败,失败原因:\n" + e.Message
                });
            }
        }
    }
Beispiel #2
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 #3
0
 public OPResult Delete(CustomerBO customer)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         try
         {
             _linqOP.Delete <SoftCustomerMapping>(o => o.CustomerID == customer.ID);
             _linqOP.Delete <SoftVersionCustomerMapping>(o => o.CustomerID == customer.ID);
             _linqOP.Delete <Customer>(customer);
             scope.Complete();
         }
         catch (Exception e)
         {
             return(new OPResult {
                 IsSucceed = false, Message = "删除失败,失败原因:\n" + e.Message
             });
         }
     }
     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 = "保存成功."
            });
        }