public VehicleModel GetByMakeAndModelCode(string makeCode, string modelCode) { var model = GetFromCache(makeCode, modelCode); if (model == null) { Vehicle vehicle = null; using (var context = new VehicleEntities()) { vehicle = context.Vehicles.Include("Model") .Include("Model.Make") .FirstOrDefault(x => x.Model.ModelCode == modelCode && x.Model.MakeCode == makeCode); } if (vehicle == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } model = new VehicleModel() { ImageUrl = vehicle.ImageUrl, Make = vehicle.Model.Make.MakeName, Model = vehicle.Model.ModelName, ProducedFromUtc = vehicle.ProducedFromUtc, ProducedToUtc = vehicle.ProducedToUtc }; PutToCache(model, makeCode, modelCode); } return model; }
public IEnumerable<Entities.Make> GetMakes() { var makes = new List<Entities.Make>(); using (var context = new VehicleEntities()) { makes.AddRange(context.Makes.Select(x => new Entities.Make() { Code = x.MakeCode, Name = x.MakeName })); } return makes; }
public IEnumerable<Entities.Model> GetModels(string makeCode) { var models = new List<Entities.Model>(); using (var context = new VehicleEntities()) { models.AddRange(context.Models.Where(x => x.MakeCode == makeCode) .Select(x => new Entities.Model() { Code = x.MakeCode, Name = x.ModelName, MakeCode = x.MakeCode })); } return models; }