Skip to content

Commit

Permalink
Merge pull request #246 from marcosdosea/Branch_samuel158
Browse files Browse the repository at this point in the history
Branch samuel158
  • Loading branch information
matheusmt12 authored Oct 22, 2022
2 parents f0f28fe + 75a35d1 commit 5f15dd8
Show file tree
Hide file tree
Showing 11 changed files with 536 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Codigo/ModernSchool/Core/Service/IPessoaService.cs
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 Codigo/ModernSchool/ModernSchool/Controllers/PessoaController.cs
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));
}
}
}
14 changes: 14 additions & 0 deletions Codigo/ModernSchool/ModernSchool/Mappers/PessoaProfile.cs
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 Codigo/ModernSchool/ModernSchool/Models/PessoaViewModel.cs
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; }


}
}
2 changes: 1 addition & 1 deletion Codigo/ModernSchool/ModernSchool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Main(string[] args)
builder.Services.AddTransient<IAvaliacaoService, AvaliacaoService>();
builder.Services.AddTransient<ICargoService, CargoService>();
builder.Services.AddTransient<IGovernoService, GovernoService>();
//builder.Services.AddTransient<IPessoaService, PessoaService>();
builder.Services.AddTransient<IPessoaService, PessoaService>();
builder.Services.AddTransient<ITurmaService, TurmaService>();
builder.Services.AddTransient<IUnidadeTematicaService, UnidadeTematicaService>();
builder.Services.AddTransient<IAnoLetivoService, AnoLetivoService>();
Expand Down
62 changes: 62 additions & 0 deletions Codigo/ModernSchool/ModernSchool/Views/Pessoa/Create.cshtml
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 Codigo/ModernSchool/ModernSchool/Views/Pessoa/Delete.cshtml
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 Codigo/ModernSchool/ModernSchool/Views/Pessoa/Details.cshtml
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>
Loading

0 comments on commit 5f15dd8

Please sign in to comment.