public ActionResult Models(ModelsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = ModelsRepositoryFactory.GetRepository();

                try
                {
                    CarMastery.Models.Tables.Models addModel = new CarMastery.Models.Tables.Models();
                    addModel.UserId           = AuthorizeUtilities.GetUserId(this);
                    addModel.ModelDateAdded   = DateTime.Now;
                    addModel.ModelDescription = model.ModelToAdd.ModelDescription;
                    addModel.MakeId           = model.ModelToAdd.MakeId;

                    repo.AddModel(addModel);

                    return(RedirectToAction("Models"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var makesRepo = MakesRepositoryFactory.GetRepository();
                model.Makes = new SelectList(makesRepo.GetAllMakes(), "MakeId", "MakeDescription");
                return(View(model));
            }
        }
Beispiel #2
0
        public ActionResult Models()
        {
            var allUsers  = _context.Users.ToList();
            var allMakes  = _context.Makes.ToList();
            var allModels = _context.Models.ToList();

            var model = new ModelsViewModel();

            var modelsRepo = ModelFactory.GetRepository();
            var makesRepo  = MakeFactory.GetRepository();

            List <ModelsViewModel> modelList = allModels.Select(x => new ModelsViewModel
            {
                MakeName  = allMakes.Where(y => y.MakeID == x.MakeID).Select(y => y.MakeName).FirstOrDefault(),
                ModelName = x.ModelName,
                DateAdded = x.DateAdded,
                User      = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault()
            }).ToList();


            ModelsViewModel viewModel = new ModelsViewModel
            {
                Makes    = makesRepo.GetMakes(),
                Models   = modelsRepo.GetModels(),
                ModelsVM = modelList
            };

            return(View(viewModel));
        }
        public ActionResult SampleModels()
        {
            ModelsViewModel modelsViewModel = new ModelsViewModel();

            modelsViewModel.pagesData  = getData.getPageInfo(Request.Path);
            modelsViewModel.modelsList = db.models.ToList();
            return(View(modelsViewModel));
        }
Beispiel #4
0
        public ActionResult Index()
        {
            ModelsViewModel viewModel = new ModelsViewModel();

            viewModel.Artists = db.Artists.ToList();
            viewModel.Albums  = db.Albums.ToList();
            viewModel.Songs   = db.Songs.Distinct().ToList();


            return(View(viewModel));
        }
        public ActionResult Models()
        {
            var repo  = ModelRepositoryFactory.GetRepository();
            var model = new ModelsViewModel();

            model.models = repo.GetAll();
            var MakesRepo = MakeRepositoryFactory.GetRepository();

            model.makes = new SelectList(MakesRepo.GetAll(), "MakeID", "Make");
            return(View(model));
        }
        public ActionResult Models()
        {
            var model     = new ModelsViewModel();
            var repo      = ModelsRepositoryFactory.GetRepository();
            var makesRepo = MakesRepositoryFactory.GetRepository();

            model.ModelsList = repo.GetAllModels().ToList();
            model.ModelToAdd = new CarMastery.Models.Tables.Models();
            model.Makes      = new SelectList(makesRepo.GetAllMakes(), "MakeId", "MakeDescription");

            return(View(model));
        }
Beispiel #7
0
        public ActionResult Models(ModelsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var modelsRepo = ModelFactory.GetRepository();
                var makesRepo  = MakeFactory.GetRepository();

                model.Model           = new Model();
                model.Model.MakeID    = model.Car.MakeID;
                model.Model.ModelName = model.Car.Model.ModelName;
                model.Model.UserID    = AuthorizeUtilities.GetUserId(this);
                model.Model.DateAdded = DateTime.Now.ToString("MM/dd/yyyy");

                modelsRepo.InsertModel(model.Model);

                var allUsers  = _context.Users.ToList();
                var allMakes  = _context.Makes.ToList();
                var allModels = _context.Models.ToList();

                List <ModelsViewModel> modelList = allModels.Select(x => new ModelsViewModel
                {
                    MakeName  = allMakes.Where(y => y.MakeID == x.MakeID).Select(y => y.MakeName).FirstOrDefault(),
                    ModelName = x.ModelName,
                    DateAdded = x.DateAdded,
                    User      = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault()
                }).ToList();


                ModelsViewModel viewModel = new ModelsViewModel
                {
                    Makes    = makesRepo.GetMakes(),
                    Models   = modelsRepo.GetModels(),
                    ModelsVM = modelList
                };

                return(View(viewModel));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult AddModel(ModelsViewModel model)
        {
            model.newModel.UserName = this.User.Identity.Name;
            var repo = ModelRepositoryFactory.GetRepository();

            try
            {
                repo.Add(model.newModel);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            repo         = ModelRepositoryFactory.GetRepository();
            model.models = repo.GetAll();
            var MakesRepo = MakeRepositoryFactory.GetRepository();

            model.makes = new SelectList(MakesRepo.GetAll(), "MakeID", "Make");
            return(View("Models", model));
        }
Beispiel #9
0
        private ModelsViewModel GetViewModel(IList <ModelModelPicture> castedData)
        {
            var viewModel = new ModelsViewModel();

            foreach (var castedItem in castedData)
            {
                var existingItem = viewModel.Models.Where(x => x.Name == castedItem.Name).FirstOrDefault();

                if (existingItem == null)
                {
                    viewModel.Models.Add(new PictureViewModel {
                        Location = castedItem.Location, Name = castedItem.Name, Titles = new List <string> {
                            castedItem.Title
                        }
                    });

                    continue;
                }

                viewModel.Models.Where(x => x == existingItem).FirstOrDefault().Titles.Add(castedItem.Title);
            }

            return(viewModel);
        }
Beispiel #10
0
 internal ModuleView(Process process)
 {
     InitializeComponent();
     DataContext = new ModelsViewModel(process.Modules);
 }