Right click on ‘Controllers’ folder –> Add –> New Scaffolded Item… For api controller without views select ‘API Controller with actions, using Entity Framework’ and click ‘Add’.If MVC then choose ‘MVC Controller with views, using using Entity Framework’ On next view select your model (you need create model before generate code) and select data contextContinue reading “Scaffolding in .NET Core (generate API controllers – CRUD (or MVC controller with views in necessary)”
Category Archives: programming
Background automation tasks in .NET Core – sample web application using Hangfire
It is the second post about Hangfire, but this time I am using Hangfire in web application. And there is link to previous post about Hanfire in console application:Background automation tasks in .NET – sample console application using Hangfire I will show a simple web application using Hangfire to automate tasks. First, create a new project:Continue reading “Background automation tasks in .NET Core – sample web application using Hangfire”
Background automation tasks in .NET Core – sample console application using Hangfire
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”
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]:
Git clone fatal: Authentication failed
I recently had a problem with git credentials on Windows and a message like “git clone fatal: Authentication failed for…” Git did not work because the old password was set. In order for git to work again, I had to change the password in Windows settings. To fix this, go to the following path: AndContinue reading “Git clone fatal: Authentication failed”
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.
Run a site using the IIS Express in command line
Useful when we are writing tests and working with Selenium, and we want to inspect some element on page with DevTools. Open a command prompt and run the following command with appropriate paths: This command runs the app on http://localhost:9777