public ActionResult Share(ShareCar model) { try { var element = new RatingCar(); if (model.BodyId != -1) { element.Body = db.Body.FirstOrDefault(x => x.Id == model.BodyId); } if (model.BrandId != -1) { element.Brand = db.Brand.FirstOrDefault(x => x.Id == model.BrandId); } if (model.GenerationId != -1) { element.Generation = db.Generation.FirstOrDefault(x => x.Id == model.GenerationId); } if (model.ModelId != -1) { element.Model = db.Model.FirstOrDefault(x => x.Id == model.ModelId); } if (model.MotorId != -1) { element.Motor = db.Motor.FirstOrDefault(x => x.Id == model.MotorId); } var send = new RCViewVM(); if (element.Brand != null) { send.Brand = element.Brand.Id; } if (element.Body != null) { send.Body = element.Body.Id; } if (element.Generation != null) { send.Generation = element.Generation.Id; } if (element.Model != null) { send.Model = element.Model.Id; } if (element.Motor != null) { send.Motor = element.Motor.Id; } return(RedirectToAction("Car", send)); } catch (Exception e) { e.Data.Values.GetEnumerator(); } return(RedirectToAction("Index")); }
public ActionResult Share() { var model = new ShareCar(); model.Brand = db.Brand.ToList(); model.Model = new List <Model>(); model.Generation = new List <Generation>(); model.Body = new List <Body>(); model.Motor = new List <Motor>(); return(View(model)); }