예제 #1
0
        public static bool Update(BaseParkinfo model, bool addlog = true)
        {
            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 && park.PKID != model.PKID)
            {
                throw new MyException("车场编号不能重复");
            }

            bool result = factory.Update(model);

            if (result && addlog)
            {
                OperateLogServices.AddOperateLog <BaseParkinfo>(model, OperateType.Update);
            }
            return(result);
        }
예제 #2
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;
                }
            }
        }