# What to write a complex validation?

  • Use let to hold computed properties inside pre block

    pre{
    	let participantCount:Int = `domainLogicRef.lottery.participantCount(input.lotteryName)`
    	condition atLeastTwoParticipants => 
                    existingLotteryName -> ` participantCount > 1` failing "The lottery does not have any participant!"
    }
    
  • To execute a check only when a pervious condition passes use the condition name with -> operator.



     


    pre{
    	condition existingLotteryName => lottery.lotteryNameExists(input.lotteryName) 
    	condition openToRun => existingLotteryName -> lottery.isOpenToRun(input.lotteryName)
    }
    
  • To execute a condition only when an optional input's value exists use keyword present along with -> operator.




     



    command addParticipant{
    		input(lotteryName:String,participantName:String,email:String?)
    		pre{
    		condition validEmail => present(input.email) -> lottery.validateEmail(input.email.dig)
    		}
    }
    
  • Use ! to apply negation inside the condition logic


     



    pre{
    		condition NewLotteryName => !(lottery.lotteryNameExists(input.lotteryName)) failing "Lottery Name Already Exists !"
    			...
    }