How do I approve a model depending on the confirmation of another model?

1

How do I make the View of request only appear to the user, when the confirmation of class Aprovacao is true .

Follow logic:

The user creates the request and registers,

2- User waits for confirmation of request made

3- if the request is approved

4 user can see the registered request

Models:

public class Solicitacao
{
    public int SolicitacaoId { get; set; }

    public bool Status { get; set; }


    public string servico { get; set; }
}

I would like this class to confirm the request

public class Aprovacao
{
    public  int AprovacaoId  { get; set; }


    public string Aprova { get; set; }

   public int SolicitacaoId { get; set; }

   public virtual Solicitacao _Solicitacao{ get; set; }

}

View:

@using (Html.BeginForm()) 
 {
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>Solicitacao</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="checkbox">
                @Html.EditorFor(model => model.Status)
                @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Servico, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Servico, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Servico, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Create" class="btn btn-default" />
        </div>
    </div>
</div>
}

What method would I use to make this commit in%% of Approval?

    
asked by anonymous 15.05.2017 / 23:24

1 answer

0

When saving your request you can redirect the user to the screen with the lists of all the requests:

    [HttpPost]
    public ActionResult Create(Solicitacao solicitacao)
    {
        SeuRepositorio.SalvarSolicitacao(solicitacao);
        return RedirectToAction("Index");
    }

In the view index you can list all open requests on the system, and display a message to the user that there are requests that have not yet been approved.

These requests can be displayed in an ordered table, displaying unapproved records at the beginning, or even unapproved records rows can be highlighted in red.

Then in your Action Index it would look like this:

    public ActionResult Index()
    {
        List<Solicitacao> solicitacoes = SeuRepositorio.ObterTodasAsSolicitacoes();
        return View(solicitacoes);
    }

I'm assuming that the status field of the request is what indicates that it is approved or not.

Now in your View Index you create your table, I recommend using the bootstrap to make it easier to use the highlight lines:

@model List<AprovadorDeSolicitacoes.Models.Solicitacao>
<table class="table table-hover table-striped">
<thead>
    <tr>
        <th>Id</th>
        <th>Solicitacao</th>
        <th>#</th>
    </tr>
</thead>
<tbody>
    @foreach(var item in this.Model)
    {
        <tr class="@(item.Status ? "success" : "danger")">
            <td>@item.SolicitacaoId </td>
            <td>@item.servico  </td>
            <td>
                <a href="/Solicitacao/Detalhes/@item.SolicitacaoId">detalhes</a>
            </td>
        </tr>
    }
</tbody>
</table>

In turn in the details link where you redirect to the detail action you can do another validation and redirect the user to the appropriate view:

    public ActionResult Detalhes(int id)
    {
        var solicitacao = SeuRepositorio.AbrirSolicitacao(id);
        if(!solicitacao.Status)
            return View("ViewComMensagemDeNaoAprovado", solicitacao);
        return View(solicitacao); // manda para sua view que exibe os detalhes da solicitação já aprovada.
    }

I hope I have helped.

    
16.05.2017 / 19:36