示例#1
0
        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"));
        }
示例#2
0
        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"));
        }
示例#3
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        public ActionResult Models()
        {
            var repo = CarMasterRepoFactory.Create();
            AddModelViewModel model = new AddModelViewModel();

            model.SetMakesList(repo.GetAllMakes());
            return(View(model));
        }
示例#7
0
        private void AddModelExecuteAsync()
        {
            var dataContext = new AddModelViewModel(SelectedMake);

            ShowFromWorkplaceDialog(new AddModelWindow()
            {
                DataContext = dataContext
            });
        }
示例#8
0
        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();
        }
示例#9
0
        public async Task <IActionResult> Add()
        {
            List <Manufacturer> manufacturers = await _manufacturers.GetManufacturersAsync();

            AddModelViewModel model = new AddModelViewModel();

            model.SetManufacturers(manufacturers);
            return(View(model));
        }
示例#10
0
        public ActionResult AddModel()
        {
            var repo = RepositoryFactory.GetRepository();

            AddModelViewModel model = new AddModelViewModel();

            model.SetMakes(repo.GetMakes());
            model.Models = repo.GetModels();
            return(View(model));
        }
示例#11
0
        public ActionResult Models()
        {
            AddModelViewModel model = new AddModelViewModel()
            {
                Models = _modelRepo.GetAll(),
                Makes  = _makeRepo.GetAll()
            };

            return(View(model));
        }
示例#12
0
        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"));
        }
示例#13
0
        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));
            }
        }
示例#14
0
        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));
        }
示例#16
0
        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);
        }
示例#17
0
        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));
        }
示例#18
0
        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));
            }
        }
示例#19
0
        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));
        }
示例#20
0
        public ActionResult Models()
        {
            var viewModel = new AddModelViewModel();

            return(View(viewModel));
        }
示例#21
0
        public IActionResult Model(AddModelViewModel model)
        {
            string ViewName = model.AddType;

            return(RedirectToAction(ViewName));
        }
示例#22
0
        public IActionResult Model()
        {
            var ViewModel = new AddModelViewModel();

            return(View(ViewModel));
        }
示例#23
0
 private void CmbCategory_Loaded(object sender, RoutedEventArgs e)
 {
     cmbCategory.ItemsSource = AddModelViewModel.GetCategory();
 }