0% found this document useful (0 votes)
5 views5 pages

MVC Currency Converter Web App

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

MVC Currency Converter Web App

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

FACULTY OF ENGINEERING AND TECHNOLOGY

Department of Computer Engineering


01CE0523 - .NET Technologies

Experiment 8

AIM: Creating web application using MVC

Code :

CurrencyConverterController

using Prcatical_8._3.Models;
using System;
using [Link];
using System.Įinq;
using [Link];
using
[Link];

namespace Prcatical_8._3.Controllers
{
public class CurrencyConverterController : Controller
{

public ActionResult Index()


{
return View();
}

public ActionResult CurrencyConverter()


{
var model = new CurrencyConverterModel
{
FromCurrency = "I
R", ToCurrency =
"JPY",
CurrencySelectĮist = [Link]()
};
return View(model);
}

// store conversion.
private static readonly Dictionary<string, decimal> exchangeRates =
new Dictionary<string, decimal>
{
{ "I R", 1.0m }, // Base rate for I R (reference)
{ "JPY", 1.5m }, // 1 I R = 1.5 JPY
{ "GBP", 0.010m }, // 1 I R = 0.010 GBP
{ "RUB", 0.83m } // 1 I R = 0.83 RUB
};

public ActionResult Convert(CurrencyConverterModel model)

YASH ANAND (92201703234) BATCH: A |21


FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0523 - .NET Technologies
{

YASH ANAND (92201703234) BATCH: A |22


FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0523 - .NET Technologies

if ([Link]([Link]) fifi
[Link]([Link]))
{
decimal fromRate = exchangeRates[[Link]];
decimal toRate = exchangeRates[[Link]];

// Conversion formula: (Amount / FromRate) * ToRate


[Link] = ([Link] / fromRate) * toRate;
}

// Repopulate the CurrencySelectĮist for the dropdown lists in the


view. [Link]Įist =
[Link](); return
View("CurrencyConverter", model);
}

}
}

CurrencyConverterModel

using System;
using [Link];
using System.Įinq;
using [Link];
using
[Link];

namespace Prcatical_8._3.Models
{
public class CurrencyConverterModel
{

public string FromCurrency { get; set;


} public string ToCurrency { get; set;
} public decimal Amount { get; set; }
public decimal ConvertedAmount { get; set; }

//SelectĮistItem
public Įist<SelectĮistItem> CurrencySelectĮist { get; set; }

// currency list as SelectĮistItem


public static Įist<SelectĮistItem> GetCurrencies()
{
return new Įist<SelectĮistItem>
{
new SelectĮistItem { Value = "I R", Text = "Indian
Rupee" }, new SelectĮistItem { Value = "JPY", Text =
"Japanese Yen" }, new SelectĮistItem { Value = "GBP",
Text = "British Pound" }, new SelectĮistItem { Value =
"RUB", Text = "Russian Ruble" }
};
}
}
}

YASH ANAND (92201703234) BATCH: A |23


FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0523 - .NET Technologies

CurrencyConverterView

@model Prcatical_8._3.[Link]

@{
[Link] = "CurrencyConverter";
}

<h2>CurrencyConverter</h2>

@using ( [Link]("Convert", "CurrencyConverter", [Link]))


{
<div style="display:flex">
<div style="margin-right:30px">
<label for="FromCurrency">From:</label>
@ [Link]ĮistFor(model => [Link],
[Link]Įist, "Select a currency", new { @class = "form-control"
})
</div>

<div>
<label for="ToCurrency">To:</label>
@ [Link]ĮistFor(model => [Link],
[Link]Įist, "Select a currency", new { @class = "form-control"
})
</div>

</div>

<div style="margin-block:20px">
<label for="Amount">Amount:</label>
@ [Link](model => [Link], new { @class = "form-
control", type = "number", step = "0.01", placeholder = "Enter amount" })

</div>

<div>
<input type="submit" value="Convert" class="btn btn-primary" />

</div>

@if ([Link] > 0)


{

<div style="margin-block:20px">
<h2>Converted Amount: @[Link]</h2>
</div>

YASH ANAND (92201703234) BATCH: A |24


FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0523 - .NET Technologies

Screenshot:

YASH ANAND (92201703234) BATCH: A |25

You might also like