Monday, March 23, 2015

Angular Comparison Validation

Ahh, Angular... Why can't your documentation be as good as what I find on StackOverflow?

Thank you, Bernard Loureiro  for the code sample! From that I was able to put this together.

This directive allows you to compare two different fields on your model. The compareOperator property is really cheesie right now. If it is set, it checks to see if there's an equals and/or a greater than sign. If not, it ignores it. To make that more robust, I'd need to give some good error messages, add some documentation, etc... It works for my needs right now.


Monday, March 16, 2015

Escaping Text for CSV in TSQL

Needed string fields output in CSV, but with punctuation being used, that can be crazy. Figured it out, at least for the cases I'm looking at.


SELECT
cr.Id
,'"' + REPLACE(cr.Description, '"', '""') + '"' AS Descrption
,'"' + REPLACE(rr.Response, '"', '""') + '"' AS Response
,'"' + REPLACE(rr.Reason, '"', '""') + '"' AS Reason
,cr.ResolvedDate
FROM Reviews cr
LEFT OUTER JOIN Responses rr ON cr.Id = rr.ReviewId
ORDER BY cr.Id, rr.Id DESC

Wednesday, February 4, 2015

PrismJS - Code Formatter for blogs

Note to self: Use this when you eventually get around to styling this blog!

http://prismjs.com/

Tuesday, February 3, 2015

MVC Routing and Areas - Can't find your view?

MVC Routing is weird...

We're refactoring an app to use Areas to break up our app into more manageable pieces. I moved some controllers to the new "Internal" area and tried to access it. It couldn't find the controller by accessing ~/Internal/Controller, but my code would be hit if I did ~/Controller, even though the controller had been moved to the new Area.

Even when hit, it couldn't find the view by calling return View(model);

I added a new controller to the area controller's folder and used that namespace for my existing controller.

Now it works! However, my controller will still be hit if I call ~/Controller or ~/Internal/Controller.

MVC must look at the namespace to determine routing, which I think is unfortunate.

So, if you're having an issue with a controller you moved to an area, make sure you have the correct namespace!

Tuesday, October 14, 2014

Array and Model to MVC Controller Method via jQuery Post()

Posting this as a reminder on how to make the jQuery post() method work with MVC when passing an array.


Monday, September 15, 2014

Google OAuth 2 - The Hard Way

So... Google has deprecated their old single signon code. Unfortunately I'd added that code to 3 different applications. So, we need to move forward!


I tried using the Microsoft WebPages OAuth Library, but the Google provider wouldn't work properly. Tried following the directions here

http://www.beabigrockstar.com/blog/google-signin-for-asp-net-mvc/

... but I was too stupid to "get it" and make it work. Getting weird errors on Google's end. I was already on 2 urgent projects, and now I have to make our Google login work again. It's just web requests, right? I can do some requests, no biggie. Found this site...

https://developers.google.com/oauthplayground/

which is everything the Google OAuth documentation isn't. Gave me everything I needed! Used a lot of code from Jerrie Peelser's blog (http://www.beabigrockstar.com/) which was a huge help. I'm thinking maybe the permissions from the Google dev site just hadn't propagated. Regardless, I created a helper class that just "does it".

You can modify it to suit your needs.

The "GetLoginRedirectUrl" code can be modified to specify which API's you want to access. The "GetAuthenticatedUserEmail" method is just a stupid simple method I use to get the email address. You can request any API that you put in the "GetAuthenticatedUserEmail" method no problem.

I hope you find this useful!

Tuesday, July 22, 2014

Cheesie simple modal dialog

From time to time I have to work on projects where I have old versions of libraries, like jQuery, and I can't upgrade them. Yet, I need some features of libraries I like to use, like Bootstrap. This time, I needed a simple wait dialog that would show up, then go away when I needed it to. I'm working with jQuery 1.4.4 and jQueryUI is just too much for what I'm doing.

So, I found a great article on the web for a simple CSS positioned modal dialog.

http://blog.raventools.com/create-a-modal-dialog-using-css-and-javascript/

And my version is below. All I really changed is some styling, added a variable for content, which I'm setting statically, and have the styles inline instead of in a separate style sheet. This is a quick and dirty fix for a dying project. I've done a better version with bootstrap/angular but that's a different post :)