Vladimir Shiyanov
Vladimir Shiyanov

Reputation: 1396

Forcing DTO properties along the path in ServiceStack

I have some DTO class with boolean field IsLocked.

It's easy to build route like

/.../{IsLocked}
and it will assign this field to query value.

But I need something like

/.../lock
/.../unlock
and that is to assing IsLocked field forcibly to true or to false depending on the route.

Can I do that without CustomRequestBinder and without parsing Request.RawUrl?

Thanks in advance for help.

Upvotes: 0

Views: 100

Answers (1)

mythz
mythz

Reputation: 143319

This looks like 2 different operations so I'd look at declaring 2 operations, e.g:

[Route("/files/{FileName}/lock")]
public class LockFile { ... }

[Route("/files/{FileName}/unlock")]
public class UnlockFile { ... }

Otherwise you can declare the routes as normal and return a computed boolean property comparing the string, e.g:

[Route("/files/{FileName}/{LockString}")]
public class LockOrUnlockFile 
{
    public string FileName { get; set; }
    public string LockString { get; set; }
    public bool IsLocked { get { return LockString == "lock"; } }
}

Upvotes: 2

Related Questions