Guest User

Untitled

a guest
Feb 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. public class Customer
  2. {
  3. [Key]
  4. public int Id { get; set; }
  5.  
  6. [DisplayName("Имя")]
  7. public string Name { get; set; }
  8.  
  9. [DisplayName("Адрес")]
  10. public IList<Address> Addresses { get; set; }
  11.  
  12. [DisplayName("Телефон")]
  13. public IList<Phone> Phones { get; set; }
  14.  
  15. [DisplayName("E-mail")]
  16. public IList<Email> Emails { get; set; }
  17.  
  18. [DisplayName("Обновлен")]
  19. public IList<ProfileUpdate> ProfileUpdates { get; set; }
  20.  
  21. [DisplayName("Заметка")]
  22. public string Notes { get; set; }
  23.  
  24. [DisplayName("Аккаунт")]
  25. public bool Active { get; set; } // активен ли аккаунт
  26. }
  27. public class Address
  28. {
  29. [Key]
  30. public int Id { get; set; }
  31.  
  32. public string Type { get; set; }
  33.  
  34. [DisplayName("Адрес 1")]
  35. public string Street1 { get; set; }
  36.  
  37. [DisplayName("Адрес 2")]
  38. public string Street2 { get; set; }
  39.  
  40. [DisplayName("Почтовый индекс")]
  41. public int PostalCode { get; set; }
  42.  
  43. [DisplayName("Город")]
  44. public string Town { get; set; }
  45. }
  46. public class Email
  47. {
  48. [Key]
  49. public int Id { get; set; }
  50.  
  51. public string Type { get; set; }
  52.  
  53. [DisplayName("E-mail")]
  54. public string Value { get; set; }
  55. }
  56. public class Phone
  57. {
  58. [Key]
  59. public int Id { get; set; }
  60.  
  61. public string Type { get; set; }
  62.  
  63. [DisplayName("Телефон")]
  64. public long Value { get; set; }
  65. }
  66. public class ProfileUpdate
  67. {
  68. [Key]
  69. public int Id { get; set; }
  70.  
  71. public DateTime UpdateDateTime { get; set; }
  72. }
  73.  
  74. public async Task<ActionResult> Edit(int? id)
  75. {
  76. if (id == null)
  77. {
  78. return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  79. }
  80.  
  81. 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);
  82. if (customer == null)
  83. {
  84. return this.HttpNotFound();
  85. }
  86.  
  87. return this.View(customer);
  88. }
  89.  
  90. // POST: Customers/Edit/5
  91. [HttpPost]
  92. [ValidateAntiForgeryToken]
  93. public async Task<ActionResult> Edit(Customer customer)
  94. {
  95. if (!this.ModelState.IsValid)
  96. {
  97. return this.View(customer);
  98. }
  99.  
  100. this.db.Entry(customer).State = EntityState.Modified;
  101. await this.db.SaveChangesAsync().ConfigureAwait(false);
  102. return this.RedirectToAction("Index");
  103. }
  104.  
  105. <div class="form-horizontal">
  106. <h4>Customer</h4>
  107. <hr />
  108. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  109. @Html.HiddenFor(model => model.Id)
  110.  
  111. <div class="form-group">
  112. @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
  113. <div class="col-md-10">
  114. @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
  115. @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
  116. </div>
  117. </div>
  118.  
  119. <div class="form-group">
  120. @Html.LabelFor(model => model.Notes, htmlAttributes: new { @class = "control-label col-md-2" })
  121. <div class="col-md-10">
  122. @Html.EditorFor(model => model.Notes, new { htmlAttributes = new { @class = "form-control" } })
  123. @Html.ValidationMessageFor(model => model.Notes, "", new { @class = "text-danger" })
  124. </div>
  125. </div>
  126.  
  127. <div class="form-group">
  128. @Html.LabelFor(model => model.Active, htmlAttributes: new { @class = "control-label col-md-2" })
  129. <div class="col-md-10">
  130. <div class="checkbox">
  131. @Html.EditorFor(model => model.Active)
  132. @Html.ValidationMessageFor(model => model.Active, "", new { @class = "text-danger" })
  133. </div>
  134. </div>
  135. </div>
  136.  
  137. <div class="form-group">
  138. @Html.LabelFor(model => model.Phones, htmlAttributes: new { @class = "control-label col-md-2" })
  139. <div class="col-md-10">
  140. @foreach (var phone in Model.Phones)
  141. {
  142. @Html.Label(phone.Type, htmlAttributes: new { @class = "control-label col-md-2" })
  143. <br/>
  144. @Html.EditorFor(model => phone.Value, new { htmlAttributes = new { @class = "form-control" } })
  145. @Html.ValidationMessageFor(model => phone.Value, "", new { @class = "text-danger" })
  146. }
  147. </div>
  148. </div>
  149.  
  150. <div class="form-group">
  151. @Html.LabelFor(model => model.Emails, htmlAttributes: new { @class = "control-label col-md-2" })
  152. <div class="col-md-10">
  153. @foreach (var email in Model.Emails)
  154. {
  155. <p>@Html.Label(email.Type, htmlAttributes: new { @class = "control-label col-md-2" })</p>
  156. @Html.EditorFor(model => email.Value, new { htmlAttributes = new { @class = "form-control" } })
  157. @Html.ValidationMessageFor(model => email.Value, "", new { @class = "text-danger" })
  158. }
  159. </div>
  160. </div>
  161.  
  162. <div class="form-group">
  163. @Html.LabelFor(model => model.Addresses, htmlAttributes: new { @class = "control-label col-md-2" })
  164. <div class="col-md-10">
  165. @foreach (var adr in Model.Addresses)
  166. {
  167. <p>@Html.Label(adr.Type, htmlAttributes: new { @class = "control-label col-md-2" })</p>
  168. <p>@Html.EditorFor(model => adr.PostalCode, new { htmlAttributes = new { @class = "form-control" } })</p>
  169. @Html.ValidationMessageFor(model => adr.PostalCode, "", new { @class = "text-danger" })
  170. <p>@Html.EditorFor(model => adr.Town, new { htmlAttributes = new { @class = "form-control" } })</p>
  171. @Html.ValidationMessageFor(model => adr.Town, "", new { @class = "text-danger" })
  172. <p>@Html.EditorFor(model => adr.Street1, new { htmlAttributes = new { @class = "form-control" } })</p>
  173. @Html.ValidationMessageFor(model => adr.Street1, "", new { @class = "text-danger" })
  174. <p>@Html.EditorFor(model => adr.Street2, new { htmlAttributes = new { @class = "form-control" } })</p>
  175. @Html.ValidationMessageFor(model => adr.Street2, "", new { @class = "text-danger" })
  176. }
  177. </div>
  178. </div>
  179.  
  180. <div class="form-group">
  181. <div class="col-md-offset-2 col-md-10">
  182. <input type="submit" value="Save" class="btn btn-default" />
  183. </div>
  184. </div>
  185. </div>
Add Comment
Please, Sign In to add comment