Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wave Code Challenge Submission #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config

# Windows Store app package directory
AppPackages/
BundleArtifacts/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe

# FAKE - F# Make
.fake/
31 changes: 29 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,35 @@ There are many ways that this application could be built; we ask that you build

Please modify `README.md` to add:

1. Instructions on how to build/run your application
1. A paragraph or two about what you are particularly proud of in your implementation, and why.
### Instructions to Build/Run application

I developed this on Ubuntu 16.04 using dotnet core (using Visual Studio Code if you're interested)

See the following for instructions on how to install dotnet core on Ubuntu. There are also Mac instructions as well as other Linux distro instructions.

https://www.microsoft.com/net/core#linuxubuntu

Complete step 1 to set up the dotnet core apt-get feed

Complete step 2 to install dotnet core

Clone the repository and then navigate inside the se-challenge-expenses folder.

Run the command 'dotnet restore'

Navigate to the se-challenge-expenses/src/aspnetcoreapp

Run the command 'dotnet run'

The 'dotnet run' command should give a url to navigate to. Usually it is http://localhost:5000

This project uses SQLite, .NET Core Platform, ASP.NET Core MVC framework, and Dapper.NET micro ORM

### Implementation thoughts

This was an interesting project for me. I'm a .NET developer but I haven't used the .NET core platform or the ASP.NET Core web framework before. Most of my time was spent setting things up on linux and getting to know the new platform. Once I had things working it was a case of searching around for where all my familiar libraries had been moved to. So the part of this project I enjoyed the most was getting the new stack up and running on linux.

The ASP.NET core (web framework) has a well defined template for starting a project and separating the concerns of the application. I chose to use a simple model, Expense, to represent the data going into the database. I used a simple viewmodel, ExpenseReportViewModel, to represent the data that is queried from the database and displayed in the expense report. If the project expanded I might think about breaking up the Expense model. I would break up the model to represent an Employee, Tax, and Expense but if all we're doing is calculating the expense report there's no point in adding unnecessary joins to the query.

## Submission Instructions

Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects":[
"src",
"test"
]
}
58 changes: 58 additions & 0 deletions src/aspnetcoreapp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApplication.Services;
using WebApplication.Data;

namespace WebApplication.Controllers
{
public class HomeController : Controller
{

private readonly ICsvImporter _csvImporter;
private readonly IExpenseRepository _expenseRepository;

public HomeController(ICsvImporter csvImporter, IExpenseRepository expenseRepository)
{
_csvImporter = csvImporter;
_expenseRepository = expenseRepository;
}

public IActionResult Index()
{
// The view being returned is calculated based on the name of the
// controller (Home) and the name of the action method (Index).
// So in this case, the view returned is /Views/Home/Index.cshtml.
return View();
}

[HttpPost]
public ActionResult Upload(IFormFile file)
{
try
{
var expenses = _csvImporter.ReadCsvFile(file);
_expenseRepository.SaveExpenses(expenses);
}
catch (CsvImportException e)
{
ViewData["error"] = e.Message;
return View("Index");
}
catch(Exception e)
{
ViewData["error"] = e.Message;
return View("Index");
}
return RedirectToAction("Expense");
}

public IActionResult Expense()
{
// Creates a model and passes it on to the view.
var expenseViewModels = _expenseRepository.GetExpenseReport();

return View(expenseViewModels);
}
}
}
27 changes: 27 additions & 0 deletions src/aspnetcoreapp/Data/DapperBaseRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Data.Sqlite;
using System.Data;
using Microsoft.AspNetCore.Hosting;

namespace WebApplication.Data
{
public class DapperBaseRepo
{
private readonly IHostingEnvironment _hostingEnvironment;

public DapperBaseRepo (IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public string DbFile
{
get { return _hostingEnvironment.ContentRootPath + "/ImportDb.sqlite"; }
}

public IDbConnection SimpleDbConnection()
{
return new SqliteConnection("Data Source=" + DbFile);
}
}
}


Loading