diff --git a/ASP.NET Core Basics/src/Contacts/Contacts.csproj b/ASP.NET Core Basics/src/Contacts/Contacts.csproj index be7e935..c817625 100644 --- a/ASP.NET Core Basics/src/Contacts/Contacts.csproj +++ b/ASP.NET Core Basics/src/Contacts/Contacts.csproj @@ -20,6 +20,7 @@ + diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml new file mode 100644 index 0000000..8c5a371 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml @@ -0,0 +1,65 @@ +@page +@model Contacts.Pages.ContactsRazorPages.CreateModel + +@{ + ViewData["Title"] = "Create"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Create

+ +

Contact

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ +
+ Back to List +
+ +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml.cs b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml.cs new file mode 100644 index 0000000..9c0ebcf --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Create.cshtml.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Contacts.Data; +using Contacts.Models; + +namespace Contacts.Pages.ContactsRazorPages +{ + public class CreateModel : PageModel + { + private readonly Contacts.Data.ContactsContext _context; + + public CreateModel(Contacts.Data.ContactsContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + return Page(); + } + + [BindProperty] + public Contact Contact { get; set; } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Contact.Add(Contact); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } + } +} \ No newline at end of file diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml new file mode 100644 index 0000000..fafaeea --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml @@ -0,0 +1,65 @@ +@page +@model Contacts.Pages.ContactsRazorPages.DeleteModel + +@{ + ViewData["Title"] = "Delete"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Contact

+
+
+
+ @Html.DisplayNameFor(model => model.Contact.Name) +
+
+ @Html.DisplayFor(model => model.Contact.Name) +
+
+ @Html.DisplayNameFor(model => model.Contact.Address) +
+
+ @Html.DisplayFor(model => model.Contact.Address) +
+
+ @Html.DisplayNameFor(model => model.Contact.City) +
+
+ @Html.DisplayFor(model => model.Contact.City) +
+
+ @Html.DisplayNameFor(model => model.Contact.State) +
+
+ @Html.DisplayFor(model => model.Contact.State) +
+
+ @Html.DisplayNameFor(model => model.Contact.PostalCode) +
+
+ @Html.DisplayFor(model => model.Contact.PostalCode) +
+
+ @Html.DisplayNameFor(model => model.Contact.Phone) +
+
+ @Html.DisplayFor(model => model.Contact.Phone) +
+
+ @Html.DisplayNameFor(model => model.Contact.Email) +
+
+ @Html.DisplayFor(model => model.Contact.Email) +
+
+ +
+ + | + Back to List +
+
diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml.cs b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml.cs new file mode 100644 index 0000000..8dbd90d --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Delete.cshtml.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Contacts.Data; +using Contacts.Models; + +namespace Contacts.Pages.ContactsRazorPages +{ + public class DeleteModel : PageModel + { + private readonly Contacts.Data.ContactsContext _context; + + public DeleteModel(Contacts.Data.ContactsContext context) + { + _context = context; + } + + [BindProperty] + public Contact Contact { get; set; } + + public async Task OnGetAsync(int? id) + { + if (id == null) + { + return NotFound(); + } + + Contact = await _context.Contact.SingleOrDefaultAsync(m => m.Id == id); + + if (Contact == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync(int? id) + { + if (id == null) + { + return NotFound(); + } + + Contact = await _context.Contact.FindAsync(id); + + if (Contact != null) + { + _context.Contact.Remove(Contact); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } + } +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml new file mode 100644 index 0000000..9c9fff5 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml @@ -0,0 +1,62 @@ +@page +@model Contacts.Pages.ContactsRazorPages.DetailsModel + +@{ + ViewData["Title"] = "Details"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Details

+ +
+

Contact

+
+
+
+ @Html.DisplayNameFor(model => model.Contact.Name) +
+
+ @Html.DisplayFor(model => model.Contact.Name) +
+
+ @Html.DisplayNameFor(model => model.Contact.Address) +
+
+ @Html.DisplayFor(model => model.Contact.Address) +
+
+ @Html.DisplayNameFor(model => model.Contact.City) +
+
+ @Html.DisplayFor(model => model.Contact.City) +
+
+ @Html.DisplayNameFor(model => model.Contact.State) +
+
+ @Html.DisplayFor(model => model.Contact.State) +
+
+ @Html.DisplayNameFor(model => model.Contact.PostalCode) +
+
+ @Html.DisplayFor(model => model.Contact.PostalCode) +
+
+ @Html.DisplayNameFor(model => model.Contact.Phone) +
+
+ @Html.DisplayFor(model => model.Contact.Phone) +
+
+ @Html.DisplayNameFor(model => model.Contact.Email) +
+
+ @Html.DisplayFor(model => model.Contact.Email) +
+
+
+
+ Edit | + Back to List +
diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml.cs b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml.cs new file mode 100644 index 0000000..cc4557e --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Details.cshtml.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Contacts.Data; +using Contacts.Models; + +namespace Contacts.Pages.ContactsRazorPages +{ + public class DetailsModel : PageModel + { + private readonly Contacts.Data.ContactsContext _context; + + public DetailsModel(Contacts.Data.ContactsContext context) + { + _context = context; + } + + public Contact Contact { get; set; } + + public async Task OnGetAsync(int? id) + { + if (id == null) + { + return NotFound(); + } + + Contact = await _context.Contact.SingleOrDefaultAsync(m => m.Id == id); + + if (Contact == null) + { + return NotFound(); + } + return Page(); + } + } +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml new file mode 100644 index 0000000..842537b --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml @@ -0,0 +1,66 @@ +@page +@model Contacts.Pages.ContactsRazorPages.EditModel + +@{ + ViewData["Title"] = "Edit"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Edit

+ +

Contact

+
+
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ +
+ Back to List +
+ +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml.cs b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml.cs new file mode 100644 index 0000000..57c3fd2 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Edit.cshtml.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; +using Contacts.Data; +using Contacts.Models; + +namespace Contacts.Pages.ContactsRazorPages +{ + public class EditModel : PageModel + { + private readonly Contacts.Data.ContactsContext _context; + + public EditModel(Contacts.Data.ContactsContext context) + { + _context = context; + } + + [BindProperty] + public Contact Contact { get; set; } + + public async Task OnGetAsync(int? id) + { + if (id == null) + { + return NotFound(); + } + + Contact = await _context.Contact.SingleOrDefaultAsync(m => m.Id == id); + + if (Contact == null) + { + return NotFound(); + } + return Page(); + } + + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(Contact).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + + } + + return RedirectToPage("./Index"); + } + } +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml new file mode 100644 index 0000000..81c8af3 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml @@ -0,0 +1,73 @@ +@page +@model Contacts.Pages.ContactsRazorPages.IndexModel + +@{ + ViewData["Title"] = "Index"; + Layout = "~/Views/Shared/_Layout.cshtml"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + + + + + +@foreach (var item in Model.Contact) { + + + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.Contact[0].Name) + + @Html.DisplayNameFor(model => model.Contact[0].Address) + + @Html.DisplayNameFor(model => model.Contact[0].City) + + @Html.DisplayNameFor(model => model.Contact[0].State) + + @Html.DisplayNameFor(model => model.Contact[0].PostalCode) + + @Html.DisplayNameFor(model => model.Contact[0].Phone) + + @Html.DisplayNameFor(model => model.Contact[0].Email) +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Address) + + @Html.DisplayFor(modelItem => item.City) + + @Html.DisplayFor(modelItem => item.State) + + @Html.DisplayFor(modelItem => item.PostalCode) + + @Html.DisplayFor(modelItem => item.Phone) + + @Html.DisplayFor(modelItem => item.Email) + + Edit | + Details | + Delete +
diff --git a/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml.cs b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml.cs new file mode 100644 index 0000000..ce676d7 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/ContactsRazorPages/Index.cshtml.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using Contacts.Data; +using Contacts.Models; + +namespace Contacts.Pages.ContactsRazorPages +{ + public class IndexModel : PageModel + { + private readonly Contacts.Data.ContactsContext _context; + + public IndexModel(Contacts.Data.ContactsContext context) + { + _context = context; + } + + public IList Contact { get;set; } + + public async Task OnGetAsync() + { + Contact = await _context.Contact.ToListAsync(); + } + } +} diff --git a/ASP.NET Core Basics/src/Contacts/Pages/_ValidationScriptsPartial.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..185300a --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/_ValidationScriptsPartial.cshtml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/ASP.NET Core Basics/src/Contacts/Pages/_ViewImports.cshtml b/ASP.NET Core Basics/src/Contacts/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..1f109e7 --- /dev/null +++ b/ASP.NET Core Basics/src/Contacts/Pages/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using RazorPages +@namespace RazorPages.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/ASP.NET Core Basics/src/Contacts/Views/Shared/_Layout.cshtml b/ASP.NET Core Basics/src/Contacts/Views/Shared/_Layout.cshtml index 53959b0..b09160e 100644 --- a/ASP.NET Core Basics/src/Contacts/Views/Shared/_Layout.cshtml +++ b/ASP.NET Core Basics/src/Contacts/Views/Shared/_Layout.cshtml @@ -32,6 +32,7 @@