Пример #1
0
        public static bool Add(BaseParkinfo model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (string.IsNullOrWhiteSpace(model.PKNo))
            {
                throw new MyException("车场编号不能为空");
            }

            IParking     factory = ParkingFactory.GetFactory();
            BaseParkinfo park    = factory.QueryParkingByParkingNo(model.PKNo);

            if (park != null)
            {
                throw new MyException("车场编号不能重复");
            }

            model.PKID = GuidGenerator.GetGuidString();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = factory.Add(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加车场信息失败");
                    }

                    result = ParkCarModelServices.AddDefault(model.PKID, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加车型失败");
                    }

                    result = ParkCarTypeServices.AddDefault(model.PKID, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加车类型失败");
                    }
                    dbOperator.CommitTransaction();
                    if (result)
                    {
                        OperateLogServices.AddOperateLog <BaseParkinfo>(model, OperateType.Add);
                    }
                    return(true);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 创建默认车场
        /// </summary>
        /// <param name="model"></param>
        /// <param name="dbOperator"></param>
        /// <returns></returns>
        public static bool AddParkinfoDefault(BaseParkinfo model, DbOperator dbOperator)
        {
            IParking factory = ParkingFactory.GetFactory();

            try
            {
                dbOperator.BeginTransaction();
                bool result = factory.Add(model, dbOperator);
                if (!result)
                {
                    throw new MyException("添加车场信息失败");
                }

                result = ParkCarModelServices.AddDefault(model.PKID, dbOperator);
                if (!result)
                {
                    throw new MyException("添加车型失败");
                }

                result = ParkCarTypeServices.AddDefault(model.PKID, dbOperator);
                if (!result)
                {
                    throw new MyException("添加车类型失败");
                }
                dbOperator.CommitTransaction();
                if (result)
                {
                    OperateLogServices.AddOperateLog <BaseParkinfo>(model, OperateType.Add);
                }
                return(true);
            }
            catch
            {
                dbOperator.RollbackTransaction();
                throw;
            }
        }