Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deltek full stack exam #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
50 changes: 25 additions & 25 deletions BackEnd/ContactsAPI/ContactsAPI.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContactsAPI", "ContactsAPI\ContactsAPI.csproj", "{C2C455C2-BAB7-4180-A837-435078F8896A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C2C455C2-BAB7-4180-A837-435078F8896A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2C455C2-BAB7-4180-A837-435078F8896A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2C455C2-BAB7-4180-A837-435078F8896A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2C455C2-BAB7-4180-A837-435078F8896A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CA893CD6-352D-46BA-BBB2-A8D58E06D822}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContactsAPI", "ContactsAPI\ContactsAPI.csproj", "{7FA08D1A-CF69-45F2-8E00-232C6D30F640}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FA08D1A-CF69-45F2-8E00-232C6D30F640}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FA08D1A-CF69-45F2-8E00-232C6D30F640}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FA08D1A-CF69-45F2-8E00-232C6D30F640}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FA08D1A-CF69-45F2-8E00-232C6D30F640}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4BC91885-6E0C-4728-9FC4-0B2DA2C04F3D}
EndGlobalSection
EndGlobal
29 changes: 14 additions & 15 deletions BackEnd/ContactsAPI/ContactsAPI/ContactsAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.4.0" />
</ItemGroup>


</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions BackEnd/ContactsAPI/ContactsAPI/Controllers/ContactsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using ContactsAPI.Data;
using ContactsAPI.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace ContactsAPI.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ContactsController : Controller
{
private readonly ContactsAPIDbContext dbContext;

public ContactsController(ContactsAPIDbContext dbContext)
{
this.dbContext = dbContext;
}


[HttpGet]
public async Task<IActionResult> GetAllContacts()
{
return Ok(await dbContext.Contacts.ToListAsync());
}

[HttpGet]
[Route("{id:guid}")]
public async Task<IActionResult> GetContact([FromRoute] Guid id)
{
var contact = await dbContext.Contacts.FindAsync(id);

if (contact == null)
{
return NotFound("Contact not found!");
}

return Ok(contact);
}

[HttpPost]
public async Task<IActionResult> AddContact(AddContactRequest addContactrequest)
{
var contact = new Contact()
{
Id = Guid.NewGuid(),
Address = addContactrequest.Address,
Email = addContactrequest.Email,
FullName = addContactrequest.FullName,
Phone = addContactrequest.Phone
};

await dbContext.Contacts.AddAsync(contact);
await dbContext.SaveChangesAsync();

return Ok(contact);
}

[HttpPut]
[Route("{id:guid}")]
public async Task<IActionResult> UpdateContact([FromRoute] Guid id, UpdateContactRequest updateContactRequest)
{
var contact = await dbContext.Contacts.FindAsync(id);

if (contact != null)
{
contact.Email = updateContactRequest.Email;
contact.FullName = updateContactRequest.FullName;
contact.Phone = updateContactRequest.Phone;
contact.Address = updateContactRequest.Address;

await dbContext.SaveChangesAsync();

return Ok(contact);
}
return NotFound();
}

[HttpDelete]
[Route("{id:guid}")]
public async Task<IActionResult> DeleteContact([FromRoute] Guid id)
{
var contact = await dbContext.Contacts.FindAsync(id);

if (contact != null)
{
dbContext.Remove(contact);
await dbContext.SaveChangesAsync();
return Ok(contact);
}

return NotFound();
}
}
}
14 changes: 14 additions & 0 deletions BackEnd/ContactsAPI/ContactsAPI/Data/ContactsAPIDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ContactsAPI.Models;
using Microsoft.EntityFrameworkCore;

namespace ContactsAPI.Data
{
public class ContactsAPIDbContext : DbContext
{
public ContactsAPIDbContext(DbContextOptions options) : base(options)
{
}

public DbSet<Contact> Contacts { get; set; }
}
}
10 changes: 10 additions & 0 deletions BackEnd/ContactsAPI/ContactsAPI/Models/AddContactRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ContactsAPI.Models
{
public class AddContactRequest
{
public string FullName { get; set; }
public string Email { get; set; }
public long Phone { get; set; }
public string Address { get; set; }
}
}
23 changes: 11 additions & 12 deletions BackEnd/ContactsAPI/ContactsAPI/Models/Contact.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ContactsAPI.Models
{
public class Contact
{
// Insert Contact Fields Here
}
}
namespace ContactsAPI.Models
{
public class Contact
{
public Guid Id { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public long Phone { get; set; }
public string Address { get; set; }
}
}
10 changes: 10 additions & 0 deletions BackEnd/ContactsAPI/ContactsAPI/Models/UpdateContactRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ContactsAPI.Models
{
public class UpdateContactRequest
{
public string FullName { get; set; }
public string Email { get; set; }
public long Phone { get; set; }
public string Address { get; set; }
}
}
56 changes: 30 additions & 26 deletions BackEnd/ContactsAPI/ContactsAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace ContactsAPI
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
using ContactsAPI.Data;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddDbContext<ContactsAPIDbContext>(options => options.UseInMemoryDatabase("ContactsDb"));

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
60 changes: 31 additions & 29 deletions BackEnd/ContactsAPI/ContactsAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49240",
"sslPort": 44305
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ContactsAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5303",
"sslPort": 44333
}
},
"profiles": {
"ContactsAPI": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7120;http://localhost:5226",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
17 changes: 8 additions & 9 deletions BackEnd/ContactsAPI/ContactsAPI/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
19 changes: 9 additions & 10 deletions BackEnd/ContactsAPI/ContactsAPI/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading