Skip to content

Commit 7fb8d73

Browse files
authored
Merge pull request #26 from alexandrunastase/master
Updated database schema & migrations, Contact model and added some minor fixes
2 parents 258ff82 + 587c981 commit 7fb8d73

25 files changed

+772
-1843
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ The following resources were helpful in setting up this template:
123123
- [Stack Overflow - Token Based Authentication in ASP.NET Core](http://stackoverflow.com/questions/30546542/token-based-authentication-in-asp-net-core-refreshed)
124124
- [SPA example of a token based authentication implementation using the Aurelia front end framework and ASP.NET core]( https://github.com/alexandre-spieser/AureliaAspNetCoreAuth)
125125
- [A Real-World React.js Setup for ASP.NET Core and MVC5](https://www.simple-talk.com/dotnet/asp-net/a-real-world-react-js-setup-for-asp-net-core-and-mvc)
126+
- [Customising ASP.NET Core Identity EF Core naming conventions for PostgreSQL](https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql)
126127
- My own perseverance because this took a _lot_ of time to get right 😁

api.test/ControllerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ControllerTests
88
public void Test1()
99
{
1010
var contact = new aspnetCoreReactTemplate.Models.Contact();
11-
Assert.True(string.IsNullOrEmpty(contact.email));
11+
Assert.True(string.IsNullOrEmpty(contact.Email));
1212
}
1313
}
1414
}

api.test/Unit/Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public void TestNewContactProperties()
1010
{
1111
var contact = new app.Models.Contact();
1212

13-
Assert.True(string.IsNullOrEmpty(contact.lastName));
14-
Assert.True(string.IsNullOrEmpty(contact.firstName));
15-
Assert.True(string.IsNullOrEmpty(contact.email));
16-
Assert.True(string.IsNullOrEmpty(contact.phone));
13+
Assert.True(string.IsNullOrEmpty(contact.LastName));
14+
Assert.True(string.IsNullOrEmpty(contact.FirstName));
15+
Assert.True(string.IsNullOrEmpty(contact.Email));
16+
Assert.True(string.IsNullOrEmpty(contact.Phone));
1717
}
1818
}
1919
}

api/Controllers/ContactController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ContactsController(DefaultDbContext context)
2323
[HttpGet]
2424
public IEnumerable<Contact> Get()
2525
{
26-
return _context.Contacts.OrderBy((o)=> o.lastName);
26+
return _context.Contacts.OrderBy((o)=> o.LastName);
2727
}
2828

2929
// GET api/contacts/5
@@ -38,8 +38,8 @@ public Contact Get(int id)
3838
public IEnumerable<Contact> Search(string q)
3939
{
4040
return _context.Contacts.
41-
Where((c)=> c.lastName.ToLower().Contains(q.ToLower()) || c.firstName.ToLower().Contains(q.ToLower())).
42-
OrderBy((o) => o.lastName);
41+
Where((c)=> c.LastName.ToLower().Contains(q.ToLower()) || c.FirstName.ToLower().Contains(q.ToLower())).
42+
OrderBy((o) => o.LastName);
4343
}
4444

4545
// POST api/contacts
@@ -53,7 +53,7 @@ public async Task<IActionResult> Post([FromBody]Contact model)
5353

5454
_context.Contacts.Add(model);
5555
await _context.SaveChangesAsync();
56-
return CreatedAtRoute("GetContact", new { id = model.contactId }, model);
56+
return CreatedAtRoute("GetContact", new { id = model.Id }, model);
5757
}
5858

5959
// PUT api/contacts/5
@@ -65,7 +65,7 @@ public async Task<IActionResult> Put(int id, [FromBody]Contact model)
6565
return BadRequest(ModelState);
6666
}
6767

68-
model.contactId = id;
68+
model.Id = id;
6969
_context.Update(model);
7070
await _context.SaveChangesAsync();
7171
return Ok();
@@ -75,7 +75,7 @@ public async Task<IActionResult> Put(int id, [FromBody]Contact model)
7575
[HttpDelete("{id}")]
7676
public async Task<IActionResult> Delete(int id)
7777
{
78-
var contact = new Contact() { contactId = id };
78+
var contact = new Contact() { Id = id };
7979
_context.Entry(contact).State = EntityState.Deleted;
8080

8181
await _context.SaveChangesAsync();

api/Extensions/StringExtension.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Text.RegularExpressions;
2+
3+
namespace aspnetCoreReactTemplate.Extensions
4+
{
5+
public static class StringExtensions
6+
{
7+
public static string ToSnakeCase(this string input)
8+
{
9+
if (string.IsNullOrEmpty(input))
10+
{
11+
return input;
12+
}
13+
14+
var startUnderscores = Regex.Match(input, @"^_+");
15+
return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower();
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)