public static AddNewModel FromDomainModel(ModelCar model) { if (model == null) return null; return new AddNewModel() { ID = model.ID, Make = model.Make, ModelAuto = model.ModelAuto, CreationYear = model.Year, ClassAuto=model.ClassAuto ///TODO }; }
/// <summary> /// Add model /// </summary> public static void AddModel(ModelCar car) { using (CarsEntity autorentEntityContext = new CarsEntity()) { try { Autorent.Models.Auto.AutoModel autoModel = new Autorent.Models.Auto.AutoModel { Id = Guid.NewGuid(), Maker = car.Make, ConceptName = car.ModelAuto, Year = (short)car.Year, Class = ((int)car.ClassAuto).ToString() }; autorentEntityContext.AutoModels.AddObject(autoModel); autorentEntityContext.SaveChanges(); } catch (InvalidOperationException ex) { throw ex; } } }
/// <summary> /// Return all models /// </summary> public static IList<ModelCar> GetModels() { IList<ModelCar> modelCars = new List<ModelCar>(); using (CarsEntity autorentEntity = new CarsEntity()) { try { var query = from am in autorentEntity.AutoModels select am; foreach (var item in query) { ModelCar modelCar = new ModelCar(); modelCar.ID = item.Id; modelCar.Make = item.Maker; modelCar.ModelAuto = item.ConceptName; modelCar.Year = (short)item.Year; modelCar.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class); modelCars.Add(modelCar); } } catch (InvalidOperationException ex) { throw ex; } } return modelCars; }
public ActionResult AddNewModel(AddNewModel model) { if (ModelState.IsValid) { ModelCar mc = new ModelCar(); model.AssignTo(mc); ModelCarAPI.AddModel(mc); return RedirectToAction("ActionAddModelSuccess", "Administration"); } return RedirectToAction("ActionAddModelSuccess", "Administration"); }