Update Runtime Object Asp.Net MVC

0

I have a difficulty in an action. I want to update an object at runtime, for example, I have a request, that request is in approved state. except that by unsubscribing this request, I want to change the status of it to FINALIZED. The problem is that I am wanting to make the change, for the low controller and not the request.

Vr = Class / Entity Application ----- Mv = Class / Low Entity ----- MvVr = Low Request

I tried to create a method but it gives an error.

ActionGetCode

publicActionResultMvVr(intid){Vrvrs=newVr();vrs=vrs.BuscarPorIdDaVr(id);Mvmv=newMv();mv.Vrs=vrs;returnView(mv);}

ActionPostCode

[HttpPost][ValidateAntiForgeryToken]publicActionResultMvVr(MvobjMv,intVrId){objMv.Id=0;if(ModelState.IsValid){varidentity=User.IdentityasClaimsIdentity;varlogin=identity.Claims.FirstOrDefault(c=>c.Type=="Id").Value;
            var usuario = db.UsuariosDb.FirstOrDefault(u => u.Id.ToString() == login);
            objMv.IdUsuario = usuario.Id; // Usuário que Finalizou a Vr

            // ALterar estado da Solicitação
            Vr vr = new Vr();
            vr = vr.BuscarPorId(VrId);
            vr.Situacao = Situacao.Finalizado;
            vr.AtualizarSituacao(vr);

            objMv.VrId = VrId;
            db.MvDb.Add(objMv);
            db.SaveChanges();
            TempData["Sucesso"] = "Baixa Realizada Com Sucesso.";
            return RedirectToAction("Index", "Painel");
        }
        TempData["Errado"] = "Favor Preencher os Campos Corretamente.";
        return View(objMv);
    }

Mediode Code

     public void AtualizarSituacao([Bind(Include = "VrId,DataServico,DataSolicitacao,HoraServico,TempoProvavel,Situacao,ServicoExecultado,Itinerario,IdVeiculo,IdMotorista,IdUsuario")] Vr vr)
    {

        db.Entry(vr).State = EntityState.Modified;
        db.SaveChanges();
    }
    
asked by anonymous 14.05.2018 / 16:57

0 answers