Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added controller

  • Loading branch information...
commit 771b570e6bd2bce06f7bd1ea5987bc7312ad62bb 1 parent 0155a84
@wendellinfinity authored
View
BIN  ExpenseMe.suo
Binary file not shown
View
12 ExpenseMe/.project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ExpenseMe</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.projects.webnature</nature>
+ </natures>
+</projectDescription>
View
92 ExpenseMe/Controllers/ExpenseController.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Routing;
+using ExpenseMe.Models;
+using ExpenseMe.Domain;
+
+namespace ExpenseMe.Controllers {
+ [Authorize]
+ public class ExpenseController : Controller {
+
+ public static void RegisterRoutes(RouteCollection routes) {
+ routes.MapRoute(
+ "Expense", // Route name
+ "Expense/{action}/{id}", // URL with parameters
+ new { controller = "Expense", action = "Index", id = UrlParameter.Optional } // Parameter defaults
+ );
+ }
+
+ //
+ // GET: /Expense/
+
+ public JsonResult Index() {
+ List<ViewExpense> expenses = new List<ViewExpense>();
+ return this.Json(expenses);
+ }
+
+ //
+ // GET: /Expense/Details/5
+ public JsonResult Details(int id) {
+ ViewExpense expense = new ViewExpense()
+ {
+ Description="Kuma treat",
+ ExpenseDate=DateTime.Today,
+ ExpenseId=888,
+ Spent=1000.10
+ };
+ return this.Json(expense,JsonRequestBehavior.AllowGet);
+ }
+
+ //
+ // POST: /Expense/Create
+ [HttpPost]
+ public JsonResult Create(ViewExpense expense) {
+ try {
+ // TODO: Add insert logic here
+ //create a new Client object
+ ExpenseMeModelContainer context = new ExpenseMeModelContainer();
+ Expense e = new Expense();
+ e.Description = expense.Description;
+ //save to db
+ context.AddToExpenses(e);
+ context.SaveChanges();
+ return this.Json(expense);
+ }
+ catch (Exception ex) {
+ return this.Json(new TransactionResult() { IsError = true, StatusDescription = ex.Message });
+ }
+ }
+
+
+ //
+ // POST: /Expense/Edit/5
+ [HttpPost]
+ public JsonResult Edit(ViewExpense expense) {
+ try {
+ // TODO: Add update logic here
+
+ return this.Json(expense);
+ }
+ catch (Exception ex) {
+ return this.Json(new TransactionResult() { IsError = true, StatusDescription = ex.Message });
+ }
+ }
+
+ //
+ // POST: /Expense/Delete/5
+ [HttpPost]
+ public JsonResult Delete(int id) {
+ try {
+ // TODO: Add delete logic here
+
+ return this.Json(new TransactionResult() { IsError = false, StatusDescription = "OK" });
+ }
+ catch (Exception ex) {
+ return this.Json(new TransactionResult() { IsError = true, StatusDescription = ex.Message });
+ }
+ }
+ }
+}
View
2  ExpenseMe/Controllers/HomeController.cs
@@ -5,6 +5,8 @@
using System.Web.Mvc;
namespace ExpenseMe.Controllers {
+
+ [Authorize]
public class HomeController : Controller {
public ActionResult Index() {
ViewBag.Message = "Welcome to ASP.NET MVC!";
View
9 ExpenseMe/ExpenseMe.csproj
@@ -63,11 +63,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\AccountController.cs" />
+ <Compile Include="Controllers\ExpenseController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\AccountModels.cs" />
+ <Compile Include="Models\TransactionResult.cs" />
+ <Compile Include="Models\ViewExpense.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -146,6 +149,12 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ExpenseMe.Domain\ExpenseMe.Domain.csproj">
+ <Project>{F83FFC5A-3683-41B9-8793-1D7C524DFDC1}</Project>
+ <Name>ExpenseMe.Domain</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
3  ExpenseMe/ExpenseMe.csproj.user
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <ProjectView>ShowAllFiles</ProjectView>
+ </PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
View
3  ExpenseMe/Global.asax.cs
@@ -4,6 +4,7 @@
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
+using ExpenseMe.Controllers;
namespace ExpenseMe {
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
@@ -23,6 +24,8 @@ public class MvcApplication : System.Web.HttpApplication {
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
+ ExpenseController.RegisterRoutes(routes);
+
}
protected void Application_Start() {
View
12 ExpenseMe/Models/TransactionResult.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace ExpenseMe.Models {
+ public struct TransactionResult {
+ public string StatusDescription { get; set; }
+ public bool IsError { get; set; }
+ public object Data { get; set; }
+ }
+}
View
13 ExpenseMe/Models/ViewExpense.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace ExpenseMe.Models {
+ public class ViewExpense {
+ public int ExpenseId { get; set; }
+ public string Description { get; set; }
+ public DateTime ExpenseDate { get; set; }
+ public double Spent { get; set; }
+ }
+}
View
2  ExpenseMe/Views/Shared/_Layout.cshtml
@@ -11,7 +11,7 @@
<div class="page">
<header>
<div id="title">
- <h1>My MVC Application</h1>
+ <h1>?</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
View
2  ExpenseMe/Web.config
@@ -7,7 +7,7 @@
<configuration>
<connectionStrings>
<add name="ApplicationServices"
- connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
+ connectionString="data source=.;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ExpenseMeModelContainer" connectionString="metadata=res://*/ExpenseMeModel.csdl|res://*/ExpenseMeModel.ssdl|res://*/ExpenseMeModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=ExpenseMe;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
View
BIN  ExpenseMe/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.