Skip to main content
deleted 13 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

My Create, Update & DeleteCreate, Update and Delete methods should return a success and errors list depending up on the result. I want to avoid the out parameters in the method. Therefore I came up with an implementation of ResultModel class which gets returned for the above mentioned methods.

Question: Is my implementation elegant enough to go ahead with the real world project? Or there could be other ways to return the Result which are much better? Is my implementation elegant enough to go ahead with the real world project? Or could there be other better ways to return the result?

Here is the sample code which actually works. :) I have inserted comments in the code where I think is necessary.

Here is the Program ClassProgram class to call the above code for testing, it. It also has some helper methods which are mentioned in the MainMain function.

Edit: For validations, I will be using FluentValidation library. So, the Validations I have written here is just a sample (I didn't want to complicate this question's code). For validations, I will be using FluentValidation library. So, the validations I have written here is just a sample (I didn't want to complicate this question's code).

My Create, Update & Delete methods should return a success and errors list depending up on the result. I want to avoid the out parameters in the method. Therefore I came up with an implementation of ResultModel class which gets returned for the above mentioned methods.

Question: Is my implementation elegant enough to go ahead with the real world project? Or there could be other ways to return the Result which are much better?

Here is the sample code which actually works. :) I have inserted comments in the code where I think is necessary.

Here is the Program Class to call the above code for testing, it also has some helper methods which are mentioned in the Main function.

Edit: For validations, I will be using FluentValidation library. So, the Validations I have written here is just a sample (I didn't want to complicate this question's code).

My Create, Update and Delete methods should return a success and errors list depending up on the result. I want to avoid the out parameters in the method. Therefore I came up with an implementation of ResultModel class which gets returned for the above mentioned methods.

Is my implementation elegant enough to go ahead with the real world project? Or could there be other better ways to return the result?

Here is the sample code which actually works. I have inserted comments in the code where I think is necessary.

Here is the Program class to call the above code for testing. It also has some helper methods which are mentioned in the Main function.

For validations, I will be using FluentValidation library. So, the validations I have written here is just a sample (I didn't want to complicate this question's code).

Added a bit more information about Validations.
Source Link
Coder Absolute
  • 453
  • 1
  • 6
  • 15

Edit: For validations, I will be using FluentValidation library. So, the Validations I have written here is just a sample (I didn't want to complicate this question's code).

Edit: For validations, I will be using FluentValidation library. So, the Validations I have written here is just a sample (I didn't want to complicate this question's code).

edited tags; edited title
Link
200_success
  • 145.6k
  • 22
  • 191
  • 480

Elegant Pattern to return Errors as well as result by a method, C# Validation that also returns error messages

add error-handling and design-patterns tags
Link
Loading
Corrected the grammar.
Source Link
Coder Absolute
  • 453
  • 1
  • 6
  • 15
Loading
Source Link
Coder Absolute
  • 453
  • 1
  • 6
  • 15
Loading