// User view for all parts public ActionResult ViewAllParts(DirtbikeModel iDirtbikeModel, PartModel iPartModel) { // Must be logged in to any role to access this view if (((LoginModel)Session["loginModel"]) != null) { MapperDirtbike map = new MapperDirtbike(); Dirtbike iDirtbike = new Dirtbike(); iDirtbike = map.MapDirtbike(iDirtbikeModel); DirtbikeBLL selectDirtbike = new DirtbikeBLL(); // Returned list of Dirtbikes from Database List <Dirtbike> listDirtbike = selectDirtbike.Select(iDirtbike); /* Get Dirtbike values from database and set it to * viewbag to pass it to view for drop downlist*/ IEnumerable <SelectListItem> makes = listDirtbike.Select(m => new SelectListItem { Value = m.Make, Text = m.Make }); ViewBag.Make = makes; IEnumerable <SelectListItem> makeYear = listDirtbike.Select(m => new SelectListItem { Value = m.MakeYear.ToString(), Text = m.MakeYear.ToString() }); ViewBag.MakeYear = makeYear; IEnumerable <SelectListItem> models = listDirtbike.Select(m => new SelectListItem { Value = m.Model, Text = m.Model }); ViewBag.Model = models; /* PartModel */ PartMapper partMap = new PartMapper(); Part iPart = new Part(); iPart = partMap.MapDirtbike(iPartModel); PartBLL selectPart = new PartBLL(); // Create List object for returned parts List <Part> listParts = selectPart.SelectAllParts(iPart); return(View(listParts)); } else { return(RedirectToAction("login", "home")); } }
// User View for specific part public ActionResult ViewPart(PartModel iPartID) { // Must be logged in to any role to access this view if (((LoginModel)Session["loginModel"]) != null) { ViewBag.Title = "Part View"; /* PartModel */ PartMapper partMap = new PartMapper(); Part iPart = new Part(); iPart = partMap.MapDirtbike(iPartID); PartBLL selectPart = new PartBLL(); // Create List object for returned parts where partID is the same as partID from user clicked part in Parts view List <Part> part = selectPart.SelectAllParts(iPart).Where(p => p.PartID == iPartID.PartID).ToList(); return(View(part)); } else { return(RedirectToAction("login", "home")); } }