Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Customer
- {
- [Key]
- public int Id { get; set; }
- [DisplayName("Имя")]
- public string Name { get; set; }
- [DisplayName("Адрес")]
- public IList<Address> Addresses { get; set; }
- [DisplayName("Телефон")]
- public IList<Phone> Phones { get; set; }
- [DisplayName("E-mail")]
- public IList<Email> Emails { get; set; }
- [DisplayName("Обновлен")]
- public IList<ProfileUpdate> ProfileUpdates { get; set; }
- [DisplayName("Заметка")]
- public string Notes { get; set; }
- [DisplayName("Аккаунт")]
- public bool Active { get; set; } // активен ли аккаунт
- }
- public class Address
- {
- [Key]
- public int Id { get; set; }
- public string Type { get; set; }
- [DisplayName("Адрес 1")]
- public string Street1 { get; set; }
- [DisplayName("Адрес 2")]
- public string Street2 { get; set; }
- [DisplayName("Почтовый индекс")]
- public int PostalCode { get; set; }
- [DisplayName("Город")]
- public string Town { get; set; }
- }
- public class Email
- {
- [Key]
- public int Id { get; set; }
- public string Type { get; set; }
- [DisplayName("E-mail")]
- public string Value { get; set; }
- }
- public class Phone
- {
- [Key]
- public int Id { get; set; }
- public string Type { get; set; }
- [DisplayName("Телефон")]
- public long Value { get; set; }
- }
- public class ProfileUpdate
- {
- [Key]
- public int Id { get; set; }
- public DateTime UpdateDateTime { get; set; }
- }
- public async Task<ActionResult> Edit(int? id)
- {
- if (id == null)
- {
- return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
- }
- var customer = await this.db.Customers.Include(a => a.Addresses).Include(a => a.Phones).Include(a => a.Emails).Include(a => a.ProfileUpdates).SingleOrDefaultAsync(a => a.Id == id).ConfigureAwait(false);
- if (customer == null)
- {
- return this.HttpNotFound();
- }
- return this.View(customer);
- }
- // POST: Customers/Edit/5
- [HttpPost]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Edit(Customer customer)
- {
- if (!this.ModelState.IsValid)
- {
- return this.View(customer);
- }
- this.db.Entry(customer).State = EntityState.Modified;
- await this.db.SaveChangesAsync().ConfigureAwait(false);
- return this.RedirectToAction("Index");
- }
- <div class="form-horizontal">
- <h4>Customer</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- @Html.HiddenFor(model => model.Id)
- <div class="form-group">
- @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Notes, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Notes, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Notes, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Active, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- <div class="checkbox">
- @Html.EditorFor(model => model.Active)
- @Html.ValidationMessageFor(model => model.Active, "", new { @class = "text-danger" })
- </div>
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Phones, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @foreach (var phone in Model.Phones)
- {
- @Html.Label(phone.Type, htmlAttributes: new { @class = "control-label col-md-2" })
- <br/>
- @Html.EditorFor(model => phone.Value, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => phone.Value, "", new { @class = "text-danger" })
- }
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Emails, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @foreach (var email in Model.Emails)
- {
- <p>@Html.Label(email.Type, htmlAttributes: new { @class = "control-label col-md-2" })</p>
- @Html.EditorFor(model => email.Value, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => email.Value, "", new { @class = "text-danger" })
- }
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.Addresses, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @foreach (var adr in Model.Addresses)
- {
- <p>@Html.Label(adr.Type, htmlAttributes: new { @class = "control-label col-md-2" })</p>
- <p>@Html.EditorFor(model => adr.PostalCode, new { htmlAttributes = new { @class = "form-control" } })</p>
- @Html.ValidationMessageFor(model => adr.PostalCode, "", new { @class = "text-danger" })
- <p>@Html.EditorFor(model => adr.Town, new { htmlAttributes = new { @class = "form-control" } })</p>
- @Html.ValidationMessageFor(model => adr.Town, "", new { @class = "text-danger" })
- <p>@Html.EditorFor(model => adr.Street1, new { htmlAttributes = new { @class = "form-control" } })</p>
- @Html.ValidationMessageFor(model => adr.Street1, "", new { @class = "text-danger" })
- <p>@Html.EditorFor(model => adr.Street2, new { htmlAttributes = new { @class = "form-control" } })</p>
- @Html.ValidationMessageFor(model => adr.Street2, "", new { @class = "text-danger" })
- }
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Save" class="btn btn-default" />
- </div>
- </div>
- </div>
Add Comment
Please, Sign In to add comment