ASP.NET Web API allows only one body parameter in POST

Say with me, “ASP.NET Web API allows only one body parameter in POST”. And again, “ASP.NET Web API allows only one body parameter in POST”. Now repeat it 100 times.

It’s tiresome and probably utterly unnecessary. But that’s the only way to remember it. Believe me. I keep falling in the trap and repeating the same mistake over and over. I have wasted countless hours on this simple, stupid thing.

Don’t be like me. Memorize this mantra. Do it now. Do not delay it.

You know my pain if you have ever received this super-generic message and spent a gazillion fertile hours googling for a solution.

No action was found on the controller that matches the request

It’s like being told that your car cannot be driven because a part is missing. But, wait! Which part? Which f**k**g part? If you have been through this pain, you are my friend.

There could be countless reasons for this error. Perhaps you tried to access the wrong URL. Perhaps you used the wrong HTTP method. Perhaps you misspelled a parameter name.

Or, if you are like me, perhaps you had more than one parameter in a POST API method. Like this:

public async Task<HttpResponseMessage> AddProduct(int productId, string productName)
{
     ...
}

You were probably anticipating multiple values for an entity called Product in your HTTP POST request. So you created your API method like this in a bout of natural instinct. You were not wrong. ASP.NET is stupid. Because it allows for only one POST body parameter, it forces you to create a separate class to handle multiple parameters.

Do this to fix your woes:

public class Product
{
    int productId { get; set; };
    string productName { get; set; }
}
 
public async Task<HttpResponseMessage> AddProduct(Product prod)
{
    ...
}

Unjumble — You won’t lose that jumbled words game again

Another of my free time exercises, Unjumble does just that – it unscrambles a jumbled/scrambled word into all possible English dictionary words that can be formed out of that jumbled word. The interface is extremely simple. You have a textbox to input your jumbled word, and as you type, all unjumbled word suggestions start appearing as list items in the combobox below. To copy an unjumbled word to clipboard, just click on it. Simple, isn’t it?

Like QuickCopy, Unjumble was coded in C#, and makes use of SQLite as the portable database to store a huge list of English dictionary words. What’s the most interesting thing about this little app is the algorithm behind it.

There is a pre-prepared database of almost all (58000+) English words [wordlist.txt], stored along with their hashes (words formed by the original words’ individual alphabets in sorted order). The input jumbled word’s hash is then calculated in a similar way, and is compared with the hashes stored in the database. All matches are then displayed in the list box.

I bet, using Unjumble, you’ll never lose your newspaper’s jumbled words game again. 😉

Download: Source Code (1.5 MB) – Installer (1.7 MB)

QuickCopy — No typing that password again

A very simple password management tool that I developed in my free time. It aims to simplify the task of copy-pasting frequently used text, like usernames and passwords. A Windows-only tool, it’s code purely in C#, and makes use of the wonderfully portable SQLite to store entries in the backend. The interface includes 2 components (basically 3; one is hidden) — system tray icon and “add content” dialog. All content added through the dialog gets added as a menu item in the system tray icon’s context menu (the one you see on right-clicking the icon). To copy a content from the menu to the clipboard, all you need to do is just click on its entry in the menu and it’s done!

Some features:

  • Store content – frequently used text, like usernames.
  • Store passwords – these are masked by content tags, which are then shown in the context menu (in red color).
  • Hotkeys – the top 3 entries in the context menu can be quickly copied to the clipboard using the key combinations of CTRL+F1, CTRL+F2 and CTRL+F3.

For a password, its respective content tag acts as a mask to hide it under its name. Say you’re adding your Gmail password @ILuvKatz!! in the dialog, and set its content tag as Gmail Password, the password’s entry will appear in the menu in red color with the name Gmail Password. When you click on Gmail Password, your actual password will be copied to the clipboard.

There is no easy provision of modifying existing content entries. But I’ve provided a QueryEditor (invoked by pressing CTRL+Q in the “Add Content” dialog), where you can change the content entries by issuing your regular SQL queries. For example:

UPDATE content SET content='@IHateKatz!!' WHERE content_tag='Gmail Password'

Download: Source Code (1.1 MB) – Installer (1.2 MB)

Some C++ programs

Update:
As requested by Sajith Karingat (comment #29), I worked on a Phone Billing System in C++, as per his requirements. You can download it here.

I have entered my final year in my B.Tech course, and with it, it’s placement time. Companies for the computer science stream (my stream) will start visiting my college beginning from 11th August. The first to come will be TCS (Tata Consultancy Services) which is considered as a good IT firm in India with global fame.

As part of my prep for the placements, obviously, I am revising my concepts (technical ones). Today, as it was raining heavily in the college, we sat in our central canteen, waiting for the rain to stop. During that time, we held a heated discussion on C++ programs that were most likely to be asked in interviews for placements.

Amongst those programs, one was to swap the values of two variables “a” and “b” without using the “temp” variable. Another interested one we discussed was that would generate a pattern like:

1
2 3
4 5 6
7 8 9 10
11 12 13 14
…… and so on.

When I got back home, I decided to have a go on these programs. And so, here are my answers to above problems.

Continue reading Some C++ programs