protected void CreateRoutetBtn_Click(object sender, EventArgs e) { if (this.Page.IsValid) { if (!this.AreOriginAndDestinationValid()) { this.InvalidOriginAndDestinationCustomValidator.IsValid = false; return; } double distance = this.GetValidDistance(); if (distance == -1) { this.InvalidDistanceCustonValidator.IsValid = false; return; } var routeEventArgs = new RoutesManagementEventArgs() { OriginId = int.Parse(this.AddOriginDropDownList.SelectedItem.Value), DestinationId = int.Parse(this.AddDestinationDropDownList.SelectedItem.Value), DistanceInKm = distance }; this.OnRoutesAddItem?.Invoke(null, routeEventArgs); this.SuccessPanel.Visible = true; this.AddedRouteIdLiteral.Text = routeEventArgs.Id.ToString(); this.ClearFields(); } }
private void View_OnRoutesUpdateItem(object sender, RoutesManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(RoutesManagementEventArgs)); } var route = this.routesServices.GetRoute(e.Id); if (route == null) { this.View.ModelState.AddModelError( ErrorMessages.MODEL_ERROR_KEY, string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id)); return; } this.View.TryUpdateModel(route); if (this.View.ModelState.IsValid) { if (route.OriginId <= 0) { throw new IndexOutOfRangeException(ErrorMessages.INVALID_ID); } route.OriginId = e.OriginId; route.DestinationId = e.DestinationId; this.routesServices.UpdateRoute(e.Id, route); } }
private void View_OnRoutesDeleteItem(object sender, RoutesManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(RoutesManagementEventArgs)); } this.routesServices.DeleteRoute(e.Id); }
private void View_OnRoutesAddItem(object sender, RoutesManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(RoutesManagementEventArgs)); } var route = new Route() { OriginId = e.OriginId, DestinationId = e.DestinationId, DistanceInKm = e.DistanceInKm }; e.Id = this.routesServices.AddRoute(route); }