ASP.NET MVC, MVC, C#, PYTHON, JQUERY

Friday, July 3, 2020

Insert,Update and Delete Using Asp.net MVC



 In this article, we will learn about how to Insert, Update and Delete Records in ASP.NET MVC 5.

LET'S START ASP.NET MVC 5 WITH 

 In this example, I am going to create a simple student registration form in MVC5 using CRUD  (Create, Read, Update and Delete) Operation. In this tutorial, We will use  entity framework.

 <pre>
 <code class="csharp">
public List<RecruitmentRegistrationModel> GetUserRegistrationRecord(RecruitmentRegistrationModel model, int ProcId)
        {
            var sqlParam = new SqlParameter[]{
                          new SqlParameter { ParameterName = "@ProcId" , Value =ProcId },
                          new SqlParameter { ParameterName = "@Id" , Value =model.ApplicationPostId },
                          new SqlParameter { ParameterName = "@Gender" , Value =model.Gender??"" },
                          new SqlParameter { ParameterName = "@Age" , Value =model.Age??0 },
                          new SqlParameter { ParameterName = "@TotalExp" , Value =model.TotalExp??0 },
                          new SqlParameter { ParameterName = "@EmployerType" , Value =model.EmployerType??"" }
                    };
            var sqlQuery = @"proc_GetUserRegistrationRecord @ProcId,@Id,@Gender,@Age,@TotalExp,@EmployerType";
            var res = this.Database.SqlQuery<RecruitmentRegistrationModel>(sqlQuery, sqlParam).ToList();
            return res;
        }
                               </code></pre>





Share:

Monday, June 29, 2020

Download All Files In ZIP Format In Asp.Net MVC.NET



Hello Friends In this article, we will create a application for download all media file’s in zip format. We have to follow some simple steps to create a project and export some files in zip format in ASP.NET MVC
Step 1 – Create a Project
Opening Visual Studio, next, we need to create an ASP.NET MVC project. For doing that, just click File – New – Project.
After choosing a project, a new dialog will pop up. In that, select ASP.NET Web Application in the Web tab and give your project the location and a name. Then, click the “Ok” button. Choose the MVC Template.
Step 2: Install the SharpZipLib from Nuget package console
Install-Package SharpZipLib
Install-Package SharpZipLib


