Skip to content

Commit 76d8132

Browse files
committed
Add project files.
1 parent a5ae7cf commit 76d8132

Some content is hidden

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

61 files changed

+40067
-0
lines changed

Controllers/ContactsController.cs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Couchbase.Core;
6+
using Couchbase.Linq;
7+
using HelloCouch.Data;
8+
using HelloCouch.Models;
9+
using Microsoft.AspNetCore.Http;
10+
using Microsoft.AspNetCore.Mvc;
11+
12+
namespace HelloCouch.Controllers
13+
{
14+
public class ContactsController : Controller
15+
{
16+
private BucketContext _bucketContext;
17+
public ContactsController(BucketContext bucketContext)
18+
{
19+
_bucketContext = bucketContext;
20+
}
21+
22+
// GET: Contacts
23+
public ActionResult Index()
24+
{
25+
var allContacts = _bucketContext
26+
.Query<Contact>()
27+
.Where(x => x.Type == "Contact")
28+
.Select(x => new ContactDto
29+
{
30+
Id = N1QlFunctions.Meta(x).Id,
31+
Name = x.Name,
32+
Number = x.Number
33+
})
34+
.ToList();
35+
36+
return View(allContacts);
37+
}
38+
39+
// GET: Contacts/Details/5
40+
public ActionResult Details(string id)
41+
{
42+
var contact = _bucketContext
43+
.Query<Contact>()
44+
.Select(x => new ContactDto
45+
{
46+
Id = N1QlFunctions.Meta(x).Id,
47+
Name = x.Name,
48+
Number = x.Number
49+
})
50+
.FirstOrDefault(x => x.Id == id);
51+
return View(contact);
52+
}
53+
54+
// GET: Contacts/Create
55+
public ActionResult Create()
56+
{
57+
return View();
58+
}
59+
60+
// POST: Contacts/Create
61+
[HttpPost]
62+
[ValidateAntiForgeryToken]
63+
public ActionResult Create(ContactDto contactDto)
64+
{
65+
try
66+
{
67+
// TODO: Add insert logic here
68+
//contactsModel.Id = Guid.NewGuid().ToString();
69+
var contact = new Contact { Name = contactDto.Name, Number = contactDto.Number };
70+
_bucketContext.Save(contact);
71+
return RedirectToAction(nameof(Index));
72+
}
73+
catch (Exception e)
74+
{
75+
ModelState.TryAddModelException("exception", e);
76+
return View();
77+
}
78+
}
79+
80+
// GET: Contacts/Edit/5
81+
public ActionResult Edit(string id)
82+
{
83+
var contact = _bucketContext
84+
.Query<Contact>()
85+
.Select(x => new ContactDto
86+
{
87+
Id = N1QlFunctions.Meta(x).Id,
88+
Name = x.Name,
89+
Number = x.Number
90+
})
91+
.FirstOrDefault(x => x.Id == id);
92+
return View(contact);
93+
}
94+
95+
// POST: Contacts/Edit/5
96+
[HttpPost]
97+
[ValidateAntiForgeryToken]
98+
public ActionResult Edit(int id, ContactDto contact)
99+
{
100+
try
101+
{
102+
// TODO: Add update logic here
103+
_bucketContext.Save(new Contact { Name = contact.Name, Number = contact.Number });
104+
return RedirectToAction(nameof(Index));
105+
}
106+
catch (Exception e)
107+
{
108+
ModelState.TryAddModelException("exception", e);
109+
return View();
110+
}
111+
}
112+
113+
// GET: Contacts/Delete/5\
114+
[HttpGet(Name = "Delete")]
115+
public ActionResult ConfirmDelete(string id)
116+
{
117+
var contact = _bucketContext
118+
.Query<Contact>()
119+
.Select(x => new ContactDto
120+
{
121+
Id = N1QlFunctions.Meta(x).Id,
122+
Name = x.Name,
123+
Number = x.Number
124+
})
125+
.FirstOrDefault(x => x.Id == id);
126+
return View(contact);
127+
}
128+
129+
// POST: Contacts/Delete/5
130+
[HttpPost]
131+
[ValidateAntiForgeryToken]
132+
public ActionResult Delete(string id)
133+
{
134+
try
135+
{
136+
// TODO: Add delete logic here
137+
var contact = _bucketContext.Query<Contact>().FirstOrDefault(x => N1QlFunctions.Meta(x).Id == id);
138+
if (contact == null)
139+
return NotFound();
140+
_bucketContext.Remove(contact);
141+
return RedirectToAction(nameof(Index));
142+
}
143+
catch
144+
{
145+
return View();
146+
}
147+
}
148+
}
149+
}

Controllers/HomeController.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Logging;
8+
using HelloCouch.Models;
9+
10+
namespace HelloCouch.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private readonly ILogger<HomeController> _logger;
15+
16+
public HomeController(ILogger<HomeController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
public IActionResult Index()
22+
{
23+
return View();
24+
}
25+
26+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
27+
public IActionResult Error()
28+
{
29+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
30+
}
31+
}
32+
}

Data/Contact.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace HelloCouch.Data
7+
{
8+
public class Contact
9+
{
10+
public string Name { get; set; }
11+
public string Number { get; set; }
12+
public string Type => typeof(Contact).Name;
13+
}
14+
}

Data/IContactsBucketProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Couchbase.Extensions.DependencyInjection;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace HelloCouch.Data
8+
{
9+
public interface IContactsBucketProvider: INamedBucketProvider
10+
{
11+
}
12+
}

HelloCouch.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Couchbase.Extensions.DependencyInjection" Version="2.0.2" />
9+
<PackageReference Include="CouchbaseNetClient" Version="2.7.15" />
10+
<PackageReference Include="Linq2Couchbase" Version="1.4.2" />
11+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
12+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
13+
</ItemGroup>
14+
15+
16+
17+
</Project>

HelloCouch.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.29613.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloCouch", "HelloCouch.csproj", "{C3EE177F-9C7C-4D17-8FFB-AF46F0059CE5}"
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+
{C3EE177F-9C7C-4D17-8FFB-AF46F0059CE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C3EE177F-9C7C-4D17-8FFB-AF46F0059CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C3EE177F-9C7C-4D17-8FFB-AF46F0059CE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C3EE177F-9C7C-4D17-8FFB-AF46F0059CE5}.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 = {AB6192EB-E1BA-4D4C-9745-340DA21E63D3}
24+
EndGlobalSection
25+
EndGlobal

Models/ContactDto.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace HelloCouch.Models
8+
{
9+
public class ContactDto
10+
{
11+
[Key]
12+
public string Id { get; set; }
13+
public string Name { get; set; }
14+
public string Number { get; set; }
15+
}
16+
}

Models/ErrorViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace HelloCouch.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

Models/TravelModel.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace HelloCouch.Models
8+
{
9+
public class TravelModel
10+
11+
{
12+
[JsonProperty("callsign")]
13+
public string Callsign { get; set; }
14+
15+
[JsonProperty("country")]
16+
public string Country { get; set; }
17+
18+
[JsonProperty("iata")]
19+
public string Iata { get; set; }
20+
21+
[JsonProperty("icao")]
22+
public string Icao { get; set; }
23+
24+
[JsonProperty("id")]
25+
public long Id { get; set; }
26+
27+
[JsonProperty("name")]
28+
public string Name { get; set; }
29+
30+
[JsonProperty("type")]
31+
public string Type { get; set; }
32+
}
33+
}

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 HelloCouch
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+
}

Properties/launchSettings.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:56570",
7+
"sslPort": 44362
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"HelloCouch": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
}
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)