void Submit_Click(object sender, EventArgs e) { try { BusinessObjectLayer.Ship ship = new Ship() { Connections = int.Parse(this.Connections.Text.Trim()), Height = int.Parse(this.Height.Text.Trim()), Length = int.Parse(this.Length.Text.Trim()), Width = int.Parse(this.Width.Text.Trim()), Name = this.Name.Text.Trim() }; DataAccessLayer.Ship dalShip = new DataAccessLayer.Ship(); if (dalShip.GetAllBy(new List<SearchParameter>() {new SearchParameter("Name", ship.Name)}).Count > 0) { throw new Exception("Er is al een schip type met deze naam."); } dalShip.Insert(ship); this.SetFlash("Schip type succesvol toegevoegd."); } catch (Exception ex) { this.SetFlash("Er is iets misgegaan. Probeer het nogmaals a.u.b. (Fout: " + ex.Message + ")", FlashType.Danger); this.Response.Redirect(this.Request.RawUrl); } this.Response.RedirectPermanent("?page=DropDownShip"); }
/// <summary> /// The page_ load. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Load(object sender, EventArgs e) { List<Ship> ships = new DataAccessLayer.Ship().GetAll(); this.DropDownShip.Items.Clear(); ships.ForEach(x => this.DropDownShip.Items.Add(new ListItem(x.Name, x.Id.ToString()))); if (this.Ship != null) { this.DropDownShip.Items.FindByValue(this.Ship.Id.ToString()).Selected = true; } List<Port> ports = new DataAccessLayer.Port().GetAll(); this.DropDownPort.Items.Clear(); ports.ForEach(x => this.DropDownPort.Items.Add(new ListItem(x.ToString(), x.Id.ToString()))); if (this.Port != null) { this.DropDownPort.Items.FindByValue(this.Port.Id.ToString()).Selected = true; } this.Submit.Click += this.Submit_Click; this.Export.Click += this.Export_Click; }