Step 3 – Create a Action Method in Controller for Download zip file
Write code into Our DownloadZipController and give Media file path into List for Media file that you want to download in the zip file and create a folder named DownloadedMedia in root directory. Right now, I gave the static image path but you can set dynamic image path according to your requirements.
using System;
using System.Drawing;
using System.Web;
using System.Web.Mvc;
using System.Xml.Linq;
using ICSharpCode.SharpZipLib.Zip;
namespace DownloadZipProject.Controllers
{
  public class DownloadZipController:Controller
  {
    private DataAccessLayer _db = new DataAccessLayer ();
    public FileResult DownloadMediaFilesInZip ()
    {
      var FileName = string.Format ("{1}_AllDocumentsFiles_{0}.zip",
    DateTime.Today.
    Date.ToString ("dd-MM-yyyy") + "_1",
    SessionManager.ApplicantUserName);
      var OutPutTempPath =
Server.MapPath (Url.Content ("/DownloadedMedia/") + FileName;
using (ZipOutputStream s =
       new ZipOutputStream (System.IO.File.Create
    (OutPutTempPath)))
{
s.SetLevel (9);
/byte[]buffer = new byte[4096];
var AllMediaList = new List < string > ();
DataSet ds = _db.RecruitmentApplicationPrint ();
var MediaFilesList = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
MediaFilesList.Add (Server.MapPath
    (ds.Tables[1].Rows[i]["DocPath"].
     ToString ()));}
for (int i = 0; i < MediaFilesList.Count; i++)
{
ZipEntry entry =
new ZipEntry (Path.GetFileName (MediaFilesList[i]));
entry.DateTime = DateTime.Now;
entry.IsUnicodeText = true; s.PutNextEntry (entry);
using (FileStream fs =
       System.IO.File.OpenRead (MediaFilesList[i]))
{
int sourceBytes;
do
{
sourceBytes = fs.Read (buffer, 0, buffer.Length);
s.Write (buffer, 0, sourceBytes);}
while (sourceBytes > 0);}
}
s.Finish (); s.Flush (); s.Close ();}
byte[]finalResult =
System.IO.File.ReadAllBytes (OutPutTempPath);
if (System.IO.File.Exists (OutPutTempPath)) System.IO.
File.Delete (OutPutTempPath);
if (finalResult == null
    || !finalResult.
    Any ())throw new Exception (String.
Format
("No Media File found"));
return File (finalResult, "application/zip",
     fileName);}
}
Step 4 – Implement button on view page for download Media files from the view side
Share:

Sunday, May 31, 2020

Program for Betting in Dice Game

Code Description:
   This program is basically showing random number after rolling dice. Here are two dice where total count value is between 2 to 12. User can play this game and bet their amount on given 3 choice as per instructions.

Source Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ConsolePractice
{
    class Program
    {
        static void Main(string[] args)
        {

           DiceGame();

        }

        public static void DiceGame()
        {
            string name;
            int betamount, betChoice, DiceNumber;

            Console.WriteLine("==================Dice Game==================");
            Console.WriteLine("===========================================================");

            Console.WriteLine("You have three option for play Dice Game\nAfter entering your good name and deposit the betting amount.\n");

            Console.WriteLine("Option-1: Dice Number should between 1 to 5 ~~Winning Amount Double\nOption-2- Dice Number should between 6 to 7 ~~Winning Amount Triple\nOption-3: Dice Number should between 8 to 12 ~~Winning Amount Double\n");
            Console.WriteLine("Your Lucky Name");
            name = Console.ReadLine();
            Console.WriteLine("Your bet Amount");
            betamount = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Choose your Choice between 1,2 or 3");
            betChoice = Convert.ToInt32(Console.ReadLine());
            Random ran = new Random();
            DiceNumber = ran.Next(2, 13);

            if (betChoice==1)
            {
                Console.WriteLine("Dice is rolling . . . .");
                Thread.Sleep(2000);
                Console.WriteLine("Dice Result is {0}", DiceNumber);
                if (DiceNumber<=5)
                {
                    Console.WriteLine("Hi," + name + " your bet amount is " + betamount + " and You Win !! Your amount is now " + (betamount * 2));
                    
                }
                else
                {
                    Console.WriteLine("Oops!! Sorry" + name + ", You Loose !");

                }
            }
            else if (betChoice==2)
            {
                Console.WriteLine("Dice is rolling . . . .");
                Thread.Sleep(2000);
                Console.WriteLine("Dice Result is {0}", DiceNumber);
                if (DiceNumber==6 || DiceNumber==7)
                {
                    Console.WriteLine("Hi," + name + " your bet amount is " + betamount + " and You Win !! Your amount is now " + (betamount * 3));
                }
                else
                {
                    Console.WriteLine("Oops!! Sorry" + name + ", You Loose !");
                }
                
            }
            else if (betChoice==3)
            {
                Console.WriteLine("Dice is rolling . . . .");
                Thread.Sleep(2000);
                Console.WriteLine("Dice Result is {0}", DiceNumber);
                if (DiceNumber>=8)
                {
                    Console.WriteLine("Hi," + name + " your bet amount is " + betamount + " and You Win !! Your amount is now " + (betamount * 2));
                }
                else
                {
                    Console.WriteLine("Oops!! Sorry" + name + ", You Loose !");
                }
            }
            else
            {
                Console.WriteLine("Wrong Choice!! Choose correct Option.");
            }
            Console.ReadLine();
        }
    }

}

Output:


Share:

Program for swap two integer values

Source Code:

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            SwapNumbers();
        }
       
        //Swap two numbers
        public static void SwapNumbers()
        {
            int a = 10, b = 5;
            Console.WriteLine("Before swapping numbers are a={0},b={1}", a, b);
            a = a - b;
            b = a + b;
            Console.WriteLine("After swapping numbers are a={0}, b={1}", a, b);
            Console.ReadLine();
        }
     }
}

