The Steuerpult;
[Autorisieren (Rollen = „Inputter“)]
[HttpPost]
allgemeines ActionResult redigieren (int contractId, FormCollection formValues)
{
wenn (ModelState.IsValid)
{
Anwendung (var DB = neues ITOCEntities ())
{
var-Vertrag = DB. Contracts.Single (x => x.ContractId == contractId);
Schnurbuchstabe = contract.ContractNo_Letter;
UpdateModel (Vertrag, „Verträge“, formValues);
wenn (contract.ContractNo_Letter! = Buchstabe)
contract.ContractNo_Number = Contract.AutogenerateContractNumber (contract.ContractNo_Letter);
var clientContact = DB. Contacts.Single (x => x.ContactId == contract.ClientContactId);
UpdateModel (clientContact, „Kontakt“, formValues);
var contractAdministrationContact =
DB. Contacts.Single (x => x.ContactId == contract.ContractAdministratorContactId);
UpdateModel (contractAdministrationContact, „Kontakt“, formValues);
db.SaveChanges ();
}
RückholRedirectToAction („Liste“);
}
Rückholansicht ();
}
------------------------------------------------------------
Das ViewModel
allgemeine Kategorie ContractViewModel
{
//private ITOCEntities DB = neues ITOCEntities ();
Vertrag des allgemeinen Vertrages {erhalten; Satz; }
allgemeine IList contractTypes {erhalten; Satz; }
allgemeines IEnumerable contractTypesSelectList
{
erhalten
{
this.contractTypes.Select (Einzelteil => neues SelectListItem zurückbringen
{
Text = item.ContractType1,
Wert = item.ContractTypeId.ToString ()
});
}
}
allgemeines Kontakt clientContact {erhalten; Satz; }
allgemeines Kontakt contractAdministratorContact {erhalten; Satz; }
allgemeines ContractViewModel ()
{
Anwendung (var DB = neues ITOCEntities ())
{
this.contractTypes = db.ContractTypes.ToList ();
this.clientContact = neuer Kontakt ();
this.contractAdministratorContact = neuer Kontakt ();
this.clientContact.ContactTypeId =
db.ContactTypes.Where (x => x.ContactType1 == „Klient“) .SingleOrDefault () .ContactTypeId;
this.contractAdministratorContact.ContactTypeId =
db.ContactTypes.Where (x => x.ContactType1 == „CA“) .SingleOrDefault () .ContactTypeId;
}
}
allgemeines ContractViewModel (int contractId)
{
Anwendung (var DB = neues ITOCEntities ())
{
this.contractTypes = db.ContractTypes.ToList ();
this.contract = DB. Contracts.Where (x => x.ContractId == contractId) .SingleOrDefault ();
this.clientContact =
DB. Contacts.Where (x => x.ContactId == this.contract.ClientContactId) .SingleOrDefault ();
this.contractAdministratorContact =
DB. Contacts.Where (x => x.ContactId == this.contract.ContractAdministratorContactId) .SingleOrDefault ();
}
}
--------------------------------------------------------
Der ViewModel Hinweis in der Ansicht;
<%@ Seite Title= "" Language= " C# " MasterPageFile= " ~/Views/Shared/Site.Master "
Inherits= " System.Web.Mvc.ViewPage " %>
|