I will show a simple console application using Hangfire to automate tasks. First, create a new project: Console App (.NET Core). In my case netcoreapp3.1: Install Hangfire – add packages:Hangfire.CoreHangfire.SqlServer Copy the following code to the Main method: We also need to add namespaces: And the last step, create a database. Go to SSMS andContinue reading “Background automation tasks in .NET Core – sample console application using Hangfire”
Category Archives: C#
AutoMapper – map one list to another
Create a mapping from list to list: So e.g: Where ‘cars’ is of the List type and of course before it, we need to add a map to AutoMapper config with the .CreateMap and .ForMember methods for the appropriate properties if needed.
FileResult in controller and returning NotFound
Return NotFound() in FileResult. Just change return type to ActionResult, because FileResult inherits from ActionResult. And then it is possible to return NotFound() e.g. when object equals null. So FileResult -> ActionResult, something like this:
Passing argument to Main method in Visual Studio
To pass arguments to Main method in Visual Studio we can go to the following path: We can write down new arguments there: And we can use our added arguments with args[] and the appropriate index e.g. args[0], args[1]:
How to stop void method (return in void method)
This is quick blog post about stopping executing void method. So, how to stop executing void return type method? We just need to use ‘return’ statement itself, for example: If we pass 0 as first argument then we won’t get print from next line.