public static bool Add(ParkGrant model) { if (model == null) { throw new ArgumentNullException("model"); } model.GID = GuidGenerator.GetGuidString(); IParkGrant factory = ParkGrantFactory.GetFactory(); bool result = factory.Add(model); if (result) { OperateLogServices.AddOperateLog <ParkGrant>(model, OperateType.Add); } return(result); }
public static bool Add(List <ParkGrant> models) { if (models == null || models.Count == 0) { throw new ArgumentNullException("models"); } models.ForEach(p => p.GID = GuidGenerator.GetGuidString()); IParkGrant factory = ParkGrantFactory.GetFactory(); bool result = factory.Add(models); if (result) { foreach (var item in models) { OperateLogServices.AddOperateLog <ParkGrant>(item, OperateType.Add); } } return(result); }
private static bool AddOrderUpdateParkGrant(ParkGrant parkGrant, DbOperator dbOperator) { IParkGrant grantFactory = ParkGrantFactory.GetFactory(); ParkGrant oldGrant = grantFactory.QueryByCardIdAndParkingId(parkGrant.CardID, parkGrant.PKID); if (oldGrant != null) { parkGrant.GID = oldGrant.GID; parkGrant.BeginDate = oldGrant.BeginDate; parkGrant.EndDate = oldGrant.EndDate; } else { parkGrant.GID = GuidGenerator.GetGuidString(); } //检查车位号是否有效 if (!string.IsNullOrWhiteSpace(parkGrant.PKLot)) { List <ParkGrant> oldGrants = grantFactory.QueryByParkingAndLotAndCarType(parkGrant.PKID, parkGrant.PKLot, BaseCarType.MonthlyRent, parkGrant.GID); foreach (var item in oldGrants) { int oldLotLen = item.PKLot.Split(',').Length; int newLotLen = parkGrant.PKLot.Split(',').Length; if (oldLotLen != newLotLen) { throw new MyException(string.Format("车位号无效:车位号[{0}]与已存在的车位号[{1}]不完全一致", parkGrant.PKLot, item.PKLot)); } parkGrant.BeginDate = item.BeginDate; parkGrant.EndDate = item.EndDate; } } //临停转月卡 并且车位号存在完全一致的情况 给开始日期和结束日期赋值 if (oldGrant != null && !string.IsNullOrWhiteSpace(parkGrant.PKLot)) { ParkCarType newCarType = ParkCarTypeServices.QueryParkCarTypeByRecordId(parkGrant.CarTypeID); ParkCarType oldCarType = ParkCarTypeServices.QueryParkCarTypeByRecordId(oldGrant.CarTypeID); if (newCarType == null || oldCarType == null) { throw new MyException("车类不存在"); } if (newCarType.BaseTypeID == BaseCarType.MonthlyRent && oldCarType.BaseTypeID == BaseCarType.TempCar) { List <ParkGrant> oldGrants = grantFactory.QueryByParkingAndLotAndCarType(parkGrant.PKID, parkGrant.PKLot, BaseCarType.MonthlyRent, parkGrant.GID); foreach (var item in oldGrants) { int oldLotLen = item.PKLot.Split(',').Length; int newLotLen = parkGrant.PKLot.Split(',').Length; if (oldLotLen == newLotLen) { parkGrant.BeginDate = item.BeginDate; parkGrant.EndDate = item.EndDate; break; } } } } if (oldGrant != null) { return(grantFactory.Update(parkGrant, dbOperator)); } else { return(grantFactory.Add(parkGrant, dbOperator)); } }