コード例 #1
0
        public int CreateLeg(string @from, string to, int cost, int distance, TAP2017_2018_TravelCompanyInterface.TransportType transportType)
        {
            UtilityClass.CheckNotNull(from);
            UtilityClass.CheckNotNull(to);
            UtilityClass.CheckNameLength(from);
            UtilityClass.CheckNameLength(to);
            UtilityClass.CheckOnlyAlphanumChar(from);
            UtilityClass.CheckOnlyAlphanumChar(to);
            UtilityClass.CheckNotEquals(from, to);
            UtilityClass.CheckStrictlyPositive(cost);
            UtilityClass.CheckStrictlyPositive(distance);
            UtilityClass.CheckTransportType(transportType);

            try
            {
                using (var travelCompanyDBContext = new TravelCompanyContext(travelCompanyConnectionString))
                {
                    var leg = new LegDB()
                    {
                        From       = from,
                        To         = to,
                        Cost       = cost,
                        Distance   = distance,
                        TransportT = transportType
                    };
                    var l = travelCompanyDBContext.legs.Add(leg);
                    travelCompanyDBContext.SaveChanges();
                    return(l.LegID);
                }
            }
            catch (DbUpdateException)
            {
                throw new TapDuplicatedObjectException();
            }
            catch (Exception e)
            {
                throw new DbConnectionException(e.Message, e);
            }
        }
コード例 #2
0
        public void DeleteLeg(int legToBeRemovedId)
        {
            try
            {
                using (var travelCompanyDBContext = new TravelCompanyContext(travelCompanyConnectionString))
                {
                    var elementLegDb = (from l in travelCompanyDBContext.legs
                                        where l.LegID == legToBeRemovedId
                                        select l).Single();

                    travelCompanyDBContext.legs.Remove(elementLegDb);
                    travelCompanyDBContext.SaveChanges();
                }
            }
            catch (InvalidOperationException)
            {
                throw new NonexistentObjectException();
            }
            catch (Exception e)
            {
                throw new DbConnectionException(e.Message, e);
            }
        }