Archive for Uncategorized

Using Breeze with IHttpActionResult

I came up with a solution for this as I was writing out my question on stackoverflow.com – I love when that happens!

I’m implementing measures on my controllers to prevent users from being able to access information that they shouldn’t have permission to.

I’m looking into having my controller methods return an IHttpActionResult. Consider this simplified example:

[HttpGet]
[BreezeQueryable]
public IHttpActionResult FindById(int id)
{
    // implementation of DoesUserHavePermission not relevant
    var canAccess = DoesUserHavePermission(id); 
    if (canAccess)
        return Ok(_uow.Repo.All().Where(r => r.Id == id).FirstOrDefault());
    else
        return NotFound();
}

On the client-side, it would look something like this:

return uow.Repo
    .findById(id)
    .then(function (results) {
	if (results[0] == undefined) {
    	    router.navigate(notFoundRoute);
	}
	else {
	    myEntity(results[0]);
	}
    })
    .fail(function (e) {
        // log an error
    });

This works great when you have a result, but if the controller returns a NotFound the call to findById actually fails because the call to the controller came back with a 404 status code.

Turns out a super easy way to handle this is to check the value of e.Status in the fail handler:

return uow.Repo
    .findById(id)
    .then(function (results) {
	if (results[0] == undefined) {
    	    router.navigate(notFoundRoute);
	}
	else {
	    myEntity(results[0]);
	}
    })
    .fail(function (e) {
        if (e.status = 404)
            router.navigate(notFoundRoute);
        else
            // log an error
    });

FYI that this is a SPA using BreezeJS and DurandalJS.

New Ink

I sat for couple of tattoo sessions back in December at The Dolorosa Tattoo Company in Studio City with Christina Hock.

I wanted to get a tattoo of Phoebe over some cross-bones, and her name on a collar tag. Christina did a great job coming up with this design. This went on my lower left arm – first time under the elbow.

Instagram Photo

The next day I went in to get the lily tattoo on my shoulder redone. I’ve been wanting to redo this with bolder colors and outlining. Really happy with how it turned out.

Instagram Photo

Now available! Programming Microsoft’s Clouds: Windows Azure and Office 365

I wrote a couple of chapters for Programming Microsoft’s Clouds: Windows Azure and Office 365   about Exchange Online and Lync Online in Office 365. The book is available for purchase now on Amazon in paperback and Kindle format.

Microsoft has obviously made a huge push into the cloud. Most of our projects today have a component running in the cloud, whether its a database running in SQL Azure, a service running in a Windows Azure Worker Role, or sometimes the whole shebang running in Windows Azure.

The introduction of Office 365 also opens up a lot of possibilities to companies wanting to use and pay for products such as SharePoint, Exchange, or Lync in a subscription model. As a small business or even an enterprise, those subscription rates are extremely compelling.

In the current incarnation of Office 365, the online versions of SharePoint and Lync offer up a portion of the development experience and capabilities available in their on-premises brethren.

Expect the developer story here to improve in upcoming versions of Office 365; until then, this book provides some great guidance for dealing with those challenges and building real-world applications on top of these technologies.

Hello LA!

Big changes in the Durzi family!

We moved back to Los Angeles a few weeks ago. The move was almost a year in the making and we were finally able to make it happen after selling our place in Chicago. We got a house in an area called Lake Balboa, just North of Encino in the Valley.

Loved the 7 years we spent in Chicago, but really happy to be back in LA. Looking forward to year-round outdoor activities and farmers markets!

And most of all, swimming outside!

I recently joined Southern California Aquatics, a United States Masters Swimming club that practices at pools throughout the LA area. My new pool – the Van Nuys / Sherman Oaks Aquatics Center is pretty darn awesome!

 

Hello world!

I’ve had this domain for as long as I can remember but there’s never been anything on it. I’ve actually never even had a personal website, so I figure it’s about time I put some effort into building my own brand on the internet.

I plan to use this blog to post about interesting things I’m doing at work, and personal interests such as swimming, food, and mixology.

Welcome, and stay tuned!