public IHttpActionResult GetStationsByDrivelineNumber(int number) { Driveline driveline = unitOfWork.Drivelines.GetLineByNumber(number); if (driveline == null || driveline.Stations.Count == 0) { return(NotFound()); } List <UpdateStationInfoBindingModel> stations = new List <UpdateStationInfoBindingModel>(); foreach (Station s in driveline.Stations) { UpdateStationInfoBindingModel station = new UpdateStationInfoBindingModel(); station.Id = s.Id; station.Name = s.Name; station.Address = s.Address; Coordinates cor = unitOfWork.CoordinatesRepository.Get(s.CoordinatesId); station.X = cor.CoordX; station.Y = cor.CoordY; stations.Add(station); } return(Ok(stations)); }
public IHttpActionResult GetDrivelineNumberById(int id) { Driveline dr = unitOfWork.Drivelines.GetLineById(id); ChangeDrivelineBindingModel bindingModel = new ChangeDrivelineBindingModel(); if (dr == null) { return(NotFound()); } bindingModel.DriveLineNumber = dr.Number; bindingModel.RowVersion = dr.RowVersion; return(Ok(bindingModel)); }
private void InitialDBAdding(WebApp.Persistence.ApplicationDbContext context) { if (!context.Coordinates.Any(c => c.CoordinatesId == 1)) // kada budemo napravili server ovo ce biti nepotrebno { Coordinates c = new Coordinates() { CoordX = 1, CoordY = 1 }; context.Coordinates.Add(c); context.SaveChanges(); } if (!context.Coordinates.Any(c => c.CoordinatesId == 2)) // kada budemo napravili server ovo ce biti nepotrebno { Coordinates c = new Coordinates() { CoordX = 10, CoordY = 10 }; context.Coordinates.Add(c); context.SaveChanges(); } if (!context.DriveLines.Any(d => d.Number == 4)) { var drLine = new Driveline() { Number = 4 }; context.DriveLines.Add(drLine); context.SaveChanges(); } if (!context.DriveLines.Any(d => d.Number == 7)) { var drLine = new Driveline() { Number = 7 }; context.DriveLines.Add(drLine); context.SaveChanges(); } if (!context.DrivingPlans.Any(p => p.Departures.Equals("4: 50 ; 10:30"))) { DrivingPlan drPlan = new DrivingPlan() { Day = Models.Enums.WeekDays.Monday, Type = Models.Enums.DriveType.City, Departures = "4: 50 ; 10:30", DrivelineId = context.DriveLines.Where(l => l.Number == 4).FirstOrDefault().Id }; context.DrivingPlans.Add(drPlan); context.SaveChanges(); } if (!context.DrivingPlans.Any(p => p.Departures.Equals("10:00 ; 11:00 ; 12:00"))) { DrivingPlan drPlan = new DrivingPlan() { Day = Models.Enums.WeekDays.Monday, Type = Models.Enums.DriveType.City, Departures = "10:00 ; 11:00 ; 12:00", DrivelineId = context.DriveLines.Where(l => l.Number == 7).FirstOrDefault().Id }; context.DrivingPlans.Add(drPlan); context.SaveChanges(); } if (!context.Stations.Any(s => s.Name == "FirstStation")) { Station s = new Station() { Name = "FirstStation", Address = "Bulevar Oslobodjenja 1" }; s.CoordinatesId = context.Coordinates.Where(c => c.CoordinatesId == 1).FirstOrDefault().CoordinatesId; context.Stations.Add(s); context.SaveChanges(); } if (!context.Stations.Any(s => s.Name == "SecondStation")) { Station s = new Station() { Name = "SecondStation", Address = "Bulevar Oslobodjenja 10" }; s.CoordinatesId = context.Coordinates.Where(c => c.CoordinatesId == 2).FirstOrDefault().CoordinatesId; context.Stations.Add(s); context.SaveChanges(); } if (!context.Pricelists.Any(p => p.PricelistId == 1)) //necemo po ID-u , ali posto je samo test onda je ok { Pricelist pr = new Pricelist() { ValidFrom = DateTime.Now, ValidUntil = DateTime.Now.AddDays(2) }; context.Pricelists.Add(pr); context.SaveChanges(); } if (!context.PricelistItems.Any(p => p.TicketType == Models.Enums.TicketType.Daily && p.PassengerType == Models.Enums.PassengerType.Regular)) { PricelistItem prI = new PricelistItem() { TicketType = Models.Enums.TicketType.Daily, Price = 200, PassengerType = Models.Enums.PassengerType.Regular }; Pricelist pr = context.Pricelists.Where(p => p.PricelistId == 1).FirstOrDefault(); prI.PricelistId = pr.PricelistId; context.PricelistItems.Add(prI); context.SaveChanges(); pr.PricelistItems.Add(prI); context.PricelistItems.AddOrUpdate(prI); context.SaveChanges(); } if (!context.PassengerTypeCoefficients.Any(p => p.PassengerType == Models.Enums.PassengerType.Regular)) { PassengerTypeCoefficient pas = new PassengerTypeCoefficient() { Coefficient = 1F, PassengerType = Models.Enums.PassengerType.Regular }; context.PassengerTypeCoefficients.Add(pas); context.SaveChanges(); } if (!context.PassengerTypeCoefficients.Any(p => p.PassengerType == Models.Enums.PassengerType.Pensioner)) { PassengerTypeCoefficient pas = new PassengerTypeCoefficient() { Coefficient = 0.9F, PassengerType = Models.Enums.PassengerType.Pensioner }; context.PassengerTypeCoefficients.Add(pas); context.SaveChanges(); } if (!context.PassengerTypeCoefficients.Any(p => p.PassengerType == Models.Enums.PassengerType.Student)) { PassengerTypeCoefficient pas = new PassengerTypeCoefficient() { Coefficient = 0.8F, PassengerType = Models.Enums.PassengerType.Student }; context.PassengerTypeCoefficients.Add(pas); context.SaveChanges(); } }