Posts

Call CRUD(GET, POST, PUT, DELETE) API using HttpClient in c#

Here We will see how we can call all CRUD methods (GET, PUT, POST, DELETE) with the help of HttpClient in c#. 1. Call POST API :- string url = "http://localhost:26404/api/POSTAPI"; HttpClient httpClient = new HttpClient(); HttpResponseMessage APIResponse = new HttpResponseMessage(); var obj = new { name = "Amit", age = 26, subject = "c#" }; var objJson = JsonConvert.SerializeObject(obj); var stringContent = new StringContent(objJson, UnicodeEncoding.UTF8, "application/json"); APIResponse = httpClient.PostAsync(url, stringContent).GetAwaiter().GetResult(); var resultJson = APIResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult(); 2. Call GET API :- string url = "http://localhost:26404/api/GETAPI"; HttpClient httpClient = new HttpClient(); HttpResponseMessage APIResponse = new HttpResponseMessage(); APIResponse = httpClient.GetAsync(url).GetAwaiter().GetResult(); var resultJson = APIResponse.Content.ReadA...

Sending Base64 Image Data As Attachment With Mail Using ASP.NET MVC

In this post we will discuss about how to send base64 image data as attachment on email using asp.net mvc c#. MailController.cs :- using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Net.Mime; using System.Text; using System.Web; using System.Web.Mvc; namespace SendMail.Controllers {     public class MailController : Controller     {         public ActionResult Index()         {             return View();         }         public ActionResult SendMailWithAttachment()         {             string to_email = "receiver@gmail.com";             var from_email = "sender@gmail.com";             var subject = "Testing email sending functionality";             va...

Sending An E-Mail Using ASP.NET MVC

 In this post we will discuss about how mail is sent from ASP.NET MVC application. MailController.cs :- using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Mail; using System.Web; using System.Web.Mvc; namespace  SendMail .Controllers {     public class MailController : Controller     {         public ActionResult Index()         {             return View();         }         public ActionResult SendMail()         {             string to_email = "EmailId of the one to whom the mail is to be sent";                          var from_email = "EmailId of the one who will send the mail";             var subject = "Testing email sending functionality";   ...

Auto complete input textbox using jquery in ASP.NET MVC

 Auto complete input textbox with jquery in ASP.NET MVC In this post we will discuss about how to perform auto complete with input text box using jquery in asp.net mvc. AutoCompleteAddressController.cs :- using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace Learn_mvc.Controllers {     public class AutoCompleteAddressController : Controller     {         public ActionResult Index()         {             return View();         }         public ActionResult AutoSearchModel()         {             return View();         }         public ActionResult FetchModels(string query)         {             var models = new List<ModelMachine...

CRUD Operation Using Jquery Ajax In ASP.NET MVC

CRUD operation with jquery ajax in asp.net mvc In this post we will discuss about how to do CRUD with the help of jquery ajax. here we will take two file one is .cshtml file and one is .cs file. .cshtml file is our view and .cs file will handle DB operation. In this example I am creating a static list for creating records. I have .cs controller file this file name is JqueryAjaxController.cs. And .cshtml file this file name is Index.cshtml. JqueryAjaxController.cs :- using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using System.Web.Mvc; namespace Learn_mvc.Controllers {     public class JqueryAjaxController : Controller     {         private static List<JAEmp> emps = new List<JAEmp>() {                 new JAEmp(){ EmpId="101", EmpName="Aman", EmpSalary="1000"},               ...

Asp.Net MVC 5 authentication and authorization using claims principal

Asp.Net MVC 5 authentication and authorization using claims principal :- Step1 : File -> New Project -> Asp.Net Web Application -> Asp.Net 4.5.2 Templates Choose empty MVC project template Step2 : Install following nuget packages Microsoft.AspNet.Identity.Core Microsoft.AspNet.Identity.Owin Microsoft.Owin Microsoft.Owin.Host.SystemWeb Microsoft.Owin.Security Microsoft.Owin.Security.Cookies Microsoft.Owin.Security.OAuth Owin Step3 : Create a Owin Startup class and decorate with assembly attribute OwinStartup. using Microsoft.AspNet.Identity; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; [assembly: OwinStartup(typeof(AspNetMVC5Authorization.Startup))]  // here "AspNetMVC5Authorization" is the name of project namespace AspNetMVC5Authorization { public class Startup { public void Configuration(IAppBuilder app) { ConfigureAuthenticat...

Call CRUD(GET, POST, PUT, DELETE) API using WebClient in c#

          Here We will see how we can call all CRUD methods (GET, PUT, POST, DELETE) with the help of WebClient in c#. you will need to add reference of "System.Web.Extensions" assembly to your project. 1. Call POST API :-     string apiUrl = "http://localhost:26404/api/POSTAPI";     object input = new     {         Name = txtName.Text.Trim()     };     string inputJson = (new JavaScriptSerializer()).Serialize(input);     WebClient client = new WebClient();     client.Headers["Content-type"] = "application/json";     client.Encoding = Encoding.UTF8;     string json = client.UploadString(apiUrl + "/PostCustomers","POST", inputJson); 2. Call GET API :-     string apiUrl = "http://localhost:26404/api/GETAPI";     WebClient client = new WebClient();     client.Headers["Content-type"] = "app...

How to breakpoint or debug on .ts page in angular

Image
Hello Guys, In this post we will talk about how to debug angular components Step 1 :-              I have an angular project which name is “Hello-World” . Step 2 :-             Run this “Hello-World” project using   below command :-             ng serve   Step 3 :-             Open running project in “Chrome” browser. And then do “inspect” , for “inspect” right click on “chrome” browser and click on “inspect” option. Step 4 :-             And now go to “sources” tab. Then go to “page -> webpack:// -> . -> src -> app” and here you can see your project component pages. Choose any your project component page folder. Here I am selecting my component folder “detail” . This folder contains .h...

How to Add/Push and Remove Form fields dynamically with validation to FormArray with Reactive Forms in Angular

Image
Add/Push and Remove Form fields dynamically with validation to FormArray with Reactive Forms in Angular This article explains how we can add and remove  inputbox  dynamically to and from  FormArray with required validation Step 1 :- First we will create a project using below command :- ng new myApp Step 2 :- Now we will add bootstrap cdn in our project so open "Index.html" file and follow below code Index.html :- <! doctype   html > < html   lang = "en" > < head >    < meta   charset = "utf-8" >    < title > HelloWorld </ title >    < base   href = "/" >    < meta   name = "viewport"   content = "width=device-width, initial-scale=1" >    < link   rel = "icon"   type = "image/x-icon"   href = "favicon.ico" >    < link   rel = "stylesheet"   href = "ht...

How to add Side bar menu in Ionic 4 blank project

How to add Sidemenu bar in Ionic 4 application In this post, we will see how can we add SideDrawer in Ionic 4 blank project. Step 1 :- first create a blank ionic project using below command :- ionic start myApp blank Step 2 :- now I will create 4 pages which name will be "home", "profile", "notification", "setting" using below command :- ionic g page home ionic g page profile ionic g page notification ionic g page setting app-routing.module.ts :- import { NgModule } from '@angular/core'; import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; const routes: Routes = [   { path: '', redirectTo: 'home', pathMatch: 'full' },   { path: 'home', loadChildren: './home/home.module#HomePageModule' },   { path: 'profile', loadChildren: './profile/profile.module#ProfilePageModule' },   { path: 'notification...