I have a table, which returns the holiday records of each employee, and I need to create a page where the user can request the change of that period. However, the demand requires that the data be in the same "table". So, I need to do a foreach on the vacation table, and put the change fields (request table) in the same view.
This image exemplifies the final result that I need to get.
Inthiscase,theStartDateandEndDatebelongstotheVacationclass,andtheremaindertheclassrequest.Myrequestisthattheuserclickedit,thetablewillenablethefieldsChangestartdateandenddatechange,sotheuserputthedateshewants,andsoIsavethisdatainthedatabase,intherequesttable.>
Inthedatabase,Ireturnthedata"Start Date and End Date" of a View, called Holidays, and the data "Start Date Change and Final Date Change" should be saved in a table called Requirements. >
I do not know how I can do this, if I use ViewModel, javascript, Jquery, etc.
Save method:
[HttpPost]
public ActionResult Ferias(Requerimento requerimento)
{
if (ModelState.IsValid)
{
try
{
requerimento.sLotacao = SessionHelper.Lotacao;
requerimento.sNome = SessionHelper.Nome;
if (SessionHelper.Celular == null || SessionHelper.Celular == " ")
{
requerimento.sTelefone = SessionHelper.Telefone;
}
else
{
requerimento.sCelular = SessionHelper.Celular;
}
requerimento.sEndereco = SessionHelper.Endereco;
requerimento.sEmail = SessionHelper.Email;
requerimento.sVinculo = SessionHelper.Vinculo;
requerimento.sCargo = SessionHelper.Cargo;
requerimento.dtDataRequerimento = DateTime.Now;
requerimento.iMatricula = SessionHelper.Matricula;
requerimento.sSituacao = "Aberto";
requerimento.sTipoRequerimento = "Ferias";
requerimentosRepository.Inserir(requerimento);
TempData["Mensagem"] = "Requerimento cadastrado com sucesso";
}
catch (Exception ex)
{
TempData["Mensagem"] = ex.Message;
}
return RedirectToAction("MeusRequerimentos");
}
var errors = ModelState.Values.SelectMany(v => v.Errors);
Debug.Write(errors);
return View(requerimento);
}
View:
@model IEnumerable<PortalRH.DomainModel.Entities.FuncionariosFerias>
@{
ViewBag.Title = "Minhas Férias";
}
<div class="Nome">
<p><strong><font face="Arial" size="2"> @ViewBag.Matricula / @ViewBag.Contrato - @ViewBag.Nome</font></strong></p>
</div>
<div class="mapLocal">
<img src="~/Content/img/sitemap.ico" width="19" height="19" /> Você está em: <i>@ViewBag.Title</i>
</div>
<br />
<div class="row">
<div class="col-md-2">
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h5><strong>Férias</strong></h5>
</div>
<table class="table table-condensed">
<tr>
<th>Inicio Férias</th>
<th>Fim Férias</th>
<th>Inicio Férias Alteração</th>
<th>Fim Férias Alteração</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.DtInicioPeriodo)</td>
<td>@Html.DisplayFor(modelItem => item.DtFimPeriodo)</td>
<td>@Html.DisplayFor(modelItem => item.DtInicioAlteracao)</td>
<td>@Html.DisplayFor(modelItem => item.DtFimAlteracao)</td>
<td>Editar</td>
</tr>
}
</table>
</div>
</div>
</div>