Skip to main content
14 votes
Accepted

ASP.NET REST controller with try-catch error handling

throw ex; This is a fatal mistake. It'll create a new stack-trace and you won't be able to tell where the actual exception occured. If you want to rethrow it then ...
t3chb0t's user avatar
  • 44.3k
12 votes
Accepted

C# Rental Program

Disclaimer: if this answer feels like it gets less patient and more "to-the-point" as it goes on, I'm really tired as I am / was writing this and I can't English / logic right now. I promise I mean ...
Der Kommissar's user avatar
7 votes
Accepted

ASP controller for tracking equipment

Index It would appear you primarily do three things here. Sort, Filter, and Page. There's not much to say about your paging, but the sorting and filtering logic clutter the action. Try creating an ...
Shelby115's user avatar
  • 1,961
6 votes

Baseball player statistics controller

Bearing in mind that you claim that you do not to maintain this code anymore1, there are a few suggestions I would have about this code: define functions and accept parameters- that should allow the ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes
Accepted

A controller on a .net core API

Here I will discuss only about your API, I think something may also be changed in your domain model but I don't see enough code to suggest anything really meaningful. You have some code duplication ...
Adriano Repetti's user avatar
6 votes

Connect to MySQL and fetch a list of customers asynchronously using C#

In Get() you do not need to wrap the call to GetAllCustomers() into a Task because it's ...
Adriano Repetti's user avatar
6 votes

User controller for a .net core WebAPI dating app

Errors An assumption: you never ever want to return a 500 HTTP status code (Internal server error). It may leak information you do not want to expose and it's not informative enough. Do not throw ...
Adriano Repetti's user avatar
5 votes

A controller on a .net core API

...
t3chb0t's user avatar
  • 44.3k
5 votes

ASP.NET REST controller with try-catch error handling

Typically in an ASP.NET app (and in fact in any app), you should only catch and handle the base System.Exception in a single place as close to the application entry ...
Matt Cole's user avatar
  • 948
5 votes

Update person name in database

PersonUpdateModel Depending on how sophisticated your Person model is, you might need to consider to extend your update model with middle name Prefixing first name ...
Peter Csala's user avatar
  • 9,279
4 votes
Accepted

Rails Grape API Endpoint optional params validation in update

user.assign_attributes(params) user.save model.assign_attributes(hash) allows you to assign a key value hash to your ActiveRecord object. The only caveat is that ...
Ryan.lay's user avatar
  • 264
4 votes
Accepted

Conversational bot architecture

So, I think that this would be a good opportunity for a generalized service pattern. In general fat controllers are a fairly bad idea, in fact fat methods anywhere are generally a fairly bad idea. ...
photoionized's user avatar
4 votes
Accepted

Request dispatcher for PHP JSON web service

Now, to my best knowledge, $this->request in PHP always points to the HTTP-request when a HTTP-request has just been made My guess is that you are thinking of the super-global ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes
Accepted

Business logic inside MVC Cart Controller method

I think there is more to discuss here then business logic inside your controller. I'm going to generally keep it to a high level of discussion, but feel free to comment and ask for specifics. I'm ...
Conor Mancone's user avatar
4 votes

ASP.NET REST controller with try-catch error handling

The linked post adds a neat summary: So, to sum up: Don’t catch fatal exceptions; nothing you can do about them anyway, and trying to generally makes it worse. Fix your code so that it ...
Flater's user avatar
  • 5,542
4 votes
Accepted

Table View Controller class in Swift

There are quite a few issues here: In switch statement, you don’t need/want break statements. Unlike C languages, Swift ...
Rob's user avatar
  • 2,552
3 votes

Practicing Java servlets, MySQL and JSON - follow-up

AddPersonController content type value should be extracted into a constant or taken from an existing list in a related lib (but I'm not sure there is such list of constants in Servlet API). ...
Antot's user avatar
  • 3,657
3 votes
Accepted

Communication to Child Controller

Having to refer to $scope.$parent is absolutely bad-practice, because dependencies will go up and down and all sorts of ways in your application. It will become a ...
Vadiem Janssens's user avatar
3 votes
Accepted

Email Controller

You do not get bonus points for cramming as many operations on a single line as possible. Strive to make you code more readable and you will find that your end up with code that is easier to read and ...
Mike Brant's user avatar
  • 9,628
3 votes

Spring MVC dynamically adding form elements

Use interface List instead of concrete class for the fieldArrayList field. Make the ...
Ilya Lysenko's user avatar
3 votes

Request dispatcher for PHP JSON web service

I don't recommend emitting these headers so early, and also not as a side-effect of a constructor: ...
200_success's user avatar
3 votes
Accepted

Simple login with jsp

Object Oriented So, from a object oriented perspective, stuff is a bit chaotic. Servlet What bothers me the most is that there's "too much code" in the servlet. Just think about that: What ...
slowy's user avatar
  • 1,866
3 votes
Accepted

Validation and business logic for a form for milling jobs

The class is not a "business logic layer" class, because it is still deeply rooted in the user interface. You cannot execute the logic of this class without a valid form control, and therefore you ...
Greg Burghardt's user avatar
3 votes
Accepted

Decoupling of validation and data access in ASP.NET

I guess you'll find a lot of redundancy in the code since its been held by the controllers. Your idea of making a service is a good idea, you may need to add different services, but at the end you'...
iSR5's user avatar
  • 5,378
3 votes
Accepted

An efficient way to order content in controller [Spring Boot]

Well, you found a workable solution. One thing that strikes out at me is, that you expose the inner structure of your ContentOrderMap by accessing ...
mtj's user avatar
  • 4,822
3 votes

'Lean controller'/'Business logic on service' and filtering, sorting, pagination methods on controllers

Is this separation correct? While helper methods/classes (e.g. EmployeeService::getEmployees()) are nice to have, I would only do that if the same actions are ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Extracting queries from controller to model

This is a good place to use scopes. http://edgeguides.rubyonrails.org/active_record_querying.html#scopes Scopes are just syntactic sugar for class methods that return relations. In this way they can ...
kjprice's user avatar
  • 196
2 votes

AngularJS controller to fetch and display employee data from database

You should create a json object for your errors. Key - error number, value - custom error message. Try to be DRY. Just imagine situation, when i18n will be required.
Kindzoku's user avatar
  • 218
2 votes
Accepted

List enrolled users & show checkmark if all activities are complete

Before looking at the code, there's a simple and immediate option for speeding things up: When a user completes an activity (or a part of one), check the user's other activities, and set an overall <...
Flambino's user avatar
  • 33k

Only top scored, non community-wiki answers of a minimum length are eligible