Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mithun Pattankar
committed
May 26, 2016
1 parent
e518fde
commit 94026dd
Showing
16 changed files
with
630 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25123.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C31FC622-3BF0-403F-85E6-68F5131E6BDF}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{46066082-7F2D-48AE-9CFC-8BFBE083C410}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ContactsApi", "src\ContactsApi\ContactsApi.xproj", "{790BE90E-FF66-4357-921E-C5C8229D980E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{790BE90E-FF66-4357-921E-C5C8229D980E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{790BE90E-FF66-4357-921E-C5C8229D980E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{790BE90E-FF66-4357-921E-C5C8229D980E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{790BE90E-FF66-4357-921E-C5C8229D980E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{790BE90E-FF66-4357-921E-C5C8229D980E} = {C31FC622-3BF0-403F-85E6-68F5131E6BDF} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# ContactsAPI | ||
Contacts API is creating using ASP.NET Core Web API and also uses Swagger UI for testing | ||
Contacts API is creating using ASP.NET Core Web API | ||
|
||
For detailed write up, please go through http://www.mithunvp.com/create-aspnet-mvc-6-web-api-visual-studio-2015/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"projects": [ "src", "test" ], | ||
"sdk": { | ||
"version": "1.0.0-preview1-002702" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>790be90e-ff66-4357-921e-c5c8229d980e</ProjectGuid> | ||
<RootNamespace>ContactsApi</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using ContactsApi.Models; | ||
using ContactsApi.Repository; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace ContactsApi.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ContactsController : Controller | ||
{ | ||
public IContactsRepository ContactsRepo { get; set; } | ||
|
||
public ContactsController(IContactsRepository _repo) | ||
{ | ||
ContactsRepo = _repo; | ||
} | ||
|
||
[HttpGet] | ||
public IEnumerable<Contacts> GetAll() | ||
{ | ||
return ContactsRepo.GetAll(); | ||
} | ||
|
||
[HttpGet("{id}", Name = "GetContacts")] | ||
public IActionResult GetById(string id) | ||
{ | ||
var item = ContactsRepo.Find(id); | ||
if (item == null) | ||
{ | ||
return NotFound(); | ||
} | ||
return new ObjectResult(item); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Create([FromBody] Contacts item) | ||
{ | ||
if (item == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
ContactsRepo.Add(item); | ||
return CreatedAtRoute("GetContacts", new { Controller = "Contacts", id = item.MobilePhone }, item); | ||
} | ||
|
||
[HttpPut("{id}")] | ||
public IActionResult Update(string id, [FromBody] Contacts item) | ||
{ | ||
if (item == null) | ||
{ | ||
return BadRequest(); | ||
} | ||
var contactObj = ContactsRepo.Find(id); | ||
if (contactObj == null) | ||
{ | ||
return NotFound(); | ||
} | ||
ContactsRepo.Update(item); | ||
return new NoContentResult(); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
public void Delete(string id) | ||
{ | ||
ContactsRepo.Remove(id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ContactsApi.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ValuesController : Controller | ||
{ | ||
// GET api/values | ||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet("{id}")] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/values | ||
[HttpPost] | ||
public void Post([FromBody]string value) | ||
{ | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody]string value) | ||
{ | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace ContactsApi.Models | ||
{ | ||
public class Contacts | ||
{ | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public bool IsFamilyMember { get; set; } | ||
public string Company { get; set; } | ||
public string JobTitle { get; set; } | ||
public string Email { get; set; } | ||
public string MobilePhone { get; set; } | ||
public DateTime DateOfBirth { get; set; } | ||
public DateTime AnniversaryDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace ContactsApi | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
Oops, something went wrong.