public ActionResult Create() { var makes = this.GetMakes(); var viewModel = new CreateCarIndexModel(); viewModel.DropDownSelections.Makes = makes; viewModel.InsertCarModel = new InsertCarModel(); return this.View(viewModel); }
public ActionResult Create(InsertCarModel model) { if (ModelState.IsValid && model != null) { var car = new Car { CarMakeId = model.SelectedMakeId, CarModelId = model.SelectedModelId, CreatedOn = DateTime.Now, OwnerId = this.CurrentUser.Id, Price = model.Price, Details = model.Details, CarYearId = model.SelectedCarYearId }; if (model.Image != null) { var pictureData = this.ReadPictureFromFile(model.Image); car.Pictures.Add(new Picture() { Image = pictureData }); } this.Data.Cars.Add(car); this.Data.SaveChanges(); this.cache.RemoveAllCarsWithoutViewModel(); this.cache.RemoveAllCarsFromCashe(); return this.RedirectToAction<HomeController>(c => c.Index()); } var inputModel = new CreateCarIndexModel(); inputModel.DropDownSelections.Makes = this.GetMakes(); inputModel.InsertCarModel = model; return this.View(inputModel); }