Output:

Share:

Thursday, September 13, 2018

Half pyramid program for fibonacci series



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fibonaccipyramid
{
    class Program
    {
        static void Main(string[] args)
        {
            int i,a=0,b=1,n,c,j,k;
            Console.WriteLine("Enter the limit");
            n=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(a);
            Console.WriteLine(b);
            for (i = 1; i <= n; i++)
            {
         
                for (j = 1; j <= i; j++)
                {
               
                        c = a + b;
                        a = b;
                        b = c;

                        Console.Write(c);
                        Console.Write("\t");
               
            }
                Console.Write("\n");
            } Console.ReadLine();
        }
    }
}



Share:

Wednesday, September 12, 2018

Factorial program using recursion in c#




We have come across the situations where a function calls another function but there is one more possibility that a function calls itself.
When a function calls itself it is known as recursion. It is usually used where we have to repeat a process again and again.
The following program for finding factorial using recursion is an example of recursive function and its implementation.

  1. using System;    
  2.     
  3. namespace Recursion_Example   
  4. {    
  5.     class Program    
  6.     {    
  7.         static void Main(string[] args)    
  8.         {    
  9.            int n;
  10.             Console.WriteLine("Enter the Number");    
  11.     
  12.                
  13.              n =Convert.ToInt32(Console.ReadLine());     //read number from user
  14.     
  15.             double factorial = Factorial(n);    //invoke the static method    
  16.     
  17.             //print the factorial result    
  18.             Console.WriteLine("factorial of"+n+"="+factorial.ToString());    
  19.     
  20.         }    
  21.         public static double Factorial(int n)    
  22.         {    
  23.             if (n == 0)    
  24.                 return 1;    
  25.             return n * Factorial(n-1);//Recursive call    
  26.     
  27.         }    
  28.     }    
  29. }    
Share:

Friday, September 7, 2018

Main() Method In C#

Main() Method In C# 

Hello Friends In this article we will learn about What is Main() Method in C#.



  • Main() Method is an entry point of an application.
  • Main () Method means That execution of code start from Main() method.
  • When an application starts Execution C# compiler looks for in the source file is the Main() method.
  • You must include Main () method in a class make your program executable.


Example:-

public Class HelloCsharp
{
public static void Main(string[] args)  //Main () method 
System.Console.WriteLine("Hello Friends Welcome To Csharp4tech");
}
}
Share:

How to Find Factorial Using C#

            How to Find Factorial  Using C#

using System;
namespace FactorialDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int iCount, iUserNumber, iFact;
            Console.WriteLine("Please Enter A Number For Finding Factorial ");
            iUserNumber = Convert.ToInt32(Console.ReadLine());
            iFact = iUserNumber;
            for (iCount = iUserNumber  - 1; iCount &gt;= 1; iCount--)
            {
                iFact = iFact * iCount;
            }
            Console.WriteLine("Factorial of Entered Number {0}", iFact);
            Console.ReadLine();
        }
    }
}
Share:

C# Programming Structure

Classes in C#

C# classes are the primary building blocks of the language.C#  also provides some predefined set of classes and methods.These classes and Methods Provides various basis functionalities that you may want to implement in your Application.
Creating  First "Hello World" Program
Using System;
public class Hello
{
public static void Main(string []args)
{
         
Console.WriteLine("Hello,World!! \n");
            Console.ReadLine();
}
}


Let us look at the various parts of the given Program:
 The First Line of program using System; the using keyword is used to includes the System  namespace in the program.A program has multiple using statements.

 In the Code Class Declaration includes the method, Main() That Will display the message  ,"Hello,World !!" on your screen.

The next line defines the Main methods which is the entry point for all C# programs.The Main methods states what the class does when executed.

