// ------------------------
 // Send an email
 // ------------------------
 public static SimpleRequest SendEmail(SimpleRequest input)
 {
     if (input.Email.EndsWith("example.com"))
         throw new Exception(string.Format("Can't send email to {0}", input.Email));
     else
         Console.WriteLine("Sending email={0}", input.Email);
     return input; // return request for processing by next step        }
 }
Beispiel #2
0
        // ------------------------
        // Update the database
        // ------------------------


        public static void UpdateDatabase(SimpleRequest input)
        {
            // do something
            // return nothing at all
            Console.WriteLine("Database updated with userId={0} email={1}", input.UserId, input.Email);
        }
Beispiel #3
0
        // ------------------------
        // Add another step
        // ------------------------

        // trim spaces and lowercase
        public static SimpleRequest CanonicalizeEmail(SimpleRequest input)
        {
            return(new SimpleRequest {
                UserId = input.UserId, Name = input.Name, Email = input.Email.Trim().ToLower()
            });
        }
 // ------------------------
 // Update the database
 // ------------------------
 public static void UpdateDatabase(SimpleRequest input)
 {
     // do something
     // return nothing at all
     Console.WriteLine("Database updated with userId={0} email={1}", input.UserId, input.Email);
 }
 // ------------------------
 // Add another step
 // ------------------------
 // trim spaces and lowercase
 public static SimpleRequest CanonicalizeEmail(SimpleRequest input)
 {
     return new SimpleRequest { UserId = input.UserId, Name = input.Name, Email = input.Email.Trim().ToLower() };
 }
        private static RopResult<SimpleRequest, string> ValidateRequest(SimpleRequest input)
        {
            var name50R = Rop.Bind<SimpleRequest, SimpleRequest, string>(Name50);
            var emailNotBlankR = Rop.Bind<SimpleRequest, SimpleRequest, string>(EmailNotBlank);

            return input
                .Pipe(NameNotBlank)  // the first one does not need to be bound
                .Pipe(name50R)
                .Pipe(emailNotBlankR);
        }
 private static RopResult<SimpleRequest, string> NameNotBlank(SimpleRequest input)
 {
     if (input.Name == "")
         return Rop.Fail<SimpleRequest, string>("Name must not be blank");
     else
         return Rop.Succeed<SimpleRequest, string>(input);
 }
 private static RopResult<SimpleRequest, string> Name50(SimpleRequest input)
 {
     if (input.Name.Length > 50)
         return Rop.Fail<SimpleRequest, string>("Name must not be longer than 50 chars");
     else
         return Rop.Succeed<SimpleRequest, string>(input);
 }