Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.41 KB | None | 0 0
  1. //DETAILS PAGE//
  2.  
  3. @model ErasProject.Models.Event
  4. @{
  5.     ViewBag.Title = "Details";
  6. }
  7. <fieldset>
  8.     <legend>Event</legend>
  9.     <div class="display-label">
  10.         sportID</div>
  11.     <div class="display-field">@Model.Sport.naam</div>
  12.     <div class="display-label">
  13.         organisatorID</div>
  14.     <div class="display-field">@Model.Account.landIOC</div>
  15.     <div class="display-label">
  16.         code</div>
  17.     <div class="display-field">@Model.code</div>
  18.     <div class="display-label">
  19.         naam</div>
  20.     <div class="display-field">@Model.naam</div>
  21.     <div class="display-label">
  22.         beginDatum</div>
  23.     <div class="display-field">@String.Format("{0:g}", Model.beginDatum)</div>
  24.     <div class="display-label">
  25.         eindDatum</div>
  26.     <div class="display-field">@String.Format("{0:g}", Model.eindDatum)</div>
  27.     <div class="display-label">
  28.         tijdzone</div>
  29.     <div class="display-field">@Model.tijdzone</div>
  30.     <div class="display-label">
  31.         plaats</div>
  32.     <div class="display-field">@Model.plaats</div>
  33.     <div class="display-label">
  34.         land</div>
  35.     <div class="display-field">@Model.land</div>
  36.     <div class="display-label">
  37.         omschrijving</div>
  38.     <div class="display-field">@Model.omschrijving</div>
  39.     <div class="display-label">
  40.         eventManager</div>
  41.     <div class="display-field">@Model.eventManager</div>
  42.     <div class="display-label">
  43.         dichtsteLuchthaven</div>
  44.     <div class="display-field">@Model.dichtsteLuchthaven</div>
  45.     <div class="display-label">
  46.         dichtsteStation</div>
  47.     <div class="display-field">@Model.dichtsteStation</div>
  48.     <div class="display-label">
  49.         website</div>
  50.     <div class="display-field">@Model.website</div>
  51.     <div class="display-label">
  52.         logo</div>
  53.     <div class="display-field">@Model.logo</div>
  54.     <div class="display-label">
  55.         maximumTeams</div>
  56.     <div class="display-field">@Model.maximumTeams</div>
  57.     <div class="display-label">
  58.         creatieDatum</div>
  59.     <div class="display-field">@String.Format("{0:g}", Model.creatiedatum)</div>
  60. </fieldset>
  61. <fieldset>
  62.     <legend>Betalingen</legend>
  63.     <div class="display-label">
  64.         Accounts</div>
  65.     <div class="display-field">
  66.         @{
  67.             @Html.Raw(" | ");
  68.             for (int i = 0; i < Model.Payments.Count; i++)
  69.             {
  70.                 @Html.Raw("<a href=../../Payment/Details/" + Model.ID + "/" + Model.Payments.ElementAt(i).accountID + ">" + Model.Payments.ElementAt(i).Account.landIOC + "</a>");          
  71.                 @Html.Raw(" | ");
  72.             }
  73.         }
  74.     </div>
  75. </fieldset>
  76. <fieldset>
  77.     <legend>Deelnemers</legend>
  78.     <div class="display-label">
  79.         Accounts</div>
  80.     <div class="display-field">
  81.         @{
  82.             @Html.Raw(" | ");
  83.                
  84.             for (int i = 0; i < Model.Participations.Count; i++)
  85.             {
  86.                 @Html.Raw("<a href=../../Participation/Details/" + Model.Participations.ElementAt(i).ID + " >" + Model.Participations.ElementAt(i).accountID + "</a>");
  87.                 @Html.Raw(" | ");
  88.             }
  89.            
  90.         }
  91.     </div>
  92. </fieldset>
  93. <fieldset>
  94.     <legend>Accomodaties</legend>
  95.     <div class="display-label">
  96.         Accomodaties</div>
  97.     <div class="display-field">
  98.         @{
  99.             @Html.Raw(" | ");
  100.                             for (int i = 0; i < Model.Accomodations.Count; i++)
  101.                             {
  102.             @Html.Raw("<a href=../../Accomodation/Details/" + Model.Accomodations.ElementAt(i).ID + " >" + Model.Accomodations.ElementAt(i).naam + "</a>");
  103.             @Html.Raw(" | ");
  104.                             }
  105.         }
  106.     </div>
  107. </fieldset>
  108. <fieldset>
  109.     <legend>Contacts</legend>
  110.     <div class="display-label">
  111.         Contacts</div>
  112.     <div class="display-field">
  113.         @{
  114.             @Html.Raw(" | ");
  115.                             for (int i = 0; i < Model.Contacts.Count; i++)
  116.                             {
  117.             @Html.Raw("<a href=../../Contact/Details/" + Model.Contacts.ElementAt(i).ID + " >" + Model.Contacts.ElementAt(i).naam + "</a>");
  118.             @Html.Raw(" | ");
  119.                             }
  120.         }
  121.     </div>
  122. </fieldset>
  123. <fieldset>
  124.     <legend>Transport</legend>
  125.     <div class="display-label">
  126.         Transport</div>
  127.     <div class="display-field">
  128.         @{
  129.             @Html.Raw(" | ");
  130.                             for (int i = 0; i < Model.Transports.Count; i++)
  131.                             {
  132.             @Html.Raw("<a href=../../Transport/Details/" + Model.Transports.ElementAt(i).ID + " >" + Model.Transports.ElementAt(i).datum + " " + Model.Transports.ElementAt(i).vertrekPlaats + "</a>");
  133.             @Html.Raw(" | ");
  134.                             }
  135.         }
  136.     </div>
  137. </fieldset>
  138. <p>
  139.     @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
  140.     @Html.ActionLink("Back to List", "Index")
  141. </p>
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. // PAYMENT CONTROLLER //
  153.  
  154. using System.Collections.Generic;
  155. using System.Linq;
  156. using System.Web.Mvc;
  157. using ErasProject.Models;
  158.  
  159. namespace ErasProject.Controllers
  160. {
  161.     public class PaymentController : Controller
  162.     {
  163.         private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
  164.         //
  165.         // GET: /Payment/
  166.  
  167.         public ActionResult Index()
  168.         {
  169.             ViewBag.Events = _erasDb.Events.ToList();
  170.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  171.             return View(_erasDb.Payments.Include("Account").Include("Event").ToList());
  172.         }
  173.  
  174.         //
  175.         // GET: /Payment/Details/5
  176.  
  177.         public ActionResult Details(int accountId, int eventId)
  178.         {
  179.             ViewBag.Events = _erasDb.Events.ToList();
  180.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  181.             Payment payments =
  182.                 _erasDb.Payments.Include("Account").Include("Event").Where(
  183.                     p => p.accountID == accountId && p.eventID == eventId).FirstOrDefault();
  184.             return View(payments);
  185.         }
  186.  
  187.         //
  188.         // GET: /Payment/Create
  189.  
  190.         public ActionResult Create()
  191.         {
  192.             ViewBag.Events = _erasDb.Events.ToList();
  193.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  194.             return View(new Payment());
  195.         }
  196.  
  197.         //
  198.         // POST: /Payment/Create
  199.  
  200.         [HttpPost]
  201.         public ActionResult Create(Payment payment)
  202.         {
  203.             try
  204.             {
  205.                 ViewBag.Events = _erasDb.Events.ToList();
  206.                 ViewBag.Accounts = _erasDb.Accounts.ToList();
  207.                 _erasDb.Payments.AddObject(payment);
  208.                 _erasDb.SaveChanges();
  209.                 return RedirectToAction("Index");
  210.             }
  211.             catch
  212.             {
  213.                 return View();
  214.             }
  215.         }
  216.  
  217.         //
  218.         // GET: /Payment/Edit/5
  219.  
  220.         public ActionResult Edit(int accountId, int eventId)
  221.         {
  222.             ViewBag.Events = _erasDb.Events.ToList();
  223.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  224.             return View((from b in _erasDb.Payments.Include("Account").Include("Event")
  225.                          where b.accountID == accountId && b.eventID == eventId
  226.                          select b).FirstOrDefault());
  227.         }
  228.  
  229.         //
  230.         // POST: /Payment/Edit/5
  231.  
  232.         [HttpPost]
  233.         public ActionResult Edit(int accountId, int eventId, FormCollection collection)
  234.         {
  235.             try
  236.             {
  237.                 ViewBag.Events = _erasDb.Events.ToList();
  238.                 ViewBag.Accounts = _erasDb.Accounts.ToList();
  239.                 TryUpdateModel((from b in _erasDb.Payments.Include("Account").Include("Event")
  240.                                 where b.accountID == accountId && b.eventID == eventId
  241.                                 select b).FirstOrDefault());
  242.                 _erasDb.SaveChanges();
  243.                 return RedirectToAction("Index");
  244.             }
  245.             catch
  246.             {
  247.                 return View();
  248.             }
  249.         }
  250.  
  251.         //
  252.         // GET: /Payment/Delete/5
  253.  
  254.         public ActionResult Delete(int accountId, int eventId)
  255.         {
  256.             ViewBag.Events = _erasDb.Events.ToList();
  257.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  258.             Payment payments =
  259.                 _erasDb.Payments.Include("Account").Include("Event").Where(
  260.                     p => p.accountID == accountId && p.eventID == eventId).FirstOrDefault();
  261.             return View(payments);
  262.         }
  263.  
  264.         //
  265.         // POST: /Payment/Delete/5
  266.  
  267.         [HttpPost]
  268.         public ActionResult Delete(int accountId, int eventId, FormCollection collection)
  269.         {
  270.             try
  271.             {
  272.                 ViewBag.Events = _erasDb.Events.ToList();
  273.                 ViewBag.Accounts = _erasDb.Accounts.ToList();
  274.                 _erasDb.Payments.DeleteObject((from b in _erasDb.Payments.Include("Account").Include("Event")
  275.                                                where b.accountID == accountId && b.eventID == eventId
  276.                                                select b).FirstOrDefault());
  277.                 _erasDb.SaveChanges();
  278.                 return RedirectToAction("Index");
  279.             }
  280.             catch
  281.             {
  282.                 return View();
  283.             }
  284.         }
  285.     }
  286. }
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294. // EVENT CONTROLLER //
  295.  
  296.  
  297. using System.Linq;
  298. using System.Web.Mvc;
  299. using ErasProject.Models;
  300. using ErasProject.Models.Annotations;
  301. using ErasProject.Models.Mappers;
  302.  
  303. namespace ErasProject.Controllers
  304. {
  305.     public class EventController : Controller
  306.     {
  307.         private readonly EventMapper _eventMapper = new EventMapper();
  308.         private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
  309.  
  310.         [RequiresLogin]
  311.         public ActionResult Index()
  312.         {
  313.             var events = _eventMapper.GetEvents();
  314.             return View(events);
  315.         }
  316.  
  317.         [RequiresAdmin]
  318.         public ActionResult Details(int id)
  319.         {
  320.             ViewBag.Sports = _erasDb.Sports.ToList();
  321.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  322.             ViewBag.Payments = _erasDb.Payments.ToList();
  323.             var eventInstance = _eventMapper.GetEventById(id);
  324.             return View(eventInstance);
  325.         }
  326.  
  327.         [RequiresAdmin]
  328.         public ActionResult Create()
  329.         {
  330.             ViewBag.Sports = _erasDb.Sports.ToList();
  331.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  332.             ViewBag.Payments = _erasDb.Payments.ToList();
  333.             return View(new Event());
  334.         }
  335.  
  336.         [HttpPost]
  337.         [RequiresAdmin]
  338.         public ActionResult Create(Event @event)
  339.         {
  340.             try
  341.             {
  342.                 _eventMapper.addEvent(@event);
  343.                 return RedirectToAction("Index");
  344.             }
  345.             catch
  346.             {
  347.                 return View(@event);
  348.             }
  349.         }
  350.  
  351.         [RequiresAdmin]
  352.         public ActionResult Edit(int id)
  353.         {
  354.             ViewBag.Sports = _erasDb.Sports.ToList();
  355.             ViewBag.Accounts = _erasDb.Accounts.ToList();
  356.             ViewBag.Payments = _erasDb.Payments.ToList();
  357.             var @event = _eventMapper.GetEventById(id);
  358.  
  359.             return View(@event);
  360.         }
  361.  
  362.         [HttpPost]
  363.         [RequiresAdmin]
  364.         public ActionResult Edit(int id, FormCollection collection)
  365.         {
  366.             try
  367.             {
  368.                 TryUpdateModel(_eventMapper.GetEventById(id));
  369.                 _erasDb.SaveChanges();
  370.  
  371.                 return RedirectToAction("Index");
  372.             }
  373.             catch
  374.             {
  375.                 return View();
  376.             }
  377.         }
  378.  
  379.         [RequiresAdmin]
  380.         public ActionResult Delete(int id)
  381.         {
  382.             return View(_eventMapper.GetEventById(id));
  383.         }
  384.  
  385.         [HttpPost]
  386.         [RequiresAdmin]
  387.         public ActionResult Delete(int id, FormCollection collection)
  388.         {
  389.             try
  390.             {
  391.                 _eventMapper.deleteEvent(id);
  392.                 return RedirectToAction("Index");
  393.             }
  394.             catch
  395.             {
  396.                 return View();
  397.             }
  398.         }
  399.     }
  400. }
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. // EVENT MAPPER //
  414.  
  415.  
  416. using System;
  417. using System.Collections.Generic;
  418. using System.Data.Entity;
  419. using System.Linq;
  420. using System.Web;
  421.  
  422. namespace ErasProject.Models.Mappers
  423. {
  424.     public class EventMapper
  425.     {
  426.  
  427.         private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
  428.  
  429.         public List<Event> GetEvents()
  430.         {
  431.             var events = _erasDb.Events
  432.                .Include("BulletinDispatches")
  433.                .Include("Participations")
  434.                .Include("Sport")
  435.                .Include("Payments")
  436.                .Include("Participations")
  437.                .Include("Accomodations")
  438.                .Include("Contacts")
  439.                .Include("Account")
  440.                .Include("Transports").ToList();
  441.  
  442.             // Bulletins rangschikken
  443.             foreach (var @event in events)
  444.             {
  445.                 foreach (var bulletin in @event.BulletinDispatches)
  446.                 {
  447.                     @event.totalBulletins[bulletin.type].Add(bulletin);
  448.  
  449.                     var bevestiging =
  450.                         _erasDb.Participations.Where(
  451.                             p => p.accountID == bulletin.ontvangerID && p.eventID == @event.ID).FirstOrDefault();
  452.  
  453.                     if (bevestiging != null)
  454.                     {
  455.                         @event.confirmedBulletins[bulletin.type].Add(bulletin);
  456.                     }
  457.                     else
  458.                     {
  459.                         @event.confirmedBulletins[bulletin.type].Add(bulletin);
  460.                     }
  461.                 }
  462.             }
  463.             return events;
  464.         }
  465.  
  466.         public Event GetEventById(int eventId)
  467.         {
  468.             var @event = _erasDb.Events
  469.                 .Include("BulletinDispatches")
  470.                 .Include("BulletinDispatches.Receiver")
  471.                 .Include("BulletinDispatches.Receiver.Country")
  472.                 .Include("Participations")
  473.                 .Where(e => e.ID == eventId)
  474.                 .Include("Sport")
  475.                 .Include("Payments")
  476.                 .Include("Participations")
  477.                 .Include("Accomodations")
  478.                 .Include("Contacts")
  479.                 .Include("Account")
  480.                 .Include("Transports").FirstOrDefault();
  481.  
  482.             foreach (var bulletin in @event.BulletinDispatches)
  483.             {
  484.                 @event.totalBulletins[bulletin.type].Add(bulletin);
  485.  
  486.                 var bevestiging =
  487.                     _erasDb.Participations.Where(
  488.                         p => p.accountID == bulletin.ontvangerID && p.eventID == @event.ID).FirstOrDefault();
  489.  
  490.                 if (bevestiging != null)
  491.                 {
  492.                     @event.confirmedBulletins[bulletin.type].Add(bulletin);
  493.                 }
  494.                 else
  495.                 {
  496.                     @event.confirmedBulletins[bulletin.type].Add(bulletin);
  497.                 }
  498.             }
  499.  
  500.             return @event;
  501.         }
  502.  
  503.         public void addEvent(Event @event)
  504.         {
  505.             _erasDb.Events.AddObject(@event);
  506.             _erasDb.SaveChanges();
  507.         }
  508.  
  509.         public void deleteEvent(int id)
  510.         {
  511.             _erasDb.Events.DeleteObject(GetEventById(id));
  512.             _erasDb.SaveChanges();
  513.         }
  514.     }
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement