Example #1
0
        private void PersistVehicleCharacteristics(VehicleCharacteristics chars)
        {
            VehicleCharacteristicsEntity entity =
                VehicleCharacteristicsAssembler.FromDomainObjectToEntity(chars);

            using (VTSDatabase database = new VTSDatabase())
            {
                database.VehicleCharacteristics.Add(entity);
                try
                {
                    database.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    string result = String.Empty;
                    foreach (DbEntityValidationResult eve in e.EntityValidationErrors)
                    {
                        string entityTypename = eve.Entry.Entity.GetType().Name;
                        string errorString    = String.Empty;
                        foreach (DbValidationError error in eve.ValidationErrors)
                        {
                            errorString = error.PropertyName + " : " + error.ErrorMessage;
                        }
                        result = String.Format("{0} | {1}", result, entityTypename + " -> " + errorString);
                    }
                    throw new Exception(result);
                }
            }
        }
Example #2
0
 private VehicleCharacteristics GetBestMatchFromOurDatabase(
     string vin, string preferredLang)
 {
     using (VTSDatabase database = new VTSDatabase())
     {
         VehicleCharacteristicsEntity perfectMatch =
             database.VehicleCharacteristics.FirstOrDefault(
                 vc => vc.Vin == vin && vc.Language == preferredLang);
         if (perfectMatch != null)
         {
             return(VehicleCharacteristicsAssembler.
                    FromEntityToDomainObject(perfectMatch));
         }
         VehicleCharacteristicsEntity anything =
             database.VehicleCharacteristics.FirstOrDefault(
                 vc => vc.Vin == vin);
         if (anything == null)
         {
             return(null);
         }
         return(VehicleCharacteristicsAssembler.
                FromEntityToDomainObject(anything));
     }
 }