Some C# point -

  •    C# is case Sensitive 
  •  All statement and Expression must end with a semicolon(;).
  • The program start execution from " Main" Method.
Share:

Introduction to C#

C# is a Programming Language developed by Microsoft and approved by the European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO). C# is modern general-purpose, Object-Oriented Programming Language. C# is developed by Anders Hejlsberg and his team during the development of.Net framework.
C# is designed for Common Language Infrastructure (CLI), Which consists of the executable code and runtime environment that allows the use of various high-level  Language on Different Computer platform and architectures

Integrated Development Environment (IDE) for C#
Microsoft provides Development tools for  C# Programming:

  • Visual Studio 2010 
  • Visual C# 2010 Express 
  • Visual Studio 2012
  • Visual Web Developer 
Share:

Exploring ASP.NET MVC

   Exploring ASP.NET MVC

MVC

The MVC Model is an alternate to the ASP.NET web forms Model For developing web application .It is a light weight model and Support Exiting ASP.NET Feature.It Separates the Following three main Components From application 

 Model - 

Refers to a set of classes that describe the data that the application work with .In addition these classes define the business  Logic that governs how to data can be manipulated.

View -

Refer to the components that defines an application user Interface.For Example ,Login that contains text boxes and buttons.
Share:

Creating a Dynamic Web Page in ASP.NET MVC.

Creating a Dynamic Web Page

To Create a dynamic and interactive web page.You need to Use Scripting 

-Clint-Side Scripting

-Sever-Side Scripting

                                                 Clint-Side Scripting

Clint Side Scripting enable to develop web pages that can dynamically respond to user input without having to interact with a web server.

                                                    Sever-Side Scripting

Server Side scripting provides user dynamic content that is based on information stored at a remote location, Such as a back -end Database .Server Side scripting include code Written in server -side Scripting Technologies,Such as Active Server Pages (ASP) And Java Server Pages (JSP) . 
Share:

Introduction To Web Application Development in ASP.NET MVC

 Introduction To Web Application Development

            Web Application is programs that are executed on the Web server from a web browser. 
These applications enable organizations to share information on the Internet and Corporate Intranets.
This information can be access from anywhere any time. The web application also supports commercial transactions. 

        The Three Layers of a Web Application   

Web application generally application broken into Three Layers. Each Layers has own Functionality. In Bellow Image, You Can see how three layers Contribute in Web Application






 Introduction to Web Pages

A Web application consists of many Web Pages. A Web page is Web document that Can be accessed through a Web Browser. Web pages are two Types:-

1:-Static Web Pages


  A Web page that contains only Static Contains and is delivered to the user as it is Stored is Called Static Web pages.

2:-Dynamic Web Pages

Web pages whose content  is generated dynamically by a Web Application or that response to user input and provides interactivity  is Call Dynamic Web Pages
Share:

Thursday, September 6, 2018

What is while loop in C# ?

Hello Friend in this article we will learn about while loop in C#.The while loop statement always checks the condition before executed the statement with in the loop.When the execution reaches the end of the statement in the while loop,the controls is passed back to the start of the loop.If the condition is true ,the while statement whith in the loop are executed again.


Syntax :

while(expression){
Statement
}
Share:

Tuesday, September 4, 2018

What is Action Method in ASP. NET MVC

Hello friends in this article we will learn about Action Methods in ASP.NET MVC. 

In a controller  class all public  methods are called Action Method.
Action Methods mainly have a one to one mapping with user interactions.

Share:

Friday, August 31, 2018

What is Controller in ASP.NET MVC





As you know an MVC application consists of three parts: model, view, and controller. The development of a web application usually required the knowledge of all the three parts.
In ASP.NET MVC Controllers are responsible for processing an incoming user request, executing the appropriate application code and communicating with the model, and rendering the required view.

                            How to Create Controller.

In ASP.NET MVC, controllers handle all incoming request. For creating a controller you need to create a .cs containing the controller class in the controller folder.

