Esempio n. 1
0
        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 = "保存成功."
            });
        }
Esempio n. 2
0
 public OPResult SaveSize()
 {
     try
     {
         if (_width != null)
         {
             _linqOP.Update <BusiDataDictionary>(_width);
         }
         if (_height != null)
         {
             _linqOP.Update <BusiDataDictionary>(_height);
         }
     }
     catch (Exception e)
     {
         return(new OPResult {
             IsSucceed = false, Message = "保存失败,失败原因:" + e.Message
         });
     }
     return(new OPResult {
         IsSucceed = true, Message = "保存成功."
     });
 }
Esempio n. 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 = "保存成功."
            });
        }
Esempio n. 4
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
         });
     }
 }
Esempio n. 5
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 = "保存成功."
            });
        }