Guest User

Untitled

a guest
Aug 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. $(document).ready(function() {
  2. $("#add-more").click(function() {
  3. selectedColor = $("#select-color option:selected").val();
  4. if (selectedColor == '')
  5. return;
  6. var color = ' <
  7. div class = "form-group" >
  8. <
  9. label class = "col-md-2 control-label" > Color: < /label> <
  10. div class = "col-md-5" > < label class = "control-label" > ' + selectedColor + ' < /label></div >
  11. <
  12. /div>
  13. ';
  14. var sizeAndQuantity = ' <
  15. div class = "form-group" >
  16. <
  17. label class = "col-md-2 control-label" > Size and Quantity: < /label> <
  18. div class = "col-md-2" > < label class = "control-label" > S < /label><input type="text" class="form-control"></div >
  19. <
  20. div class = "col-md-2" > < label class = "control-label" > M < /label><input type="text" class="form-control"></div >
  21. <
  22. div class = "col-md-2" > < label class = "control-label" > L < /label><input type="text" class="form-control"></div >
  23. <
  24. div class = "col-md-2" > < label class = "control-label" > XL < /label><input type="text" class="form-control"></div >
  25. <
  26. /div>
  27. ';
  28. html = color + sizeAndQuantity
  29. $("#appendTarget").append(html)
  30. });
  31. });
  32.  
  33. namespace ProjectSem3.Areas.Admin.Models
  34. {
  35. public class ProductViewModel
  36. {
  37. public ProductGeneral ProductGeneral { get; set; }
  38. public List<SizeColorQuantityViewModel> SizeColorQuantities { get; set; }
  39. }
  40. public class ProductGeneral
  41. {
  42. public string Product { get; set; }
  43. public string Description { get; set; }
  44. public string ShortDescription { get; set; }
  45. public List<ProductCategory> Categories { get; set; }
  46. public string SKU { get; set; }
  47. public float Price { get; set; }
  48. public float PromotionPrice { get; set; }
  49. public bool Status { get; set; }
  50. }
  51.  
  52. public class SizeColorQuantityViewModel
  53. {
  54. public string ColorId { get; set; }
  55. public List<SizeAndQuantity> SizeAndQuantities { get; set; }
  56. }
  57. public class SizeAndQuantity
  58. {
  59. public string SizeId { get; set; }
  60. public int Quantity { get; set; }
  61. }
  62. }
  63.  
  64. public class ProductController : Controller
  65. {
  66. // GET: Admin/Product
  67. public ActionResult Create()
  68. {
  69. var colors = new List<string>() { "Red", "Blue" };
  70. var sizes = new List<string>() { "S", "M", "L", "XL" };
  71. var categories = new ProductDao().LoadProductCategory();
  72.  
  73. var productGeneral = new ProductGeneral()
  74. {
  75. Categories = categories
  76. };
  77. var model = new ProductViewModel
  78. {
  79. ProductGeneral = productGeneral,
  80. SizeColorQuantities = new List<SizeColorQuantityViewModel>()
  81. };
  82.  
  83.  
  84. foreach (var color in colors)
  85. {
  86. var child = new SizeColorQuantityViewModel
  87. {
  88. ColorId = color,
  89. SizeAndQuantities = new List<SizeAndQuantity>()
  90. };
  91. model.SizeColorQuantities.Add(child);
  92. foreach (var size in sizes)
  93. {
  94. child.SizeAndQuantities.Add(new SizeAndQuantity()
  95. {
  96. SizeId = size
  97. });
  98. }
  99. }
  100. return View(model);
  101. }
  102.  
  103. // POST: Admin/Product
  104. [HttpPost]
  105. public ActionResult Create(ProductViewModel model)
  106. {
  107. return View();
  108. }
  109. }
  110.  
  111. @for (var i = 0; i < Model.SizeColorQuantities.Count; i++)
  112. {
  113. <div class="form-group">
  114. <label class="col-md-2 control-label">Color:</label>
  115. <div class="col-md-2">
  116. @Html.TextBoxFor(m => m.SizeColorQuantities[i].ColorId, new { @class = "form-control", @readonly = "readonly" })
  117. </div>
  118. </div>
  119. <div class="form-group">
  120. <label class="col-md-2 control-label">Size and Quantity:</label>
  121. @for (var j = 0; j < Model.SizeColorQuantities[i].SizeAndQuantities.Count; j++)
  122. {
  123. <div class="col-md-2">
  124. @Html.TextBoxFor(m => m.SizeColorQuantities[i].SizeAndQuantities[j].SizeId, new
  125. {
  126. @class = "form-control",
  127. @style = "margin-bottom: 15px",
  128. @readonly = "readonly"
  129. })
  130. @Html.TextBoxFor(m => m.SizeColorQuantities[i].SizeAndQuantities[j].Quantity, new { @class = "form-control" })
  131. </div>
  132. }
  133. </div>
  134. }
Add Comment
Please, Sign In to add comment