Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post(int customerId, [FromBody] CustomerDto dto)
        {
            var logSuccessR     = LogSuccessR <CustomerDto>("Post {0}");
            var dtoToCustomerR  = Rop.Bind <CustomerDto, Customer, DomainMessage>(DtoConverter.DtoToCustomer);
            var upsertCustomerR = Rop.Bind <Customer, Unit, DomainMessage>(_dao.Upsert);
            var logFailureR     = LogFailureR <Unit>();
            var okR             = Rop.Lift <Unit, IHttpActionResult, DomainMessage>(this.Ok);

            dto.Id = customerId;                                      // set the DTO's CustomerId

            var dtoR = Rop.Succeed <CustomerDto, DomainMessage>(dto); // start with a success

            return(dtoR                                               // start with a success
                   .Pipe(logSuccessR)                                 // log the success branch
                   .Pipe(dtoToCustomerR)                              // convert the DTO to a Customer
                   .Pipe(upsertCustomerR)                             // upsert the Customer
                   .Pipe(logFailureR)                                 // log any errors
                   .Pipe(okR)                                         // return OK on the happy path
                   .Pipe(ToHttpResult));                              // other errors returned as BadRequest, etc
        }
Ejemplo n.º 3
0
        public IHttpActionResult Get(int customerId)
        {
            var logSuccessR       = LogSuccessR <int>("Get {0}");
            var createCustomerIdR = Rop.Bind <int, CustomerId, DomainMessage>(DomainUtilities.CreateCustomerId);
            var getByIdR          = Rop.Bind <CustomerId, Customer, DomainMessage>(_dao.GetById);
            var customerToDtoR    = Rop.Lift <Customer, CustomerDto, DomainMessage>(DtoConverter.CustomerToDto);
            var logFailureR       = LogFailureR <CustomerDto>();
            var okR = Rop.Lift <CustomerDto, IHttpActionResult, DomainMessage>(this.Ok);

            var idR = Rop.Succeed <int, DomainMessage>(customerId);    // start with a success

            return(idR
                   .Pipe(logSuccessR)       // log the success branch
                   .Pipe(createCustomerIdR) // convert the int into a CustomerId
                   .Pipe(getByIdR)          // get the Customer for that CustomerId
                   .Pipe(customerToDtoR)    // convert the Customer into a DTO
                   .Pipe(logFailureR)       // log any errors
                   .Pipe(okR)               // return OK on the happy path
                   .Pipe(ToHttpResult));    // other errors returned as BadRequest, etc
        }