示例#1
0
        /// <summary>
        /// Determines whether the contact can be saved.
        /// </summary>
        /// <param name="contact">The contact.</param>
        /// <returns>
        /// Operation Result including information about success of execution
        /// </returns>
        public OperationResult CanSave(IContact contact)
        {
            OperationResult operationResult;

            operationResult = null;

            if (string.IsNullOrEmpty(contact.FirstName))
            {
                operationResult = new OperationResult("First name not set.");
            }

            if (string.IsNullOrEmpty(contact.LastName))
            {
                if (operationResult == null)
                {
                    operationResult = new OperationResult("Last name not set.");
                }
                else
                {
                    operationResult.Errors.Add("Last name not set;");
                }
            }

            if (operationResult == null)
            {
                this.contactPersistence.CanSave(contact);
            }

            return operationResult ?? new OperationResult();
        }
示例#2
0
 private static void ValidateContractForEqualOperation(OperationResult operationResult, bool value)
 {
     Contract.Ensures(
         (operationResult == null && Contract.Result<bool>() == false) ||
         (Contract.Result<bool>() == (operationResult != null && operationResult.Success == value)));
 }