Created
September 27, 2017 00:18
-
-
Save anonymous/b46d7265681b8ec38b1afdd756ab4ac5 to your computer and use it in GitHub Desktop.
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
Pessoal a organização do projeto na empresa onde eu trabalho esta dividida da seguinte forma : | |
IntranetDAL ---> Todos as classes que fazem conexão com o banco | |
IntranetRepository ---> Model e Repository | |
web ---> Controllers e Views | |
Um exemplo de código : | |
IntranetRepository ---> Model ---> Objetivo.cs | |
``` | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace intranetRepository.Pim.Model | |
{ | |
public class Objetivo | |
{ | |
public int Id { get; set; } | |
public string Descricao { get; set; } | |
public string Validade { get; set; } | |
} | |
} | |
``` | |
intranetRepository ---> Repository ---> ObjetivoRepository.cs | |
``` | |
using intranetRepository.Pim.Model; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using ns_pim; | |
using ns_pim.StrongTypesNS; | |
using System.Data; | |
namespace intranetRepository.Pim.Repository | |
{ | |
public class ObjetivoRepository | |
{ | |
public string Gravar(Objetivo pObjetivo) | |
{ | |
using (var pim = new PIM(new InfraProgress().BuscaBroker(), "", "", "")) | |
{ | |
pim.pim_manut_objetivo(0, "I", pObjetivo.Descricao, pObjetivo.Validade, out string msg); | |
return msg; | |
} | |
} | |
public string Remover(Objetivo pObjetivo) | |
{ | |
using (var pim = new PIM(new InfraProgress().BuscaBroker(), "", "", "")) | |
{ | |
pim.pim_manut_objetivo(pObjetivo.Id, "D", "", "", out string msg); | |
return msg; | |
} | |
} | |
public string Alterar(Objetivo pObjetivo) | |
{ | |
using (var pim = new PIM(new InfraProgress().BuscaBroker(), "", "", "")) | |
{ | |
pim.pim_manut_objetivo(pObjetivo.Id, "I", pObjetivo.Descricao, pObjetivo.Validade, out string msg); | |
return msg; | |
} | |
} | |
public List<Objetivo> Listar(string descricao) | |
{ | |
using (var pim = new PIM(new InfraProgress().BuscaBroker(), "", "", "")) | |
{ | |
pim.pim_listar_objetivo_descr(descricao, out dsPimListaObjetivoDescrDataSet myDs, out string msg); | |
var objetivos = new List<Objetivo>(); | |
foreach (DataRow linha in myDs.Tables[0].Rows) | |
{ | |
var objetivo = new Objetivo() | |
{ | |
Id = int.Parse(linha["cCod_objetivo"].ToString()), | |
Descricao = linha["cDescr_objetivo"].ToString(), | |
Validade = linha["cValidade"].ToString() | |
}; | |
objetivos.Add(objetivo); | |
} | |
return objetivos; | |
} | |
} | |
} | |
} | |
``` | |
Web ---> Pim ---> Controller ---> ObjetivoController.cs | |
``` | |
using intranetRepository; | |
using intranetRepository.Pim.Model; | |
using intranetRepository.Pim.Repository; | |
using System; | |
using System.Web.Mvc; | |
using System.Web.Script.Serialization; | |
namespace web.Areas.PIM.Controllers | |
{ | |
public class ObjetivoController : Controller | |
{ | |
// GET: PIM/Objetivo | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
public ActionResult Gravar(string pDescricao, string pValidade) | |
{ | |
var objetivo = new Objetivo() { Descricao = pDescricao, Validade = pValidade }; | |
var msg = new ObjetivoRepository().Gravar(objetivo); | |
AlertaModel alerta = new AlertaModel(); | |
if (msg != "OK") | |
{ | |
alerta.Tipo = "E"; | |
alerta.Titulo = "Falha ao gravar."; | |
alerta.Mensagem = msg; | |
} | |
return Json(alerta, JsonRequestBehavior.AllowGet); | |
} | |
public ActionResult Alterar(int pId, string pDescricao, string pValidade) | |
{ | |
var objetivo = new Objetivo() { Id = pId, Descricao = pDescricao, Validade = pValidade }; | |
var msg = new ObjetivoRepository().Alterar(objetivo); | |
AlertaModel alerta = new AlertaModel(); | |
if (msg != "OK") | |
{ | |
alerta.Tipo = "E"; | |
alerta.Titulo = "Falha ao alterar."; | |
alerta.Mensagem = msg; | |
} | |
return Json(alerta, JsonRequestBehavior.AllowGet); | |
} | |
public ActionResult Remover(int pId) | |
{ | |
var objetivo = new Objetivo() { Id = pId }; | |
var msg = new ObjetivoRepository().Remover(objetivo); | |
AlertaModel alerta = new AlertaModel(); | |
if (msg != "OK") | |
{ | |
alerta.Tipo = "E"; | |
alerta.Titulo = "Falha ao remover."; | |
alerta.Mensagem = msg; | |
} | |
return Json(alerta, JsonRequestBehavior.AllowGet); | |
} | |
public ActionResult Listar(string pDescricao = "") | |
{ | |
var serializer = new JavaScriptSerializer(); | |
serializer.MaxJsonLength = Int32.MaxValue; | |
var objetivos = new ObjetivoRepository().Listar(pDescricao); | |
var result = new ContentResult | |
{ | |
Content = serializer.Serialize(objetivos), | |
ContentType = "application/json" | |
}; | |
return result; | |
} | |
} | |
} | |
``` | |
Web ---> Pim ---> Views ---> Objetivo ---> Index.cshtml | |
``` | |
@{ | |
ViewBag.NomeSistema = "Manutenção de Objetivos"; | |
} | |
<form id="form"> | |
<div class="row"> | |
<div class="col-sm-10"> | |
<label for="descricao">Descrição</label> | |
<input type="text" name="txbCodigo" id="txbCodigo" hidden /> | |
<input type="text" name="txbDescricao" id="txbDescricao" class="form-control" /> | |
</div> | |
<div class="col-sm-2"> | |
<label for="txbValidade">Validade</label> | |
<input type="text" name="txbValidade" id="txbValidade" class="form-control" /> | |
</div> | |
</div> | |
<br /> | |
<div class="row"> | |
<div class="col-sm-12"> | |
<button type="button" id="btnGravar" class="btn btn-primary">Gravar</button> | |
<button type="button" id="btnListar" class="btn btn-primary">Listar</button> | |
<button type="button" id="btnCancelar" class="btn btn-primary">Cancelar</button> | |
</div> | |
</div> | |
<br /> | |
<table class="table table-hover" id="lista" style="display:none;"> | |
<thead> | |
<tr> | |
<th>Código</th> | |
<th>Descrição</th> | |
<th>Validade</th> | |
<th></th> | |
</tr> | |
</thead> | |
<tbody> | |
</tbody> | |
</table> | |
</form> | |
<div class="modal fade" id="myModalConfirmaExclusao" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
<h4 class="modal-title" id="myModalLabel">Confirmação</h4> | |
</div> | |
<div class="modal-body"> | |
Confirma a exclusão? | |
<input id="hiddenIdModalConfirmaExclusao" type="hidden" /> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button> | |
<button type="button" id="btnModalConfirmaExclusao" class="btn btn-danger" data-dismiss="modal">Confirma</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="~/Areas/Pim/Views/Objetivo/Index.js?v=@ApplicationInstance.Application["myJavaVersion"]"></script> | |
``` | |
Web ---> Pim ---> Views ---> Objetivo ---> Index.js | |
``` | |
datePckr('#txbValidade'); | |
$('#txbCodigo').val('0'); | |
$('#btnGravar').on('click', function () { | |
var param = { | |
pId: $('#txbCodigo').val(), | |
pDescricao : $('#txbDescricao').val(), | |
pValidade : $('#txbValidade').val() | |
}; | |
$.ajax({ | |
url: '/Pim/Objetivo/Gravar', | |
data: param, | |
beforeSend: function () { | |
adicionarLoadingTela(); | |
} | |
}).done(function (result) { | |
$('#txbDescricao').val(''); | |
if (result.Tipo !== 'S') { | |
exibirMensagem(result); | |
} | |
removerLoadingTela(); | |
$('#btnListar').trigger('click'); | |
}); | |
}); | |
$('#btnListar').on('click', function () { | |
limpar(); | |
var param = { pDescricao: $('#descricao').val() } | |
$.ajax({ | |
url: '/Pim/Objetivo/Listar', | |
data: param, | |
beforeSend: function () { | |
adicionarLoadingTela(); | |
} | |
}).done(function (result) { | |
$('table tbody').empty(); | |
$('table').show(); | |
$.each(result, function () { | |
$('table tbody').append($("<tr style='cursor:pointer'></tr>") | |
.append($("<td></td>").text(this.Id)) | |
.append($("<td></td>").text(this.Descricao)) | |
.append($("<td></td>").text(this.Validade)) | |
.append($("<td><i class='fa fa-times fa-lg text-danger' title='Excluir'></i></td>")) | |
); | |
}); | |
$("table tbody tr").on('click', function () { | |
$('#txbCodigo').val($($(this).find('td').get(0)).text()); | |
$('#txbDescricao').val($($(this).find('td').get(1)).text()); | |
$('#txbValidade').val($($(this).find('td').get(2)).text()); | |
}); | |
$(".fa-times").on('click', function () { | |
var id = $('td:first', $(this).parents('tr')).text(); | |
$('#hiddenIdModalConfirmaExclusao').val(id); | |
$('#myModalConfirmaExclusao').modal('show'); | |
}); | |
removerLoadingTela(); | |
}); | |
}); | |
$('#btnCancelar').on('click', function () { | |
limpar(); | |
}); | |
$('#btnModalConfirmaExclusao').on('click', function () { | |
$('#txbDescricao').val(''); | |
var param = { | |
pId: $('#hiddenIdModalConfirmaExclusao').val() | |
}; | |
$.ajax({ | |
url: '/Pim/Objetivo/Remover', | |
data: param, | |
beforeSend: function () { | |
adicionarLoadingTela(); | |
} | |
}).done(function (result) { | |
if (result.Tipo !== 'S') { | |
exibirMensagem(result); | |
} | |
removerLoadingTela(); | |
$('#btnListar').trigger('click'); | |
}); | |
}); | |
function limpar() { | |
$('table tbody').empty(); | |
$('table').hide(); | |
$('#txbCodigo').val('0'); | |
$('#txbDescricao').val(''); | |
$('#txbValidade').val(''); | |
} | |
``` | |
Estou iniciando esse curso sobre Solid com C# e gostaria da opinião de vocês sobre essa estrutura. | |
O que vocês acham? O que posso melhorar? | |
Agradeço a atenção de vocês. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment