public Models.CreateViewModel GetCreateViewModel(Models.RetrieveViewModel rvm)
        {
            Models.CreateViewModel cvm = new Models.CreateViewModel();
            CDLContext db = new CDLContext();
            Bridge bridge = new Bridge();

            bridge = db.Bridge.Where(b => b.Latitude <= rvm.Latitude + 0.001 && b.Latitude >= rvm.Latitude - 0.001 &&
                                 b.Longitude <= rvm.Longitude + 0.001 && b.Longitude >= rvm.Longitude - 0.001).FirstOrDefault();

            if (bridge != null)  //found match
            {
                cvm.Latitude = bridge.Latitude;
                cvm.Longitude = bridge.Longitude;
                cvm.Address1 = bridge.Address1;
                cvm.City = bridge.City;
                cvm.State = bridge.State.PostalCode;
                cvm.PostalCode = bridge.PostalCode;

                cvm.Height = bridge.Height;
                cvm.BridgeId = bridge.BridgeId;

                if (bridge.Weights.Count >= 1)
                    cvm.WeightStraight = bridge.Weights.ElementAt(0).maxWeight;
                if (bridge.Weights.Count >= 2)
                    cvm.WeightSingle = bridge.Weights.ElementAt(1).maxWeight;
                if (bridge.Weights.Count >= 3)
                    cvm.WeightDouble = bridge.Weights.ElementAt(2).maxWeight;
            }
            else
            { cvm = null; }

            return cvm;
        }
        public void DropBridge(Models.CreateViewModel cvm)
        {
            CDLContext db = new CDLContext();
            Bridge bridge = new Bridge();

            bridge = db.Bridge.Find(cvm.BridgeId);

            db.Bridge.Remove(bridge);
            db.SaveChanges();
        }
        public void UpdateCreateViewModel(Models.CreateViewModel cvm)
        {
            CDLContext db = new CDLContext();
            Bridge bridge = new Bridge();

            bridge = db.Bridge.Find(cvm.BridgeId);

            State st = new State();
            st = db.State.Where(s => cvm.State == s.PostalCode).FirstOrDefault();

            bridge.Address1 = cvm.Address1;
            bridge.City = cvm.City;
            bridge.State = st;
            bridge.PostalCode = cvm.PostalCode;
            bridge.LastUpdated = DateTime.UtcNow;
            bridge.Height = cvm.Height;

            bridge.Latitude = cvm.Latitude;
            bridge.Longitude = cvm.Longitude;

            if (bridge.Weights.Count >= 1)
                bridge.Weights.ElementAt(0).maxWeight = cvm.WeightStraight;
            if (bridge.Weights.Count >= 2)
                bridge.Weights.ElementAt(1).maxWeight = cvm.WeightSingle;
            if (bridge.Weights.Count >= 3)
                bridge.Weights.ElementAt(2).maxWeight = cvm.WeightDouble;

            db.SaveChanges();
        }
        public void SaveCreateViewModel(Models.CreateViewModel cvm)
        {
            CDLContext db = new CDLContext();
            Bridge bridge = new Bridge();
            List<Weight> weights = new List<Weight>();
            Weight weight1 = new Weight();
            Weight weight2 = new Weight();
            Weight weight3 = new Weight();
            State st = new State();

            st = db.State.Where(s => cvm.State == s.PostalCode).FirstOrDefault();

            bridge.Address1 = cvm.Address1;
            bridge.City = cvm.City;
            bridge.State = st;
            bridge.PostalCode = cvm.PostalCode;
            bridge.LastUpdated = DateTime.UtcNow;
            bridge.Height = cvm.Height;

            bridge.Latitude = cvm.Latitude;
            bridge.Longitude = cvm.Longitude;

            weight1.maxWeight = cvm.WeightStraight;
            weight1.TruckType = TruckType.Straight;
            weights.Add(weight1);

            weight2.maxWeight = cvm.WeightSingle;
            weight2.TruckType = TruckType.Single;
            weights.Add(weight2);

            weight3.maxWeight = cvm.WeightDouble;
            weight3.TruckType = TruckType.Double;
            weights.Add(weight3);

            bridge.Weights = weights;

            db.Bridge.Add(bridge);
            db.SaveChanges();
        }