Skip to content

Commit 9131007

Browse files
API is created to manage all contacts and return in JSON format
0 parents  commit 9131007

File tree

119 files changed

+13162
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+13162
-0
lines changed
256 Bytes
Binary file not shown.

.vs/ContactsAPI/config/applicationhost.config

Lines changed: 995 additions & 0 deletions
Large diffs are not rendered by default.

.vs/ContactsAPI/v16/.suo

34 KB
Binary file not shown.

ContactsAPI.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29920.165
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContactsAPI", "ContactsAPI\ContactsAPI.csproj", "{7A3FFC80-B381-4782-9549-3728B785BA26}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7A3FFC80-B381-4782-9549-3728B785BA26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7A3FFC80-B381-4782-9549-3728B785BA26}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7A3FFC80-B381-4782-9549-3728B785BA26}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7A3FFC80-B381-4782-9549-3728B785BA26}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {11BB12FF-442B-4939-9143-2B6B7EF79D9B}
24+
EndGlobalSection
25+
EndGlobal

ContactsAPI/ContactsAPI.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
9+
</ItemGroup>
10+
11+
12+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
5+
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
6+
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
7+
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
8+
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
9+
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
10+
<WebStackScaffolding_LayoutPageFile />
11+
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
12+
</PropertyGroup>
13+
</Project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using ContactsAPI.Models;
6+
using ContactsAPI.Repository;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.AspNetCore.Mvc;
9+
10+
namespace ContactsAPI.Controllers
11+
{
12+
[Route("api/[controller]")]
13+
public class ContactsController : Controller
14+
{
15+
public IContactsRepository ContactRepo { get; set; }
16+
public ContactsController(IContactsRepository _repo)
17+
{
18+
ContactRepo = _repo;
19+
}
20+
21+
[HttpGet]
22+
public IEnumerable<Contacts> GetAll()
23+
{
24+
return ContactRepo.GetAll();
25+
}
26+
27+
[HttpGet("{id}", Name ="GetContacts")]
28+
public IActionResult GetById(string id)
29+
{
30+
var item = ContactRepo.Find(id);
31+
if(item == null)
32+
{
33+
return NotFound();
34+
}
35+
return new ObjectResult(item);
36+
}
37+
38+
[HttpPost]
39+
public IActionResult Create(Contacts item)
40+
{
41+
if(item == null)
42+
{
43+
return BadRequest();
44+
}
45+
ContactRepo.Add(item);
46+
return CreatedAtRoute("GetContacts", new { Controller = "Contacts", id = item.MobilePhone }, item);
47+
}
48+
49+
[HttpPut("{id}")]
50+
public IActionResult Update(string id, [FromBody] Contacts item)
51+
{
52+
if (item == null)
53+
{
54+
return BadRequest();
55+
}
56+
var contactObj = ContactRepo.Find(id);
57+
if (contactObj == null)
58+
{
59+
return NotFound();
60+
}
61+
ContactRepo.Update(item);
62+
return new NoContentResult();
63+
}
64+
65+
[HttpDelete("{id}")]
66+
public void Delete(string id)
67+
{
68+
ContactRepo.Remove(id);
69+
}
70+
}
71+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace ContactsAPI.Controllers
9+
{
10+
[ApiController]
11+
[Route("[controller]")]
12+
public class WeatherForecastController : ControllerBase
13+
{
14+
private static readonly string[] Summaries = new[]
15+
{
16+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17+
};
18+
19+
private readonly ILogger<WeatherForecastController> _logger;
20+
21+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
[HttpGet]
27+
public IEnumerable<WeatherForecast> Get()
28+
{
29+
var rng = new Random();
30+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
31+
{
32+
Date = DateTime.Now.AddDays(index),
33+
TemperatureC = rng.Next(-20, 55),
34+
Summary = Summaries[rng.Next(Summaries.Length)]
35+
})
36+
.ToArray();
37+
}
38+
}
39+
}

ContactsAPI/Models/Contacts.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace ContactsAPI.Models
7+
{
8+
public class Contacts
9+
{
10+
public string FirstName { get; set; }
11+
public string LastName { get; set; }
12+
public bool IsFamiliyMember { get; set; }
13+
public string Company { get; set; }
14+
public string JobTitle { get; set; }
15+
public string Email { get; set; }
16+
public string MobilePhone { get; set; }
17+
public DateTime DateOfBirth { get; set; }
18+
public DateTime AnniversaryDate { get; set; }
19+
}
20+
}

ContactsAPI/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace ContactsAPI
11+
{
12+
public class Program
13+
{
14+
public static void Main(string[] args)
15+
{
16+
CreateHostBuilder(args).Build().Run();
17+
}
18+
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
Host.CreateDefaultBuilder(args)
21+
.ConfigureWebHostDefaults(webBuilder =>
22+
{
23+
webBuilder.UseStartup<Startup>();
24+
});
25+
}
26+
}

0 commit comments

Comments
 (0)