コード例 #1
0
        public string AddEnterpriseProperty(EnterprisePropertyDto enterpriseProperty)
        {
            try
            {
                using (var db = new BCEnterpriseContext())
                {
                    if (db.EnterprisePropertys.Any(n => n.Name.Equals(enterpriseProperty.Name)))
                    {
                        throw new KnownException("已存在该名字");
                    }
                    if (string.IsNullOrEmpty(enterpriseProperty.Name) || string.IsNullOrEmpty(enterpriseProperty.EnterprisePropertyID))
                    {
                        throw new KnownException("信息不完善");
                    }

                    var property = new ML.BC.EnterpriseData.Model.EnterpriseProperty
                    {
                        Available            = enterpriseProperty.Available,
                        EnterprisePropertyID = enterpriseProperty.EnterprisePropertyID,
                        Name = enterpriseProperty.Name
                    };
                    db.EnterprisePropertys.Add(property);
                    if (db.SaveChanges() > 0)
                    {
                        return(property.EnterprisePropertyID);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #2
0
 public bool DeleteEnterpriseProperty(string enterprisePropertyId)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             ML.BC.EnterpriseData.Model.EnterpriseProperty temp = db.EnterprisePropertys.FirstOrDefault(obj => obj.EnterprisePropertyID.Equals(enterprisePropertyId));
             db.EnterprisePropertys.Attach(temp);
             db.EnterprisePropertys.Remove(temp);
             if (db.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }