Skip to content
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
3 changes: 3 additions & 0 deletions Week2-Project/Taran012/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CorporateLedger/.vs
CorporateLedger/packages
CorporateLedger/CorporateLedger/bin
22 changes: 22 additions & 0 deletions Week2-Project/Taran012/CorporateLedger/CorporateLedger.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 14 for Web
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CorporateLedger", "CorporateLedger\CorporateLedger.csproj", "{D8FB30AB-D096-4D93-963F-2ADC5C30D463}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D8FB30AB-D096-4D93-963F-2ADC5C30D463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8FB30AB-D096-4D93-963F-2ADC5C30D463}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8FB30AB-D096-4D93-963F-2ADC5C30D463}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8FB30AB-D096-4D93-963F-2ADC5C30D463}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Cors;

namespace CorporateLedger
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API routes
config.MapHttpAttributeRoutes();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using CorporateLedger.Models;
using System.Web.Http.Cors;

namespace CorporateLedger.Controllers
{
public class designationsController : ApiController
{
private CorporateLedgerEntities db = new CorporateLedgerEntities();

// GET: api/designations
public IQueryable<designation> Getdesignations()
{
return db.designations;
}

// GET: api/designations/5
[ResponseType(typeof(designation))]
public IHttpActionResult Getdesignation(int id)
{
designation designation = db.designations.Find(id);
if (designation == null)
{
return NotFound();
}

return Ok(designation);
}

// PUT: api/designations/5
[ResponseType(typeof(void))]
public IHttpActionResult Putdesignation(int id, designation designation)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

if (id != designation.id)
{
return BadRequest();
}

db.Entry(designation).State = EntityState.Modified;

try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!designationExists(id))
{
return NotFound();
}
else
{
throw;
}
}

return StatusCode(HttpStatusCode.NoContent);
}

// POST: api/designations
[ResponseType(typeof(designation))]
public IHttpActionResult Postdesignation(designation designation)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

db.designations.Add(designation);
db.SaveChanges();

return CreatedAtRoute("DefaultApi", new { id = designation.id }, designation);
}

// DELETE: api/designations/5
[ResponseType(typeof(designation))]
public IHttpActionResult Deletedesignation(int id)
{
designation designation = db.designations.Find(id);
if (designation == null)
{
return NotFound();
}

db.designations.Remove(designation);
db.SaveChanges();

return Ok(designation);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}

private bool designationExists(int id)
{
return db.designations.Count(e => e.id == id) > 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using CorporateLedger.Models;

namespace CorporateLedger.Controllers
{
public class employeesController : ApiController
{
private CorporateLedgerEntities db = new CorporateLedgerEntities();

// GET: api/employees
public IQueryable<employee> Getemployees()
{
return db.employees;
}

// GET: api/employees/5
[ResponseType(typeof(employee))]
public IHttpActionResult Getemployee(int id)
{
employee employee = db.employees.Find(id);
if (employee == null)
{
return NotFound();
}

return Ok(employee);
}

// PUT: api/employees/5
[ResponseType(typeof(void))]
public IHttpActionResult Putemployee(int id, employee employee)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

if (id != employee.id)
{
return BadRequest();
}

db.Entry(employee).State = EntityState.Modified;

try
{
db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!employeeExists(id))
{
return NotFound();
}
else
{
throw;
}
}

return StatusCode(HttpStatusCode.NoContent);
}

// POST: api/employees
[ResponseType(typeof(employee))]
public IHttpActionResult Postemployee(employee employee)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

db.employees.Add(employee);
db.SaveChanges();

return CreatedAtRoute("DefaultApi", new { id = employee.id }, employee);
}

// DELETE: api/employees/5
[ResponseType(typeof(employee))]
public IHttpActionResult Deleteemployee(int id)
{
employee employee = db.employees.Find(id);
if (employee == null)
{
return NotFound();
}

db.employees.Remove(employee);
db.SaveChanges();

return Ok(employee);
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}

private bool employeeExists(int id)
{
return db.employees.Count(e => e.id == id) > 0;
}
}
}
Loading