Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lohithgn committed Jan 24, 2019
1 parent e9ff107 commit 21c6eff
Show file tree
Hide file tree
Showing 54 changed files with 3,281 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ You can find getting started instructions, docs, and tutorials for Blazor at [ht
# Get Blazor Converters
1. Clone this repo.
2. Open ```BlazorConverters.sln``` in Visual Studio.
3. Run the application
3. Run the application

<i>Note: For Currency Convertion, I have used CurrencyLayer API. You will need to sign up for free and get an API key. Add the key in ForexApiClient.cs file before you run.</i>
5 changes: 5 additions & 0 deletions src/BlazorConverters.Client/App.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
Configuring this here is temporary. Later we'll move the app config
into Program.cs, and it won't be necessary to specify AppAssembly.
-->
<Router AppAssembly=typeof(Program).Assembly />
27 changes: 27 additions & 0 deletions src/BlazorConverters.Client/BlazorConverters.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Include="wwwroot\css\bootstrap\bootstrap.min.css.map" />
<None Include="wwwroot\css\open-iconic\FONT-LICENSE" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" />
<None Include="wwwroot\css\open-iconic\ICON-LICENSE" />
<None Include="wwwroot\css\open-iconic\README.md" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.7.0" PrivateAssets="all" />
<PackageReference Include="UnitsNet" Version="4.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorConverters.Shared\BlazorConverters.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page "/angle"
<div class="container-fluid">
<PageHeader Title="Angle" Link="/angle"></PageHeader>
<GenericConverter CurrentUnitCategory="@Category"></GenericConverter>
</div>
@functions {
UnitCategory Category = UnitCategory.Angle;
}
8 changes: 8 additions & 0 deletions src/BlazorConverters.Client/Pages/Converters/Area/Area.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page "/area"
<div class="container-fluid">
<PageHeader Title="Area" Link="/area"></PageHeader>
<GenericConverter CurrentUnitCategory="@Category"></GenericConverter>
</div>
@functions {
UnitCategory Category = UnitCategory.Area;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@inherits CurrencyModel
@page "/"
@page "/currency"


<div class="container-fluid">
<PageHeader Title="Currency" Link="/currency"></PageHeader>
<div class="row mt-4">
<div class="col-md-7">
<div class="card">
<div class="card-header bg-dark text-white">
Source Currency
</div>
<div class="card-body bg-light">
<CurrencyDisplay Symbol="@SourceCurrency.Symbol"
Value="@SourceCurrencyInput"
DecimalPlaces="0"></CurrencyDisplay>
<CurrencyOptions Value="@SelectedSourceCurrency"
Currencies="@Currencies"
CurrencyChanged="@OnSourceCurrencyChanged"></CurrencyOptions>
</div>
</div>
<div class="card mt-2">
<div class="card-header bg-dark text-white">
Target Currency
</div>
<div class="card-body bg-light">
<CurrencyDisplay Symbol="@TargetCurrency.Symbol"
Value="@TargetCurrencyInput"
DecimalPlaces="2"></CurrencyDisplay>
<CurrencyOptions Value="@SelectedTargetCurrency"
Currencies="@Currencies"
CurrencyChanged="@OnTargetCurrencyChanged"></CurrencyOptions>
</div>
</div>

<div class="row mt-5">
<div class="col-md-12">
<small>1 @SelectedSourceCurrency = @(Rate == 0 || Rate == 1 ? Rate.ToString() : Rate.ToString("N4")) @SelectedTargetCurrency</small>
</div>
</div>
</div>
<div class="col-md-5">
<Keyboard OnKeyInput="OnKeyInput"></Keyboard>
</div>
</div>
</div>
<span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlazorCalculator.Services;
using BlazorConverters.Data;
using Microsoft.AspNetCore.Blazor;
using Microsoft.AspNetCore.Blazor.Components;

namespace BlazorConverters.Client.Pages
{
public class CurrencyModel : BlazorComponent
{
[Inject] CurrencyService CurrencyService { get; set; }

protected IEnumerable<Currency> Currencies { get; set; } = null;
protected Currency SourceCurrency { get; set; } = null;
protected double SourceCurrencyInput { get; set; } = 1;
protected string SelectedSourceCurrency { get; set; }
protected Currency TargetCurrency { get; set; } = null;
protected double TargetCurrencyInput { get; set; } = 1;
protected string SelectedTargetCurrency { get; set; }
protected double Rate { get; set; }
protected override async Task OnInitAsync()
{
Currencies = CurrencyService.GetCurrencies();
SourceCurrency = Currencies.First();
SelectedSourceCurrency = SourceCurrency.Code;
TargetCurrency = Currencies.First();
SelectedTargetCurrency = TargetCurrency.Code;
await CalculateRate();
}

private async Task CalculateRate()
{
Rate = await CurrencyService.CalculateConversionRate(SelectedSourceCurrency, SelectedTargetCurrency);
TargetCurrencyInput = Rate * SourceCurrencyInput;
}

protected async Task OnSourceCurrencyChanged(UIChangeEventArgs e)
{
SelectedSourceCurrency = e.Value.ToString();
SourceCurrency = Currencies.First(c => c.Code == SelectedSourceCurrency);
await CalculateRate();
StateHasChanged();
}

protected async Task OnTargetCurrencyChanged(UIChangeEventArgs e)
{
SelectedTargetCurrency = e.Value.ToString();
TargetCurrency = Currencies.First(c => c.Code == SelectedTargetCurrency);
await CalculateRate();
StateHasChanged();
}

protected async Task OnKeyInput(string key)
{
var currString = SourceCurrencyInput.ToString();
switch (key.ToLower())
{
case "ce":
currString = "0";
break;
case "backspace":
currString = currString.Substring(0, currString.Length - 1);
break;
default:
currString = (currString.Length == 1 && currString == "0")
? key : $"{currString}{key}";
break;
}
SourceCurrencyInput = double.Parse(currString);
await CalculateRate();
StateHasChanged();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="col-md-12">
<div>
<span class="h5 font-weight-lighter">@Symbol</span>
<NumberDisplay DisplayLevel="4" DisplayValue="@Value" DecimalPlaces="@DecimalPlaces"></NumberDisplay>
</div>
</div>
</div>
@functions
{
[Parameter] protected string Symbol { get; set; }
[Parameter] protected double Value { get; set; }
[Parameter] protected int DecimalPlaces { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="row">
<div class="col-md-12">
<div class="form-group">
<select class="form-control" id="sourceCurrency" value="@Value"
onchange="@CurrencyChanged">
@foreach (var currency in Currencies)
{
<option value="@currency.Code">@currency.Name</option>
}
</select>
</div>
</div>
</div>
@functions
{
[Parameter]
protected IEnumerable<Data.Currency> Currencies { get; set; }

[Parameter]
protected string Value { get; set; }

[Parameter]
protected Func<UIChangeEventArgs, Task> CurrencyChanged { get; set; }
}
Loading

0 comments on commit 21c6eff

Please sign in to comment.