public StationMappingDetail(StationMapping mappig) { this.FromStaionId = mappig.FromStaionId; this.ToStationId = mappig.ToStationId; this.LineId = mappig.LineId; this.Distance = mappig.Distance; this.IsDeleay = mappig.IsDeleay; this.FromStationsName = mappig.FromStation.Name; this.ToStationsName = mappig.ToStation.Name; this.LineName = mappig.Line.Name; }
public bool AnyStationMappingExist(StationMapping stationMapping) { if (stationMapping == null) { throw new ArgumentException("StationMapping should not be null"); } bool isAnyStation = false; var reuslt = unitOfWork.StationMappings.Get(filter: sM => sM.LineId == stationMapping.LineId && sM.ToStationId == stationMapping.ToStationId && sM.FromStaionId == stationMapping.FromStaionId); if (reuslt.Count() > 0) { isAnyStation = true; } return(isAnyStation); }
public int CreateStationMapping(StationMapping newStationMapping) { if (newStationMapping == null) { throw new ArgumentException("StationMapping should not be null"); } if (newStationMapping.LineId <= 0) { throw new ArgumentException("Invalid Train Line. Train Id value is missing"); } if (newStationMapping.FromStaionId <= 0) { throw new ArgumentException("Invalid From station. Station Id value is missing"); } if (newStationMapping.ToStationId <= 0) { throw new ArgumentException("Invalid To station. Station Id value is missing"); } if (newStationMapping.ToStationId == newStationMapping.FromStaionId) { throw new ArgumentException("From and To Station not be same."); } if (newStationMapping.Distance > 50 || newStationMapping.Distance <= 0) { throw new ArgumentException("Invalid Distance. Distance Should not exceed 50 but greater than 0."); } if (AnyStationMappingExist(newStationMapping)) { throw new InvalidOperationException("Station Mapping already exists."); } unitOfWork.StationMappings.Add(newStationMapping); return(unitOfWork.Complete()); }
private void btnSetDistance_Click(object sender, EventArgs e) { try { int.TryParse(txtDistance.Text, out int distance); var stationMapping = new StationMapping() { LineId = cmbTrainLine.SelectedValue != null ? (int)cmbTrainLine.SelectedValue : 0, FromStaionId = cmbFromStation.SelectedValue != null ? (int)cmbFromStation.SelectedValue : 0, ToStationId = cmbToStation.SelectedValue != null ? (int)cmbToStation.SelectedValue : 0, Distance = distance, IsDeleay = ckIsDeleay.Checked }; var result = manageStationMapping.CreateStationMapping(stationMapping); if (result > 0) { MessageBox.Show("Distance confiquration added success", "Set distance configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); return; } MessageBox.Show("Distance confiquration could not added.", "Set distance configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Set distance configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message, "Set distance configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("Oops! Something went wrong.", "Set distance configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } }