Skip to main content

Posts

Showing posts with the label dotnet7

.NET 7 Web API CRUD Operation Using One-Many Relationship Tables

In this article, we will implement a CRUD Operation in Web API using one-many relationship tables. Web API: Web API is a framework for building HTTP services that can be accessed from any client like browser, mobile devices, and desktop apps. In Simple terminology API(Application Programming Interface) means an interface module that contains a programing function that can be requested via HTTP calls either to fetch or update data for their respective clients. Some of the key characteristics of API: Support HTTP verbs like 'GET', 'POST', 'PUT', 'DELETE', etc. Support default responses like 'XML' and 'JSON'. Also can define custom responses. Supports self-hosting or individual hosting, so that all different kinds of apps can consume it. Authentication and Authorization are easy to implement. SQL Script For One-Many Relationship Tables: For this demo, we are going to create sample tables like 'Customer' & 'CustomerAddresses&

Part-4 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Phone

The main objectives of this article are: Sending Two-Factor Authentication(2FA) Code to Phone Enable Phone 2FA: In the Asp.Net Core Identity application to enable 'Phone' Two-Factor Authentication, ensure our 'AspNetUser' table following fields has appropriate data: PhoneNumber - Should have valid phone number along with country code PhoneNumberConfirmed - must be true TwoFactorEnabled - must be true Twilio Setup: Twilio is a third-party service provider which provides services like SMS, Voice Calls, Chats, etc. (Step 1) Go to the Twilio website 'https://www.twilio.com/' and SignUp. (Step 2) Now Login => We entered into the Twilio console dashboard => Here create a project and you will get 'Account SID', 'Auth Token', and 'My Twilio Phone Number(which will be our From Phone Number). (Step 3) I'm going to use the Free credits to set up the SMS service. So here is one limitation with free credits we have to register all testing &

Part-3 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Email

The main objectives of this article are: Sending Two-Factor Authentication(2FA) Code To Email Enable Email 2FA: In Asp.Net Core Identity application to enable email Two-Factor Authentication, make sure our 'AspNetUser' table following fields has appropriate data: Email - Should not be empty or null EmailConfrimed - must be true TwoFactorEnabled - must be true. Now if we try to login into our application we can see a page to enter the 2FA code like below Send Two-Factor Authentication(2FA) Code To Email: Now let's update the code in 'OnGetAsync()' method in 'Areas/Identity/Pages/Account/LoginWith2faModel.cshtml.cs' as below. Areas/Identity/Pages/Account/LoginWith2faModel.cshtml.cs: public async Task<IActionResult> OnGetAsync(bool rememberMe, string returnUrl = null) { // Ensure the user has gone through the username & password screen first var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { throw ne

Part-2 | Asp.Net Core Identity Series[.NET 7] | Registration Email Confirmation

The main objectives of this article are: Use SendGrid Email Service. Implement Email Confirmation For User Registration Send Grid: SendGrid is a third-party email provider from which we deal with 'send' and 'receive' operations of email to our application. SendGrid SMTP(Simple Mail Transfer Protocol) provider for email transfer. SendGrid also provides SendGrid .Net NuGet package that provides easy configuration to any .NET application. So to use the SendGrid SMTP we need 'Auth Key', 'From Email'. So let's register into SendGrid. The following are the steps to register and generate the API key in SendGrid: (Step 1) Go to SendGrid's official website at 'https://sendgrid.com/'. Next do SingUp. (Step 2) Now login in to the SendGrid website, then under the left-hand side menu go to the 'Settings' ==> 'Sender Authentication'. At 'Single Sender Verification' click on the 'Get Started' button. (Step 3) Let'

Part-7 | .NET7 Web API | SQL Database | VueJS(3.0) - Composition API | CRUD Example

The main objectives of this article are: Create HTTP Delete Endpoint In API Project. VueJS Application To Invoke The Delete API. Create HTTP Delete Endpoint In API Project: Let's create the HTTP Delete endpoint in the API project. API_Project/Controllers/BeachController.cs: [HttpDelete] [Route("{id:int}")] public async Task<IActionResult> Delete(int id) { var beachToDelete = await _myWorldDbContext.Beach.FindAsync(id); if (beachToDelete == null) { return NotFound(); } _myWorldDbContext.Beach.Remove(beachToDelete); await _myWorldDbContext.SaveChangesAsync(); return Ok(); } (Line: 1)The 'HttpDelete' attribute allows only HTTP delete requests to consume the action method. (Line: 2) The 'Route' attribute is defined where we need to pass the integer 'id' value in the route. (Line: 5) Based on the 'id' value try to fetch the record from the database. (Line: 6-9) Checking whether records exist in the database or not. (Line: 10) U