Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.42 KB | None | 0 0
  1. [HttpGet]
  2. public ActionResult DierBewerken(int id)
  3. {
  4.  
  5. DierInfoService dierinfoservice = new DierInfoService();
  6. var nieuweform = new DierInfoGrootForm();
  7.  
  8.  
  9. List<Identificatie> identificatielijst = dierinfoservice.GetIdentificatieViaId(id);
  10. List<IdentificatieInfo> identificatieinfoLijst = new List<IdentificatieInfo>();
  11.  
  12. foreach (Identificatie identificiatie in identificatielijst)
  13. {
  14.  
  15. if (identificiatie.TypeIdentificatie == "CHIP")
  16. { typeidentificatie = IdentificatieInfo.TypeIdentificatieEnum.CHIP; }
  17. else
  18. { typeidentificatie = IdentificatieInfo.TypeIdentificatieEnum.TATOEAGE; }
  19.  
  20.  
  21. if (identificiatie.TatoeagePlaats == "NEK")
  22. {
  23. tatoeageplaats = IdentificatieInfo.IdentificiatiePlaats.NEK;
  24. }
  25. else if (identificiatie.TatoeagePlaats == "OOR")
  26. {
  27. tatoeageplaats = IdentificatieInfo.IdentificiatiePlaats.OOR;
  28. }
  29. else if (identificiatie.TatoeagePlaats == "BIL")
  30. {
  31. tatoeageplaats = IdentificatieInfo.IdentificiatiePlaats.BIL;
  32. }
  33. else
  34. {
  35. tatoeageplaats = null;
  36. }
  37.  
  38. if (identificiatie.TatoeageAanduiding == "LINKS")
  39. {
  40. tatoeageaanduiding = IdentificatieInfo.IdentificiatieAanduiding.LINKS;
  41. }
  42. else if (identificiatie.TatoeageAanduiding == "RECHTS")
  43. {
  44. tatoeageaanduiding = IdentificatieInfo.IdentificiatieAanduiding.RECHTS;
  45. }
  46. else
  47. {
  48. tatoeageaanduiding = null;
  49. }
  50.  
  51. if (identificiatie.ChipPlaats == "NEK")
  52. {
  53. chipplaats = IdentificatieInfo.IdentificiatiePlaats.NEK;
  54. }
  55. else if (identificiatie.ChipPlaats == "OOR")
  56. {
  57. chipplaats = IdentificatieInfo.IdentificiatiePlaats.OOR;
  58. }
  59. else if (identificiatie.ChipPlaats == "BIL")
  60. {
  61. chipplaats = IdentificatieInfo.IdentificiatiePlaats.BIL;
  62. }
  63. else
  64. {
  65. chipplaats = null;
  66. }
  67.  
  68. if (identificiatie.ChipAanduiding == "LINKS")
  69. {
  70. chipaanduiding = IdentificatieInfo.IdentificiatieAanduiding.LINKS;
  71. }
  72. else if (identificiatie.ChipAanduiding == "RECHTS")
  73. {
  74. chipaanduiding = IdentificatieInfo.IdentificiatieAanduiding.RECHTS;
  75. }
  76. else
  77. {
  78. chipaanduiding = null;
  79. }
  80.  
  81. identificatieinfoLijst.Add(
  82. new IdentificatieInfo(identificiatie.IdentificatieID, typeidentificatie, identificiatie.TatoeageNummer, tatoeageplaats,
  83. tatoeageaanduiding, identificiatie.ChipNummer, chipplaats, chipaanduiding));
  84. }
  85.  
  86. List<FysischeKenmerkenInfo> fysischeKenmerkeninfoKortLijst = new List<FysischeKenmerkenInfo>();
  87. fysischeKenmerkeninfoKortLijst = dierinfoservice.GetFysischeKenmerkenKortViaId(id);
  88.  
  89.  
  90. string NUllwaarde;
  91. int NUllID;
  92. Dier dier = db.Dier.Find(id);
  93. //var fysischeKenmerken = db.FysischeKenmerken.Where(m => m.Dier_DierID == id).ToList();
  94. DierInfo dierinfo = new DierInfo();
  95. if (dier.Ras1 == null)
  96. {
  97. NUllwaarde = "";
  98. NUllID = 0;
  99. }
  100. else
  101. {
  102. NUllwaarde = dier.Ras1.RasNaam;
  103. NUllID = (int)dier.Ras_RasIDKruising;
  104. }
  105. dierinfo.DierID = id;
  106. dierinfo.Diernaam = dier.Diernaam;
  107. dierinfo.Geboortdatum = dier.Geboortdatum;
  108. dierinfo.Geslacht = dier.Geslacht;
  109. dierinfo.Kruising = dier.Kruising;
  110. dierinfo.VermoedelijkeGeboortejaar = dier.VermoedelijkeGeboortejaar;
  111. dierinfo.RasID2 = NUllID;
  112. dierinfo.RasID = dier.Ras_RasID;
  113.  
  114. //ViewBag.HerkenningsObject_HerkenningsObjectID = new SelectList(db.HerkenningsObject, "HerkenningsObjectID", "HerkenningsObjectKenmerk" , ); ;
  115. ViewBag.Ras_RasID = new SelectList(db.Ras, "RasID", "RasNaam", dier.Ras_RasID);
  116. ViewBag.Ras_RasIDKruising = new SelectList(db.Ras, "RasID", "RasNaam", dier.Ras_RasIDKruising);
  117.  
  118. //ViewBag.Ras_RasID = new SelectList(db.HerkenningsObject, "HerkenningsObjectID", "HerkenningsObjectKenmerk", fysischeKenmerken. );
  119. //ViewBag.Ras_RasIDKruising = new SelectList(db.Ras, "RasID", "RasNaam", dier.Ras_RasIDKruising);
  120.  
  121. nieuweform.Identificatieinfos = identificatieinfoLijst;
  122. nieuweform.FysischeKenmerkenInfos = fysischeKenmerkeninfoKortLijst;
  123. nieuweform.Dierinfo = dierinfo;
  124. nieuweform.NieuweFysischeKenmerkenInfos = new List<FysischeKenmerkenInfo>();
  125. nieuweform.NieuweIdentificatieinfos = new List<IdentificatieInfo>();
  126.  
  127. return View(nieuweform);
  128.  
  129. }
  130.  
  131. [HttpPost]
  132. //[ValidateAntiForgeryToken]
  133. public ActionResult DierBewerken(DierInfoGrootForm form)
  134. //public ActionResult DierBewerken([Bind(Include = "DierID,Ras_RasID,Kruising,Ras_RasIDKruising,Diernaam,Geboortdatum,VermoedelijkeGeboortejaar,Geslacht")] Dier dier)
  135. {
  136.  
  137. if (ModelState.IsValid)
  138. {
  139.  
  140.  
  141. foreach (var item in form.Identificatieinfos)
  142. {
  143. Identificatie identificatie = new Identificatie
  144. {
  145. Dier_DierID = form.Dierinfo.DierID,
  146. IdentificatieDatum = DateTime.Now,
  147. IdentificatieID = item.IdentificatieID,
  148. TypeIdentificatie = item.TypeIdentificatieEnumeration.ToString(),
  149. TatoeageNummer = item.TatoeageNummer,
  150. TatoeagePlaats = item.TatoeagePlaats.ToString() ?? null,
  151. TatoeageAanduiding = item.TatoeageAanduiding.ToString() ?? null,
  152. ChipNummer = item.ChipNummer,
  153. ChipPlaats = item.ChipPlaats.ToString() ?? null,
  154. ChipAanduiding = item.ChipAanduiding.ToString() ?? null
  155. };
  156. db.Entry(identificatie).State = EntityState.Modified;
  157.  
  158. }
  159.  
  160. Dier dier = new Dier
  161. {
  162. DierID = form.Dierinfo.DierID,
  163. Diernaam = form.Dierinfo.Diernaam,
  164. Geslacht = form.Dierinfo.Geslacht,
  165. Kruising = form.Dierinfo.Kruising,
  166. Ras_RasID = form.Dierinfo.RasID,
  167. Ras_RasIDKruising = form.Dierinfo.RasID2,
  168. Geboortdatum = form.Dierinfo.Geboortdatum,
  169. VermoedelijkeGeboortejaar = form.Dierinfo.VermoedelijkeGeboortejaar
  170. };
  171.  
  172.  
  173. db.Entry(dier).State = EntityState.Modified;
  174. db.SaveChanges();
  175. return RedirectToAction("OverzichtDieren");
  176. }
  177. //ViewBag.Ras_RasID = new SelectList(db.Ras, "RasID", "RasNaam", dier.Ras_RasID);
  178. //ViewBag.Ras_RasIDKruising = new SelectList(db.Ras, "RasID", "RasNaam", dier.Ras_RasIDKruising);
  179. return View(form);
  180. //return View(dier);
  181. }
  182.  
  183. namespace Dierenasiel_MVC_Eindwerk.Models
  184. {
  185. public class DierInfoGrootForm
  186. {
  187. public int DierId { get; set; }
  188. public DierInfo Dierinfo { get; set; }
  189. public List<IdentificatieInfo> Identificatieinfos { get; set; }
  190. public List<FysischeKenmerkenInfo> FysischeKenmerkenInfos { get; set; }
  191. public List<IdentificatieInfo> NieuweIdentificatieinfos { get; set; }
  192. public List<FysischeKenmerkenInfo> NieuweFysischeKenmerkenInfos { get; set; }
  193.  
  194. public List<Herkenningsobjecten> Herkenningsobjectens { get; set; }
  195.  
  196.  
  197. }
  198. }
  199.  
  200. @for (int index = 0; index < Model.Identificatieinfos.Count(); index++)
  201.  
  202.  
  203. {
  204.  
  205. @Html.HiddenFor(model => model.Identificatieinfos[index].IdentificatieID)
  206. <tr>
  207. <th scope="row">@(index + 1)</th>
  208. @*<td>@Html.EditorFor(model => model.Identificatieinfos[i], new { htmlAttributes = new { @class = "form-control" } })</td>*@
  209. @*<td>@Html.DropDownListFor(m => m.Identificatieinfos[i].TypeEn , new SelectList( Enum.GetValues() )),"Selecteer identificatie")</td>*@
  210. <td>
  211. @Html.EnumDropDownListFor(model => model.Identificatieinfos[index].TypeIdentificatieEnumeration, "Selecteer identificatie", new { @class = "fields-select form-control" ,
  212. @onchange = "onSelectChange(this , index);"
  213. })
  214. </td>
  215. @if (@Model.Identificatieinfos[index].TypeIdentificatieEnumeration.ToString() == "CHIP")
  216. {
  217. <td>@Html.EditorFor(model => model.Identificatieinfos[index].ChipNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  218. <td>@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].ChipPlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  219. <td>@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].ChipAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  220. <td class="d-none">@Html.EditorFor(model => model.Identificatieinfos[index].TatoeageNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  221. <td class="d-none">@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].TatoeagePlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  222. <td class="d-none">@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].TatoeageAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  223. }
  224. else if (@Model.Identificatieinfos[index].TypeIdentificatieEnumeration.ToString() == "TATOEAGE")
  225. {
  226. <td class="d-none">@Html.EditorFor(model => model.Identificatieinfos[index].ChipNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  227. <td class="d-none">@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].ChipPlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  228. <td class="d-none">@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].ChipAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  229. <td>@Html.EditorFor(model => model.Identificatieinfos[index].TatoeageNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  230. <td>@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].TatoeagePlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  231. <td>@Html.EnumDropDownListFor(model => model.Identificatieinfos[index].TatoeageAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  232. }
  233.  
  234. </tr>
  235. //index++;
  236. }
  237.  
  238. <tr class="col" id="IdentificatieToevoegen">
  239. <th scope="row">#</th>
  240. <td colspan="4">
  241.  
  242.  
  243.  
  244. <div class="btn btn-friendly form-control text-left" name="1" value="1">@Html.ActionLink("Identificatie toevoegen", "DierBewerken", new { Bijvoegen = "identificatie" })</div>
  245.  
  246.  
  247.  
  248.  
  249. </td>
  250. </tr>
  251. </tbody>
  252. </table>
  253. @*@Model.NieuweIdentificatieinfos.Add(new Dierenasiel_MVC_Eindwerk.Models.HerdefinerenClasses.IdentificatieInfo("TATOEAGE", "15qsdq14", "NEK", "LINKS", null, null, null))*@
  254. @*Dierenasiel_MVC_Eindwerk.Models.HerdefinerenClasses.IdentificatieInfo.TypeIdentificatieEnum.TATOEAGE*@
  255. @*//new Dierenasiel_MVC_Eindwerk.Models.HerdefinerenClasses.IdentificatieInfo.TypeIdentificatieEnum.*@
  256. </div> @*div table identificatie*@
  257.  
  258. @if (Model.NieuweIdentificatieinfos.Count() > 0)
  259. {
  260. <div class="form-group col">
  261.  
  262. <table class="table table-striped">
  263. <thead>
  264. <tr>
  265. <th scope="col">#</th>
  266. <th scope="col">Type identificatie</th>
  267. <th scope="col">Nummer</th>
  268. <th scope="col">Plaats</th>
  269. <th scope="col">Zijde</th>
  270. </tr>
  271. </thead>
  272. <tbody>
  273.  
  274. @for (int index = 0; index < Model.NieuweIdentificatieinfos.Count(); index++)
  275.  
  276. //foreach (var item in @ViewBag.IdentificatieinfoLijst)
  277. {
  278.  
  279. @*@Html.HiddenFor(model => model.NieuweIdentificatieinfos[index].IdentificatieID)*@
  280. <tr>
  281. <th scope="row">@(index + 1)</th>
  282. @*<td>@Html.EditorFor(model => model.Identificatieinfos[i], new { htmlAttributes = new { @class = "form-control" } })</td>*@
  283. @*<td>@Html.DropDownListFor(m => m.Identificatieinfos[i].TypeEn , new SelectList( Enum.GetValues() )),"Selecteer identificatie")</td>*@
  284. <td>
  285. @Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].TypeIdentificatieEnumeration, "Selecteer identificatie", new { @class = "fields-select form-control" ,
  286. @onchange = "onSelectChange(this , index);"
  287. })
  288. </td>
  289. @if (@Model.NieuweIdentificatieinfos[index].TypeIdentificatieEnumeration.ToString() == "CHIP")
  290. {
  291. <td>@Html.EditorFor(model => model.NieuweIdentificatieinfos[index].ChipNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  292. <td>@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].ChipPlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  293. <td>@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].ChipAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  294. <td class="d-none">@Html.EditorFor(model => model.NieuweIdentificatieinfos[index].TatoeageNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  295. <td class="d-none">@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].TatoeagePlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  296. <td class="d-none">@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].TatoeageAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  297. }
  298. else if (@Model.NieuweIdentificatieinfos[index].TypeIdentificatieEnumeration.ToString() == "TATOEAGE")
  299. {
  300. <td class="d-none">@Html.EditorFor(model => model.NieuweIdentificatieinfos[index].ChipNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  301. <td class="d-none">@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].ChipPlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  302. <td class="d-none">@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].ChipAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  303. <td>@Html.EditorFor(model => model.NieuweIdentificatieinfos[index].TatoeageNummer, new { htmlAttributes = new { @class = "form-control" } })</td>
  304. <td>@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].TatoeagePlaats, "Selecteer de plaats", new { @class = "fields-select form-control" })</td>
  305. <td>@Html.EnumDropDownListFor(model => model.NieuweIdentificatieinfos[index].TatoeageAanduiding, "Selecteer de positie", new { @class = "fields-select form-control" })</td>
  306. }
  307.  
  308. </tr>
  309. //index++;
  310. }
  311. </tbody>
  312. </table>
  313.  
  314. </div> @*div table identificatie*@
  315.  
  316.  
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement