Escolar Documentos
Profissional Documentos
Cultura Documentos
ALUNO:
Disciplina:
PROGRAMAO DINMICA
Data da Aplicao:
Professor:
EDER
Nota:
07/05/2015
Razor. Utilizando o caractere @ para iniciar um expresso de condio ou apresentar o contedo de uma
varivel. Quando voc exibe o contedo de uma pgina utilizando o carter @, o ASP.NET RAZOR
codifica a sada, substituindo caracteres reservados do HTML com os cdigos que permitem que sejam
exibidos como texto em uma pgina web ao invs de serem interpretados como tag HTML.
4) Qual a importncia do BIND entre o Model e a View?
Unio de dados que refere-se ao processo de ajuste automtico e propriedades de um ou mais controles de
formulrio em tempo de execuo a partir de uma estrutura que contm dados. Com ligao de dados, voc
no precisa escrever explicitamente o cdigo que instancia uma conexo e cria um conjunto de dados
(como voc faria com um formulrio independente). Os assistentes associados com o Windows Forms
escrever o cdigo ADO.NET necessrio para voc. Formulrios do Windows permitem que voc ligar
facilmente a quase qualquer estrutura que contm dados.
NotMapped como exemplo pode ser calculada a partir da propriedade DataDeNascimento. Portanto, no
necessrio armazenar o valor da idade no banco de dados. Nesses casos, podemos utilizar a anotao
NotMapped e indicar quais propriedades no devem ser mapeadas nas tabelas
PRTICA
CONTATO (atributos) cdigos e descrio
CLASSE CLIENTE (ATRIBUTOS) "cdigos e nome", entre o contato cliente teremos uma associao pai
contato
CLASSE USUARIO (atributos) "cdigo nome e-mail e senha", entre cliente e usurio existe um associao
tambm aonde o pai o cliente.
1 Codifique os controle de criao e de listagem de cada entidade.
2 Identifique o resource, action e parmetros da questo anterior.
3 Codifique a VIEW de cada entidade utilizando os Helpers.
1 Codifique os controle de criao e de listagem de cada entidade.
Contato Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Controllers
{
public class ContatoController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Details(int id)
{
return View();
}
3
{
return View();
}
}
}
}
Cliente Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Controllers
{
public class ClienteController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Details(int id)
{
return View();
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
public ActionResult Edit(int id)
{
return View();
5
}
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
public ActionResult Delete(int id)
{
return View();
}
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
Usuario Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Controllers
{
public class UsuarioController : Controller
{
public ActionResult Index()
6
{
return View();
}
public ActionResult Details(int id)
{
return View();
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
public ActionResult Edit(int id)
{
return View();
}
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
public ActionResult Delete(int id)
{
return View();
}
7
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
2 Identifique o resource, action e parmetros da questo anterior.
ClienteController/index/01
ContatoController/index/02
UsusarioController/index/03
3 Codifique a VIEW de cada entidade utilizando os Helpers.
Cliente View:
@model IEnumerable<WebApplication2.Models.ClienteModels>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.condigo)
</th>
<th>
@Html.DisplayNameFor(model => model.nome)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.condigo)
</td>
<td>
@Html.DisplayFor(modelItem => item.nome)
</td>
8
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
Usuario View:
@model IEnumerable<WebApplication2.Models.UsuarioModels>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.condigo)
</th>
<th>
@Html.DisplayNameFor(model => model.nome)
</th>
<th>
@Html.DisplayNameFor(model => model.email)
</th>
<th>
@Html.DisplayNameFor(model => model.senha)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.condigo)
</td>
<td>
@Html.DisplayFor(modelItem => item.nome)
</td>
<td>
@Html.DisplayFor(modelItem => item.email)
</td>
<td>
@Html.DisplayFor(modelItem => item.senha)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
9
</td>
</tr>
}
</table>
Contato View:
@model IEnumerable<WebApplication2.Models.ContatoModels>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.condigo)
</th>
<th>
@Html.DisplayNameFor(model => model.descrio)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.condigo)
</td>
<td>
@Html.DisplayFor(modelItem => item.descrio)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
10