public ActionResult Makes(MakesViewModel makes) { if (ModelState.IsValid) { var makesRepo = MakeFactory.GetRepository(); makes.Make.UserID = AuthorizeUtilities.GetUserId(this); makes.Make.DateAdded = DateTime.Now.ToString("MM/dd/yyyy"); makesRepo.InsertMake(makes.Make); var allUsers = _context.Users.ToList(); var allMakes = _context.Makes.ToList(); makes.Makes = makesRepo.GetMakes(); makes.MakesVM = new List <MakesViewModel>(); makes.MakesVM = allMakes.Select(x => new MakesViewModel { MakeName = x.MakeName, DateAdded = x.DateAdded, User = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault() }).ToList(); return(View(makes)); } else { return(View(makes)); } }
public ActionResult Makes(MakesViewModel model) { if (ModelState.IsValid) { var repo = MakesRepositoryFactory.GetRepository(); try { Makes make = new CarMastery.Models.Tables.Makes(); make.MakeDescription = model.MakeToAdd.MakeDescription; make.UserId = AuthorizeUtilities.GetUserId(this); make.MakeDateAdded = DateTime.Now; repo.AddMake(make); return(RedirectToAction("Makes")); } catch (Exception ex) { throw ex; } } else { return(View(model)); } }
public ActionResult Index(int id, string orderBy = "Id") { var make = _appDdContext.Makes.Single(m => m.MakeId == id); var query = "SELECT * FROM MotorBikes WHERE MakeID = " + id + " ORDER BY " + orderBy; var motorBikes = _appDdContext.MotorBikes.FromSql(query); ViewBag.Make = make.Name; ViewBag.MakeId = make.MakeId; Console.WriteLine(query); var allMakes = _appDdContext.Makes.AsEnumerable(); var makeVM = new MakesViewModel { MotorBikesForMake = motorBikes, AllMakes = allMakes }; if (motorBikes.Count() > 0 && orderBy.Length > 10) { Console.WriteLine("UNION INJECTION: {0}", query); } return(View(makeVM)); }
public ActionResult Makes() { var repo = MakeRepositoryFactory.GetRepository(); var model = new MakesViewModel(); model.makes = repo.GetAll(); return(View(model)); }
public ActionResult Makes() { var model = new MakesViewModel(); var repo = MakesRepositoryFactory.GetRepository(); model.MakesList = repo.GetAllMakes().ToList(); model.MakeToAdd = new Makes(); return(View(model)); }
public MakesViewModel GetMakes() { MakesViewModel makes = new MakesViewModel { Makes = _context.Makes.Select(make => new MakesViewModel.Make { MakeId = make.MakeId, Name = make.Name }).OrderBy(make => make.Name).ToList() }; return(makes); }
public ActionResult AddMake(MakesViewModel model) { model.newMake.UserName = this.User.Identity.Name; var repo = MakeRepositoryFactory.GetRepository(); try { repo.Add(model.newMake); } catch (Exception ex) { throw ex; } model = new MakesViewModel(); model.makes = repo.GetAll(); return(View("Makes", model)); }
public ActionResult Makes() { var allUsers = _context.Users.ToList(); var allMakes = _context.Makes.ToList(); var model = new MakesViewModel(); var makesRepo = MakeFactory.GetRepository(); model.Makes = makesRepo.GetMakes(); model.MakesVM = new List <MakesViewModel>(); model.MakesVM = allMakes.Select(x => new MakesViewModel { MakeName = x.MakeName, DateAdded = x.DateAdded, User = allUsers.Where(y => y.Id == x.UserID).Select(y => y.Email).FirstOrDefault() }).ToList(); return(View(model)); }