public ActionResult AddModel(AddModelViewModel model) { var repo = RepositoryFactory.GetRepository(); Model newModel = new Model(); if (!ModelState.IsValid) { model.SetMakes(repo.GetMakes()); return(View(model)); } newModel.Description = model.ModelDescription; newModel.MakeId = model.MakeId; newModel.DateAdded = DateTime.Now.ToString(); //Find id of logged in user var userName = User.Identity.GetUserName(); var userId = context.Users.FirstOrDefault(u => u.UserName == userName).Id; newModel.UserId = userId; repo.AddModel(newModel); return(RedirectToAction("AddModel", "Admin")); }
public ActionResult AddModel(AddModelViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Model m = (from mdl in ent.Models where mdl.ModelName == model.ModelName select mdl).FirstOrDefault(); if (m != null) { return(View(model)); } m = new Model(); m.ModelName = model.ModelName; m.Description = model.Description; m.TrademarkId = model.TrademarkId; try { ent.Models.Add(m); ent.SaveChanges(); } catch (Exception ex) { string message = ex.Message; RedirectToAction("AddModel", model); } return(View("AddCTM")); }
public ActionResult AddModel() { var model = new AddModelViewModel(); model.SetMakes(repo.GetAllMakes()); return(View(model)); }
public ActionResult Models() { var models = new AddModelViewModel(); models.ModelList = _carDealer.GetAllCarModels(); return(View(models)); }
public ActionResult Models(AddModelViewModel AddModel) { if (ModelState.IsValid) { Model newModel = new Model() { MakeId = AddModel.MakeId, Addedby = User.Identity.Name, DateAdded = DateTime.Today, ModelName = AddModel.Model }; _modelRepo.Insert(newModel); AddModel.Makes = _makeRepo.GetAll(); AddModel.Models = _modelRepo.GetAll(); TempData["Success"] = "Model Successfully Added!"; return(View(AddModel)); } AddModel.Makes = _makeRepo.GetAll(); AddModel.Models = _modelRepo.GetAll(); return(View(AddModel)); }
public ActionResult Models() { var repo = CarMasterRepoFactory.Create(); AddModelViewModel model = new AddModelViewModel(); model.SetMakesList(repo.GetAllMakes()); return(View(model)); }
private void AddModelExecuteAsync() { var dataContext = new AddModelViewModel(SelectedMake); ShowFromWorkplaceDialog(new AddModelWindow() { DataContext = dataContext }); }
private void BtnAddModel_Click(object sender, RoutedEventArgs e) { string model = txbModel.Text; string category = cmbCategory.SelectedItem.ToString(); MessageBox.Show(category + " " + model + " " + brand); AddModelViewModel.AddModel(model, brand, category); this.Close(); }
public async Task <IActionResult> Add() { List <Manufacturer> manufacturers = await _manufacturers.GetManufacturersAsync(); AddModelViewModel model = new AddModelViewModel(); model.SetManufacturers(manufacturers); return(View(model)); }
public ActionResult AddModel() { var repo = RepositoryFactory.GetRepository(); AddModelViewModel model = new AddModelViewModel(); model.SetMakes(repo.GetMakes()); model.Models = repo.GetModels(); return(View(model)); }
public ActionResult Models() { AddModelViewModel model = new AddModelViewModel() { Models = _modelRepo.GetAll(), Makes = _makeRepo.GetAll() }; return(View(model)); }
public ActionResult AddModel(AddModelViewModel model) { VehicleModel vModel = new VehicleModel(); var modName = model.ModelType; vModel.VehicleModelName = modName; var userId = User.Identity.GetUserId(); var user = repo.GetUser(userId); var make = repo.GetMakeById(model.VehicleMakeId); vModel.User = user; vModel.VehicleMakeId = model.VehicleMakeId; repo.AddModel(vModel); return(RedirectToAction("Models")); }
public ActionResult Models(AddModelViewModel model) { var repo = MakeModelRepositoryFactory.GetRepository(); if (string.IsNullOrEmpty(model.CarModelName)) { ModelState.AddModelError("CarModelName", "Please enter a car model"); } if (ModelState.IsValid) { try { model.NewModel = new CarModel(); model.NewModel.CarMakeName = model.CarMakeName; model.NewModel.CarModelName = model.CarModelName; model.NewModel.DateCreated = model.DateCreated; var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var user = userMgr.FindByName(User.Identity.Name); ViewBag.UserName = user.UserName; repo.AddModel(model.NewModel); return(RedirectToAction("Models", "Admin")); } catch (Exception ex) { throw ex; } } else { model.Models = repo.GetModels(); model.Makes = (from type in repo.GetMakes() select new SelectListItem() { Text = type.CarMakeName, Value = type.CarMakeName, }).ToList(); return(View(model)); } }
public async Task <IActionResult> Add(AddModelViewModel model) { if (ModelState.IsValid) { Model aircraftModel = await _models.AddModelAsync(model.Name, model.ManufacturerId); ModelState.Clear(); model.Clear(); model.Message = $"Model '{aircraftModel.Name}' added successfully"; } List <Manufacturer> manufacturers = await _manufacturers.GetManufacturersAsync(); model.SetManufacturers(manufacturers); return(View(model)); }
public ActionResult Models(AddModelViewModel viewModel) { if (ModelState.IsValid) { bool success = DataManager.Instance.AddModel(viewModel.Make, viewModel.Model); if (success) { return(RedirectToAction("Vehicles", new { Message = $"Successfully added {viewModel.Model} to the {viewModel.Make} make" })); } // if we got here the model already exists for this make ModelState.AddModelError("Model", $"The model '{viewModel.Model}' already exists for the {viewModel.Make} make"); } // if we got here the model was invalid return(View(viewModel)); }
public List <AddModelViewModel> GetAllModelDetails() { var list = new List <AddModelViewModel>(); var makeRepo = MakeRepositoryFactory.GetMakeRepository(); foreach (var model in modelList) { var addModelViewModel = new AddModelViewModel(); addModelViewModel.ModelName = model.ModelName; addModelViewModel.MakeName = makeRepo.GetMakeById(model.MakeId); addModelViewModel.MakeId = model.MakeId; addModelViewModel.UserEmail = "abc"; addModelViewModel.DateAdded = model.DateAdded; list.Add(addModelViewModel); } return(list); }
public ActionResult Models(AddModelViewModel addModelViewModel) { var repo = ModelRepositoryFactory.GetModelRepository(); var makeRepo = MakeRepositoryFactory.GetMakeRepository(); var vehicleModel = new Model() { ModelName = addModelViewModel.ModelName, MakeId = makeRepo.GetMakeIdByName(addModelViewModel.MakeName), UserId = User.Identity.GetUserId(), DateAdded = DateTime.Today }; repo.AddModel(vehicleModel); var viewModel = new AddModelViewModel(); return(View(viewModel)); }
public ActionResult AddModel(AddModelViewModel modelToCreate) { //VM-Model and makeslist //Model //ModelId, ModelDescription, DateAdded, MakeId var repo = CarMasterRepoFactory.Create(); if (ModelState.IsValid) { //Model newModel = new Model(); //modelToCreate.Model.DateAdded = DateTime.Now; //m.Model.DateAdded = DateTime.Now; //newModel.ModelDescription = m.Model.ModelDescription; //newModel.Make.MakeId = m.Model.Make.MakeId; repo.CreateModel(modelToCreate.Model); return(RedirectToAction("Models")); } else { AddModelViewModel result = new AddModelViewModel(); result.SetMakesList(repo.GetAllMakes()); return(View(result)); } }
public ActionResult Models() { if (Request.IsAuthenticated) { var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var user = userMgr.FindByName(User.Identity.Name); ViewBag.UserName = user.UserName; } AddModelViewModel model = new AddModelViewModel(); var repo = MakeModelRepositoryFactory.GetRepository(); model.Models = repo.GetModels(); model.Makes = (from type in repo.GetMakes() select new SelectListItem() { Text = type.CarMakeName, Value = type.CarMakeName, }).ToList(); return(View(model)); }
public ActionResult Models() { var viewModel = new AddModelViewModel(); return(View(viewModel)); }
public IActionResult Model(AddModelViewModel model) { string ViewName = model.AddType; return(RedirectToAction(ViewName)); }
public IActionResult Model() { var ViewModel = new AddModelViewModel(); return(View(ViewModel)); }
private void CmbCategory_Loaded(object sender, RoutedEventArgs e) { cmbCategory.ItemsSource = AddModelViewModel.GetCategory(); }