Skip to content

Commit

Permalink
add cpa mvc functionality (seperate project called cpamvc)
Browse files Browse the repository at this point in the history
  • Loading branch information
petereps committed Jan 31, 2018
1 parent 7449243 commit 9d62f61
Show file tree
Hide file tree
Showing 96 changed files with 25,600 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cpa.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cpa", "cpa\cpa.csproj", "{873409FB-CC2D-44EB-BF7B-F877EC6A4A97}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cpa", "cpa\cpa.csproj", "{873409FB-CC2D-44EB-BF7B-F877EC6A4A97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cpamvc", "cpamvc\cpamvc.csproj", "{E245A121-FBAC-445F-BD3B-E22DBACF0E7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{873409FB-CC2D-44EB-BF7B-F877EC6A4A97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{873409FB-CC2D-44EB-BF7B-F877EC6A4A97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{873409FB-CC2D-44EB-BF7B-F877EC6A4A97}.Release|Any CPU.Build.0 = Release|Any CPU
{E245A121-FBAC-445F-BD3B-E22DBACF0E7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E245A121-FBAC-445F-BD3B-E22DBACF0E7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E245A121-FBAC-445F-BD3B-E22DBACF0E7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E245A121-FBAC-445F-BD3B-E22DBACF0E7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
93 changes: 93 additions & 0 deletions cpa/Controllers/StatementsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace cpa.Controllers
{
public class StatementsController : Controller
{
// GET: Statements
public ActionResult Index()
{
return View();
}

// GET: Statements/Details/5
public ActionResult Details(int id)
{
return View();
}

// GET: Statements/Create
public ActionResult Create()
{
return View();
}

// POST: Statements/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
// TODO: Add insert logic here

return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}

// GET: Statements/Edit/5
public ActionResult Edit(int id)
{
return View();
}

// POST: Statements/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
// TODO: Add update logic here

return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}

// GET: Statements/Delete/5
public ActionResult Delete(int id)
{
return View();
}

// POST: Statements/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
// TODO: Add delete logic here

return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}
12 changes: 12 additions & 0 deletions cpa/ScaffoldingReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Scaffolding has generated all the files and added the required dependencies.

However the Application's Startup code may required additional changes for things to work end to end.
Add the following code to the Configure method in your Application's Startup class if not already done:

app.UseMvc(routes =>
{
route.MapRoute(
name : "areas",
template : "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
7 changes: 7 additions & 0 deletions cpa/Views/Statements/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@{
ViewData["Title"] = "Index";
}

<h2>Index</h2>

7 changes: 7 additions & 0 deletions cpa/cpa.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\ccx\Controllers\" />
<Folder Include="Areas\ccx\Data\" />
<Folder Include="Areas\ccx\Models\" />
<Folder Include="Areas\ccx\Views\" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions cpamvc/Controllers/AddSourceController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace cpamvc.Controllers
{
public class AddSourceController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
}
19 changes: 19 additions & 0 deletions cpamvc/Controllers/AnalysisController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace cpamvc.Controllers
{
public class AnalysisController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
}
49 changes: 49 additions & 0 deletions cpamvc/Controllers/ArticleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using cpamvc.Models;

namespace cpamvc.Controllers
{
[Route("api/[controller]")]
public class ArticleController : Controller
{
[HttpGet]
public IEnumerable<Article> GetArticles()
{
//return array of article objects

return null;
}

[HttpGet("{id}")]
public IActionResult GetArticleById(long id)
{
//retrieve individual article by an id
return null;
}
[HttpGet("/company/{id}")]
public IActionResult GetArticleByCompany(long id)
{
//retrieve individual article by a Company id
return null;
}
[HttpGet("/company/{companyID}/ratio/{ratioID}")]
public IActionResult GetRelevantArticles(long companyID, long ratioID)
{
//retrieve articles by company + ratio
return null;
}

[HttpPost]
public IActionResult AddArticle([FromBody] Article article)
{
if (article == null) {
return BadRequest();
}
//post article
return null;
}

}
}
98 changes: 98 additions & 0 deletions cpamvc/Controllers/CompanyController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using cpamvc.Models;
using System.Data.SqlClient;
using System;
using System.Data;

namespace cpamvc.Controllers
{
[Route("api/[controller]")]
public class CompanyController : Controller
{
SqlConnection sqlConn = new SqlConnection("Server=localhost;Database=cpa;Trusted_Connection=True;");

[HttpGet]
public IEnumerable<Company> GetCompanies()
{
//return array of company objects

List<Company> companies = new List<Company>();

try
{
sqlConn.Open();
SqlDataReader myReader = null;
SqlCommand sqlCmd = new SqlCommand("SELECT id, name, description, market, symbol FROM company", sqlConn);

myReader = sqlCmd.ExecuteReader();
while (myReader.Read())
{
companies.Add(new Company(Int32.Parse(myReader["id"].ToString()), myReader["name"].ToString(),
myReader["description"].ToString(), myReader["market"].ToString(), myReader["symbol"].ToString()));
}

sqlConn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

//testing -- it works on route /api/company
//Company c1 = new Company(1, "Apple");
//Company c2 = new Company(2, "IBM");
//Company c3 = new Company(3, "Amazon");

//companies.Add(c1);
//companies.Add(c2);
//companies.Add(c3);
return companies;
}

[HttpGet("{id}")]
public IActionResult GetCompanyById(int id)
{
//retrieve individual company by an id

Company company = null;

try
{
sqlConn.Open();
SqlDataReader myReader = null;
SqlCommand sqlCmd = new SqlCommand("SELECT TOP 1 id, name, description, market, symbol FROM company WHERE id = @Param1", sqlConn);
sqlCmd.Parameters.Add(new SqlParameter("@Param1", SqlDbType.Int) { Value = id });

myReader = sqlCmd.ExecuteReader();
while (myReader.Read())
{
company = new Company(Int32.Parse(myReader["id"].ToString()), myReader["name"].ToString(),
myReader["description"].ToString(), myReader["market"].ToString(), myReader["symbol"].ToString());
}

sqlConn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

return new ObjectResult(company);
}

[HttpPost]
public IActionResult AddCompany([FromBody] Company company)
{
if (company == null)
{
return BadRequest();
}

//post company
return null;
}

}
}
37 changes: 37 additions & 0 deletions cpamvc/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using cpamvc.Models;

namespace cpamvc.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult About()
{
ViewData["Message"] = "Your application description page.";

return View();
}

public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

return View();
}

public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
Empty file.
Loading

0 comments on commit 9d62f61

Please sign in to comment.