private void HandleImages(ModelDetailsViewModel model, Model m)
 {
     IList<ModelImage> toAdd = new List<ModelImage>();
     foreach (ModelImageViewModel image in model.Images) {
         if (image.Id != 0) {
             ModelImage o = m.Images.Find(x => x.Id == image.Id);
             o.Order = image.Order;
             o.HighResolutionUrl = image.HighResolutionUrl;
             o.LowResolutionUrl = image.LowResolutionUrl;
             o.ShortDescription = image.ShortDescription;
             o.LongDescription = image.ShortDescription;
             o.ModelId = image.ModelId;
         }
         else {
             image.ModelId = model.Id;
             toAdd.Add(ModelImageViewModel.ToModel(image));
         }
     }
     if (toAdd.Count != 0) {
         foreach (ModelImage mi in toAdd) {
             EntityStore.ModelImages.Add(mi);
         }
     }
     IList<ModelImage> toDelete = (from modelImage in m.Images let mivw = model.Images.FirstOrDefault(x => x.Id == modelImage.Id) where mivw == null select modelImage).ToList();
     if (toDelete.Count != 0) {
         foreach (ModelImage mi in toDelete) {
             EntityStore.ModelImages.Remove(mi);
         }
     }
 }
 public static ModelViewModel FromModel(Model model)
 {
     return new ModelViewModel {
         Id = model.Id,
         Name = model.Name,
         Year = model.Year,
         BasePrice = model.BasePrice,
         MakeId = model.MakeId,
         MakeName = model.Make.Name
     };
 }
 public static ModelViewModel FromModel(Model model)
 {
     return new ModelViewModel {
         Id = model.Id,
         Name = model.Name,
         Year = model.Year,
         BasePrice = model.BasePrice,
         MakeId = model.MakeId,
         MakeName = model.Make.Name,
         DefaultImageUrl = model.Images != null && model.Images.Count != 0?model.Images[0].LowResolutionUrl:string.Empty,
         EngineType = model.EngineType
     };
 }
 public static ModelViewModel FromModel(Model model)
 {
     return new ModelViewModel {
         Id = model.Id,
         Name = model.Name,
         Year = model.Year,
         BasePrice = model.BasePrice,
         MakeId = model.MakeId,
         MakeName = model.Make.Name,
         MakeLogoUrl = model.Make.ImageUrl,
         DefaultImageUrl = model.Images != null && model.Images.Count != 0?model.Images[0].LowResolutionUrl:string.Empty,
         EngineType = model.EngineType,
         Description = model.Description,
         BreakHorsepower = model.BreakHorsepower,
         TopSpeed = model.TopSpeed,
         ZeroToSixty = model.ZeroToSixty
     };
 }
 public static ModelDetailViewModel FromModel(Model model)
 {
     return new ModelDetailViewModel {
         Id = model.Id,
         Name = model.Name,
         Year = model.Year,
         Description = model.Description,
         BasePrice = model.BasePrice,
         EngineType = model.EngineType,
         BreakHorsepower = model.BreakHorsepower,
         ZeroToSixty = model.ZeroToSixty,
         TopSpeed = model.TopSpeed,
         MakeId = model.MakeId,
         MakeName = model.Make.Name,
         MakeImageUrl = model.Make.ImageUrl,
         Images = model.Images.Select(x=>ModelImageViewModel.FromModel(x)).ToList()
     };
 }
 public static ModelDetailsViewModel FromModel(Model model)
 {
     if (model == null) return new ModelDetailsViewModel{Images = new List<ModelImageViewModel>()};
     return new ModelDetailsViewModel {
         Id = model.Id,
         MakeId = model.MakeId,
         MakeName = model.Make.Name,
         Name = model.Name,
         Year = model.Year,
         BasePrice = model.BasePrice,
         EngineType = model.EngineType,
         ZeroToSixty = model.ZeroToSixty,
         BreakHorsepower = model.BreakHorsepower,
         TopSpeed = model.TopSpeed,
         Description = model.Description,
         Images = model.Images.Select(x => ModelImageViewModel.FromModel(x)).ToList()
     };
 }