public class HomeController :Controller {  //Write Some Code}
Share:

Tuesday, August 28, 2018

Working With HTML and URL Helpers In ASP.NET MVC


ASP.NET MVC  HTML and URL Helpers.

Hello, friends in this article we will learn about HTML and URL Helpers. Consider a situation where the development team working on the e-commerce shopping website application needs to give an option to a user should be able to navigate the different web pages. ASP.NET MVC offers a standard set of helper method. These helpers help you work with HTML and URLs.
The benefits of using these helpers are that they help you generate links and URLs form the routing configuration.

Some HTML Helpers Methods are :

  • Html.ActionLink()
  • Html.BeginForm() and Html.EndForm()
  • Html.Label() and Html.LabelFor()
  • Html.DisplayName() and Html.DisplayNameFor()
  • Html.TextBox() and Html.TextBoxFor()
  • Html.TextArea() and Html.TextAreaFor()
  • Html.EditorFor()
  • Html.Ediotr()
  • Html.Password() and Html.PasswordFor()
  • Html.HiddenFor()
  • Html.CheckBox() and  Html.CheckBoxFor()
  • Html.DropDownList() and Html.DropDownList()
  • Html.RedioButton() and Html.RedioButtonFor()
  • Url.Action()


1. Html.ActionLink()

The Html.ActionLink() Method generates a hyperlink (ancor tag) that points to a controller's action metho.The Html.ActionLink() helper uses the internal rougting process to generate the target URL for the hyperlink.

             The syntax of    Html.ActionLink() 

@Html.ActionLink("Link Text", "ActionName","Controller Name",HtmlAttributes )


This  Html.ActionLink() generate following HTML  markup:

<a href="Controller/ActionName">Link Text</a>
   

2.Html.BeginForm() and Html.EndForm()

The  Html.BeginForm() Method indicate the start of a form. This helper method coordinates with the routing engine to generate a proper URL.

The syntax of  Html.BeginForm() 
    

@{Html.BeginForm("ActionName","Controller Name");}

The preceding syntax will generate the following  markup:

<form action="ControllerName/ActionName" method="post">

Once you created successfully form you need to close the <form> tag by rendering a closing </form> tag. Html.EndForm() Helper method render the form end tag  </form>

In order to avoid to use Html.EndForm()  you can use the following syntax:


@using(Html.BeginForm("ActionName","ControllerName"){

//Write your code here
}

The preceding syntax will generate the following  markup:

<form action="ControllerName/ActionName" >
<!--Write your code here-->
</form>





Share:

Monday, August 27, 2018

How to Count number of rows using jquery.

How to Count number of rows using jquery. ?

Hello friends in this tutorial we will learn about how to count number of row using Jquery.
For  count the number of rows use a selector that will select all the rows and take the lenth.

var myrowcount = $("#tablename tr").lenth;
Share:

Saturday, August 25, 2018

How to send SMTP Email ?

                How to Send Email Using SMTP mail





                        MailMessage mail = new MailMessage();
                        mail.To.Add(item);
                        mail.Subject = subject;
                        mail.Body = message;
                        mail.IsBodyHtml = true;
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "smtp.gmail.com";
                        smtp.Port = 587;
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials = new System.Net.NetworkCredential(email, pass);                                                    smtp.EnableSsl = true;
                        smtp.Send(mail);
Share:

Thursday, August 23, 2018

Naming Conventions in C#


Why Naming Conventions?
Naming Conventions are very important to identify the usage and purpose of a class or a method and to identify the type of variable and arguments.
Types of Naming Conventions Below are the two major parts of Naming Conventions.
  • Pascal Casing (PascalCasing)
  • Camel Casing (camelCasing)
Share:

SOCIAL PROFILES

Search This Blog

Powered by Blogger.

Fixed Menu (yes/no)

yes

Contact Form

Name

Email *

Message *

Tags

Ads Section

Tags

ASP.NET MVC (7) C# (11) jQuery (1)