-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from marcosdosea/Branch_samuel158
Branch samuel158
- Loading branch information
Showing
11 changed files
with
536 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Core.Service | ||
{ | ||
public interface IPessoaService | ||
{ | ||
int Create(Pessoa pessoa); | ||
void Edit(Pessoa pessoa); | ||
void Delete(int id); | ||
Pessoa Get(int id); | ||
IEnumerable<Pessoa> GetAll(); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Codigo/ModernSchool/ModernSchool/Controllers/PessoaController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using AutoMapper; | ||
using Core.Service; | ||
using Core; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ModernSchoolWEB.Models; | ||
|
||
namespace ModernSchoolWEB.Controllers | ||
{ | ||
public class PessoaController : Controller | ||
{ | ||
private readonly IPessoaService _pessoaService; | ||
private readonly IMapper _mapper; | ||
|
||
public PessoaController(IPessoaService pessoaService, IMapper mapper) | ||
{ | ||
_pessoaService = pessoaService; | ||
_mapper = mapper; | ||
} | ||
|
||
// GET: PessoaController | ||
public ActionResult Index() | ||
{ | ||
var listaPessoas = _pessoaService.GetAll(); | ||
var listaPessoasModel = _mapper.Map<List<PessoaViewModel>>(listaPessoas); | ||
return View(listaPessoasModel); | ||
} | ||
|
||
// GET: PessoaController/Details/5 | ||
public ActionResult Details(int id) | ||
{ | ||
Pessoa pessoa = _pessoaService.Get(id); | ||
PessoaViewModel pessoaModel = _mapper.Map<PessoaViewModel>(pessoa); | ||
return View(pessoaModel); | ||
} | ||
|
||
// GET: PessoaController/Create | ||
public ActionResult Create() | ||
{ | ||
return View(); | ||
} | ||
|
||
// POST: PessoaController/Create | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Create(PessoaViewModel pessoaModel) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var pessoa = _mapper.Map<Pessoa>(pessoaModel); | ||
_pessoaService.Create(pessoa); | ||
} | ||
return RedirectToAction(nameof(Index)); | ||
|
||
} | ||
|
||
// GET: PessoaController/Edit/5 | ||
public ActionResult Edit(int id) | ||
{ | ||
Pessoa pessoa = _pessoaService.Get(id); | ||
PessoaViewModel pessoaModel = _mapper.Map<PessoaViewModel>(pessoa); | ||
return View(pessoaModel); | ||
} | ||
|
||
// POST: PessoaController/Edit/5 | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Edit(int id, PessoaViewModel pessoaViewModel) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var pessoa = _mapper.Map<Pessoa>(pessoaViewModel); | ||
_pessoaService.Edit(pessoa); | ||
} | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
|
||
// GET: PessoaController/Delete/5 | ||
public ActionResult Delete(int id) | ||
{ | ||
Pessoa pessoa = _pessoaService.Get(id); | ||
PessoaViewModel pessoaModel = _mapper.Map<PessoaViewModel>(pessoa); | ||
return View(pessoaModel); | ||
} | ||
|
||
// POST: PessoaController/Delete/5 | ||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public ActionResult Delete(int id, PessoaViewModel pessoaViewModel) | ||
{ | ||
_pessoaService.Delete(id); | ||
return RedirectToAction(nameof(Index)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using AutoMapper; | ||
using Core; | ||
using ModernSchoolWEB.Models; | ||
|
||
namespace ModernSchoolWEB.Mappers | ||
{ | ||
public class PessoaProfile : Profile | ||
{ | ||
public PessoaProfile() | ||
{ | ||
CreateMap<PessoaViewModel, Pessoa>().ReverseMap(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Codigo/ModernSchool/ModernSchool/Models/PessoaViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Xml.Linq; | ||
|
||
namespace ModernSchoolWEB.Models | ||
{ | ||
public class PessoaViewModel | ||
{ | ||
public int Id { get; set; } | ||
public string? Nome { get; set; } | ||
public string? Cpf { get; set; } | ||
public int Idade { get; set; } | ||
public string? Rua { get; set; } | ||
public string? Bairro { get; set; } | ||
public int Numero { get; set; } | ||
public DateTime? DataNascimento { get; set; } | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Codigo/ModernSchool/ModernSchool/Views/Pessoa/Create.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@model ModernSchoolWEB.Models.PessoaViewModel | ||
|
||
<h4>PessoaViewModel</h4> | ||
<hr /> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form asp-action="Create"> | ||
<div asp-validation-summary="ModelOnly" class="text-danger"></div> | ||
<div class="form-group"> | ||
<label asp-for="Id" class="control-label"></label> | ||
<input asp-for="Id" class="form-control" /> | ||
<span asp-validation-for="Id" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Nome" class="control-label"></label> | ||
<input asp-for="Nome" class="form-control" /> | ||
<span asp-validation-for="Nome" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Cpf" class="control-label"></label> | ||
<input asp-for="Cpf" class="form-control" /> | ||
<span asp-validation-for="Cpf" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Idade" class="control-label"></label> | ||
<input asp-for="Idade" class="form-control" /> | ||
<span asp-validation-for="Idade" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Rua" class="control-label"></label> | ||
<input asp-for="Rua" class="form-control" /> | ||
<span asp-validation-for="Rua" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Bairro" class="control-label"></label> | ||
<input asp-for="Bairro" class="form-control" /> | ||
<span asp-validation-for="Bairro" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Numero" class="control-label"></label> | ||
<input asp-for="Numero" class="form-control" /> | ||
<span asp-validation-for="Numero" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="DataNascimento" class="control-label"></label> | ||
<input asp-for="DataNascimento" class="form-control" /> | ||
<span asp-validation-for="DataNascimento" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<input type="submit" value="Create" class="btn btn-primary" /> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<a asp-action="Index">Back to List</a> | ||
</div> | ||
|
||
@section Scripts { | ||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");} | ||
} |
62 changes: 62 additions & 0 deletions
62
Codigo/ModernSchool/ModernSchool/Views/Pessoa/Delete.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@model ModernSchoolWEB.Models.PessoaViewModel | ||
|
||
<h3>Are you sure you want to delete this?</h3> | ||
<div> | ||
<h4>PessoaViewModel</h4> | ||
<hr /> | ||
<dl class="row"> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Id) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Id) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Nome) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Nome) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Cpf) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Cpf) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Idade) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Idade) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Rua) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Rua) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Bairro) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Bairro) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Numero) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Numero) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.DataNascimento) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.DataNascimento) | ||
</dd> | ||
</dl> | ||
|
||
<form asp-action="Delete"> | ||
<input type="submit" value="Delete" class="btn btn-danger" /> | | ||
<a asp-action="Index">Back to List</a> | ||
</form> | ||
</div> |
60 changes: 60 additions & 0 deletions
60
Codigo/ModernSchool/ModernSchool/Views/Pessoa/Details.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@model ModernSchoolWEB.Models.PessoaViewModel | ||
|
||
<div> | ||
<h4>PessoaViewModel</h4> | ||
<hr /> | ||
<dl class="row"> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Id) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Id) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Nome) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Nome) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Cpf) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Cpf) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Idade) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Idade) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Rua) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Rua) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Bairro) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Bairro) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.Numero) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.Numero) | ||
</dd> | ||
<dt class = "col-sm-2"> | ||
@Html.DisplayNameFor(model => model.DataNascimento) | ||
</dt> | ||
<dd class = "col-sm-10"> | ||
@Html.DisplayFor(model => model.DataNascimento) | ||
</dd> | ||
</dl> | ||
</div> | ||
<div> | ||
@Html.ActionLink("Edit", "Edit", new { id = Model.Id }) | | ||
<a asp-action="Index">Back to List</a> | ||
</div> |
Oops, something went wrong.