Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DETAILS PAGE//
- @model ErasProject.Models.Event
- @{
- ViewBag.Title = "Details";
- }
- <fieldset>
- <legend>Event</legend>
- <div class="display-label">
- sportID</div>
- <div class="display-field">@Model.Sport.naam</div>
- <div class="display-label">
- organisatorID</div>
- <div class="display-field">@Model.Account.landIOC</div>
- <div class="display-label">
- code</div>
- <div class="display-field">@Model.code</div>
- <div class="display-label">
- naam</div>
- <div class="display-field">@Model.naam</div>
- <div class="display-label">
- beginDatum</div>
- <div class="display-field">@String.Format("{0:g}", Model.beginDatum)</div>
- <div class="display-label">
- eindDatum</div>
- <div class="display-field">@String.Format("{0:g}", Model.eindDatum)</div>
- <div class="display-label">
- tijdzone</div>
- <div class="display-field">@Model.tijdzone</div>
- <div class="display-label">
- plaats</div>
- <div class="display-field">@Model.plaats</div>
- <div class="display-label">
- land</div>
- <div class="display-field">@Model.land</div>
- <div class="display-label">
- omschrijving</div>
- <div class="display-field">@Model.omschrijving</div>
- <div class="display-label">
- eventManager</div>
- <div class="display-field">@Model.eventManager</div>
- <div class="display-label">
- dichtsteLuchthaven</div>
- <div class="display-field">@Model.dichtsteLuchthaven</div>
- <div class="display-label">
- dichtsteStation</div>
- <div class="display-field">@Model.dichtsteStation</div>
- <div class="display-label">
- website</div>
- <div class="display-field">@Model.website</div>
- <div class="display-label">
- logo</div>
- <div class="display-field">@Model.logo</div>
- <div class="display-label">
- maximumTeams</div>
- <div class="display-field">@Model.maximumTeams</div>
- <div class="display-label">
- creatieDatum</div>
- <div class="display-field">@String.Format("{0:g}", Model.creatiedatum)</div>
- </fieldset>
- <fieldset>
- <legend>Betalingen</legend>
- <div class="display-label">
- Accounts</div>
- <div class="display-field">
- @{
- @Html.Raw(" | ");
- for (int i = 0; i < Model.Payments.Count; i++)
- {
- @Html.Raw("<a href=../../Payment/Details/" + Model.ID + "/" + Model.Payments.ElementAt(i).accountID + ">" + Model.Payments.ElementAt(i).Account.landIOC + "</a>");
- @Html.Raw(" | ");
- }
- }
- </div>
- </fieldset>
- <fieldset>
- <legend>Deelnemers</legend>
- <div class="display-label">
- Accounts</div>
- <div class="display-field">
- @{
- @Html.Raw(" | ");
- for (int i = 0; i < Model.Participations.Count; i++)
- {
- @Html.Raw("<a href=../../Participation/Details/" + Model.Participations.ElementAt(i).ID + " >" + Model.Participations.ElementAt(i).accountID + "</a>");
- @Html.Raw(" | ");
- }
- }
- </div>
- </fieldset>
- <fieldset>
- <legend>Accomodaties</legend>
- <div class="display-label">
- Accomodaties</div>
- <div class="display-field">
- @{
- @Html.Raw(" | ");
- for (int i = 0; i < Model.Accomodations.Count; i++)
- {
- @Html.Raw("<a href=../../Accomodation/Details/" + Model.Accomodations.ElementAt(i).ID + " >" + Model.Accomodations.ElementAt(i).naam + "</a>");
- @Html.Raw(" | ");
- }
- }
- </div>
- </fieldset>
- <fieldset>
- <legend>Contacts</legend>
- <div class="display-label">
- Contacts</div>
- <div class="display-field">
- @{
- @Html.Raw(" | ");
- for (int i = 0; i < Model.Contacts.Count; i++)
- {
- @Html.Raw("<a href=../../Contact/Details/" + Model.Contacts.ElementAt(i).ID + " >" + Model.Contacts.ElementAt(i).naam + "</a>");
- @Html.Raw(" | ");
- }
- }
- </div>
- </fieldset>
- <fieldset>
- <legend>Transport</legend>
- <div class="display-label">
- Transport</div>
- <div class="display-field">
- @{
- @Html.Raw(" | ");
- for (int i = 0; i < Model.Transports.Count; i++)
- {
- @Html.Raw("<a href=../../Transport/Details/" + Model.Transports.ElementAt(i).ID + " >" + Model.Transports.ElementAt(i).datum + " " + Model.Transports.ElementAt(i).vertrekPlaats + "</a>");
- @Html.Raw(" | ");
- }
- }
- </div>
- </fieldset>
- <p>
- @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) |
- @Html.ActionLink("Back to List", "Index")
- </p>
- // PAYMENT CONTROLLER //
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Mvc;
- using ErasProject.Models;
- namespace ErasProject.Controllers
- {
- public class PaymentController : Controller
- {
- private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
- //
- // GET: /Payment/
- public ActionResult Index()
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- return View(_erasDb.Payments.Include("Account").Include("Event").ToList());
- }
- //
- // GET: /Payment/Details/5
- public ActionResult Details(int accountId, int eventId)
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- Payment payments =
- _erasDb.Payments.Include("Account").Include("Event").Where(
- p => p.accountID == accountId && p.eventID == eventId).FirstOrDefault();
- return View(payments);
- }
- //
- // GET: /Payment/Create
- public ActionResult Create()
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- return View(new Payment());
- }
- //
- // POST: /Payment/Create
- [HttpPost]
- public ActionResult Create(Payment payment)
- {
- try
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- _erasDb.Payments.AddObject(payment);
- _erasDb.SaveChanges();
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- //
- // GET: /Payment/Edit/5
- public ActionResult Edit(int accountId, int eventId)
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- return View((from b in _erasDb.Payments.Include("Account").Include("Event")
- where b.accountID == accountId && b.eventID == eventId
- select b).FirstOrDefault());
- }
- //
- // POST: /Payment/Edit/5
- [HttpPost]
- public ActionResult Edit(int accountId, int eventId, FormCollection collection)
- {
- try
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- TryUpdateModel((from b in _erasDb.Payments.Include("Account").Include("Event")
- where b.accountID == accountId && b.eventID == eventId
- select b).FirstOrDefault());
- _erasDb.SaveChanges();
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- //
- // GET: /Payment/Delete/5
- public ActionResult Delete(int accountId, int eventId)
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- Payment payments =
- _erasDb.Payments.Include("Account").Include("Event").Where(
- p => p.accountID == accountId && p.eventID == eventId).FirstOrDefault();
- return View(payments);
- }
- //
- // POST: /Payment/Delete/5
- [HttpPost]
- public ActionResult Delete(int accountId, int eventId, FormCollection collection)
- {
- try
- {
- ViewBag.Events = _erasDb.Events.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- _erasDb.Payments.DeleteObject((from b in _erasDb.Payments.Include("Account").Include("Event")
- where b.accountID == accountId && b.eventID == eventId
- select b).FirstOrDefault());
- _erasDb.SaveChanges();
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- }
- }
- // EVENT CONTROLLER //
- using System.Linq;
- using System.Web.Mvc;
- using ErasProject.Models;
- using ErasProject.Models.Annotations;
- using ErasProject.Models.Mappers;
- namespace ErasProject.Controllers
- {
- public class EventController : Controller
- {
- private readonly EventMapper _eventMapper = new EventMapper();
- private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
- [RequiresLogin]
- public ActionResult Index()
- {
- var events = _eventMapper.GetEvents();
- return View(events);
- }
- [RequiresAdmin]
- public ActionResult Details(int id)
- {
- ViewBag.Sports = _erasDb.Sports.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- ViewBag.Payments = _erasDb.Payments.ToList();
- var eventInstance = _eventMapper.GetEventById(id);
- return View(eventInstance);
- }
- [RequiresAdmin]
- public ActionResult Create()
- {
- ViewBag.Sports = _erasDb.Sports.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- ViewBag.Payments = _erasDb.Payments.ToList();
- return View(new Event());
- }
- [HttpPost]
- [RequiresAdmin]
- public ActionResult Create(Event @event)
- {
- try
- {
- _eventMapper.addEvent(@event);
- return RedirectToAction("Index");
- }
- catch
- {
- return View(@event);
- }
- }
- [RequiresAdmin]
- public ActionResult Edit(int id)
- {
- ViewBag.Sports = _erasDb.Sports.ToList();
- ViewBag.Accounts = _erasDb.Accounts.ToList();
- ViewBag.Payments = _erasDb.Payments.ToList();
- var @event = _eventMapper.GetEventById(id);
- return View(@event);
- }
- [HttpPost]
- [RequiresAdmin]
- public ActionResult Edit(int id, FormCollection collection)
- {
- try
- {
- TryUpdateModel(_eventMapper.GetEventById(id));
- _erasDb.SaveChanges();
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- [RequiresAdmin]
- public ActionResult Delete(int id)
- {
- return View(_eventMapper.GetEventById(id));
- }
- [HttpPost]
- [RequiresAdmin]
- public ActionResult Delete(int id, FormCollection collection)
- {
- try
- {
- _eventMapper.deleteEvent(id);
- return RedirectToAction("Index");
- }
- catch
- {
- return View();
- }
- }
- }
- }
- // EVENT MAPPER //
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Web;
- namespace ErasProject.Models.Mappers
- {
- public class EventMapper
- {
- private readonly ErasDatabaseEntities _erasDb = new ErasDatabaseEntities();
- public List<Event> GetEvents()
- {
- var events = _erasDb.Events
- .Include("BulletinDispatches")
- .Include("Participations")
- .Include("Sport")
- .Include("Payments")
- .Include("Participations")
- .Include("Accomodations")
- .Include("Contacts")
- .Include("Account")
- .Include("Transports").ToList();
- // Bulletins rangschikken
- foreach (var @event in events)
- {
- foreach (var bulletin in @event.BulletinDispatches)
- {
- @event.totalBulletins[bulletin.type].Add(bulletin);
- var bevestiging =
- _erasDb.Participations.Where(
- p => p.accountID == bulletin.ontvangerID && p.eventID == @event.ID).FirstOrDefault();
- if (bevestiging != null)
- {
- @event.confirmedBulletins[bulletin.type].Add(bulletin);
- }
- else
- {
- @event.confirmedBulletins[bulletin.type].Add(bulletin);
- }
- }
- }
- return events;
- }
- public Event GetEventById(int eventId)
- {
- var @event = _erasDb.Events
- .Include("BulletinDispatches")
- .Include("BulletinDispatches.Receiver")
- .Include("BulletinDispatches.Receiver.Country")
- .Include("Participations")
- .Where(e => e.ID == eventId)
- .Include("Sport")
- .Include("Payments")
- .Include("Participations")
- .Include("Accomodations")
- .Include("Contacts")
- .Include("Account")
- .Include("Transports").FirstOrDefault();
- foreach (var bulletin in @event.BulletinDispatches)
- {
- @event.totalBulletins[bulletin.type].Add(bulletin);
- var bevestiging =
- _erasDb.Participations.Where(
- p => p.accountID == bulletin.ontvangerID && p.eventID == @event.ID).FirstOrDefault();
- if (bevestiging != null)
- {
- @event.confirmedBulletins[bulletin.type].Add(bulletin);
- }
- else
- {
- @event.confirmedBulletins[bulletin.type].Add(bulletin);
- }
- }
- return @event;
- }
- public void addEvent(Event @event)
- {
- _erasDb.Events.AddObject(@event);
- _erasDb.SaveChanges();
- }
- public void deleteEvent(int id)
- {
- _erasDb.Events.DeleteObject(GetEventById(id));
- _erasDb.SaveChanges();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement