public static void AddRoad(DTO.Road newRoad) { CitiesAndRoadsDbContext db = new CitiesAndRoadsDbContext(); if (newRoad.Length == 0) { throw new CustomException("Road requires actual length."); } if (newRoad.SideCityOneId == newRoad.SideCityTwoId) { throw new CustomException("Cities must be different."); } if (DoesRoadExist(newRoad, db)) { throw new CustomException("Road already exist."); } var road = new Road(); road.Length = newRoad.Length; road.SideCityOneId = newRoad.SideCityOneId; road.SideCityTwoId = newRoad.SideCityTwoId; db.Roads.Add(road); db.SaveChanges(); }
public static void SetLogisticCenter(DTO.City logisticCenter) { CitiesAndRoadsDbContext db = new CitiesAndRoadsDbContext(); logisticCenter.IsLogisticCenter = true; var city = db.Cities.First(c => c.Id == logisticCenter.Id); city.IsLogisticCenter = logisticCenter.IsLogisticCenter; db.SaveChanges(); }
public static void AddCity(DTO.City newCity) { CitiesAndRoadsDbContext db = new CitiesAndRoadsDbContext(); if (String.IsNullOrWhiteSpace(newCity.Name)) { throw new CustomException("City requires Name."); } if (DoesCityExist(newCity, db)) { throw new CustomException("City already exists."); } var city = new City(); city.Name = newCity.Name; db.Cities.Add(city); db.SaveChanges(); }