0
I have a table, where I return the vacation records of each employee, and I need to create a page, where the user can request the change of this period. However, the demand requires that the data be in the same "table". Therefore, I need to do a foreach in the holiday table, and put the change fields(table requirement) in the same view.
This image exemplifies the final result I need to obtain.
In this case, the Start Date and End Date belong to the vacation class, and the rest to the requirement class. My demand is that the user click edit, the table enable the fields Initial date change and final date change, for the user to put the dates you want, and so I save this data in the database, in the table requirement.
In the database, I return the "Start Date and End Date" data from a View, called Vacation, and the "Start Date Change and End Date Change" data must be saved in a table called Requirements.
I don’t know how I can do it, if I use Viewmodel, javascript, Jquery, etc.
Saving 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>
You can always create two fields
[NotMapped]
(one for the initial change date and one for the end date) in the holiday class, to fill in the values that are in the requirement class. To save the data, in the controller, just fetch the returned value from the view and save the data in the required class– CesarMiguel
@Cesarmiguel edited the question with my method to save, would help in how I take the values to use in the controller?
– Randrade
You can use a Viewmodel
– Rod
Yeah, or use a Viewmodel. You have both tables with some connection, right? Foreign key or something
– CesarMiguel
@Cesarmiguel do not have, because the Holiday table is a View in Sql, I do not have access to the table itself, only to View.
– Randrade
Explain it better, you have two tables right? One with the Initial and Final Date, and one with the Initial Date Change and Final Date Change. Am I right? What is called each of these tables?
– CesarMiguel
@Cesarmiguel, exactly that. I edited with the names of each table
– Randrade
@Renilsonandrade, do you have the holiday table and request? I’m sorry but that’s what I keep reading the question
– CesarMiguel
I have View Vacations and Table requirement
– Randrade