/// <summary> /// Auxiliary method that controls if the LegEntity is null /// </summary> /// <param name="leg"></param> public static void CheckLegEntity(LegEntity leg) { if (leg == null) { throw new NonexistentObjectException($"Leg is null"); } }
/// <summary> /// Creates an ILeg which connects two cities. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cost"></param> /// <param name="distance"></param> /// <param name="transportType"></param> /// <returns></returns> public int CreateLeg(string from, string to, int cost, int distance, TransportType transportType) { CheckLeg(from, to, cost, distance, transportType); using (var c = new TravelCompanyContext(_tcConnectionstring)) { var legtoAdd = new LegEntity() { From = from, To = to, Cost = cost, Distance = distance, Type = transportType }; c.Legs.Add(legtoAdd); c.SaveChanges(); return(legtoAdd.Id); } }