/// <summary> /// AddAsset page routing. /// </summary> /// <returns>Renders view of the page used to add new assets.</returns> public IActionResult AddAsset() { //Retrieves all assets types from AssetType table and adds to ViewBag to share with the view. var assetTypes = AssetTypeManager.GetAllAssetTypes(); ViewBag.AssetTypes = assetTypes; return(View()); }
/// <summary> /// Edit page routing. /// </summary> /// <param name="id">The Asset Id of the record that the user wants to modify.</param> /// <returns>Redirects user edit page with information from the selected record populated.</returns> public IActionResult Edit(int id) { //Retrieves all assets types from AssetType table and adds to ViewBag to share with the view. var assetTypes = AssetTypeManager.GetAllAssetTypes(); ViewBag.AssetTypes = assetTypes; //Retrieves the information associated with the currently selected asset record. var currentAsset = AssetManager.Find(id); return(View(currentAsset)); }
/// <summary> /// Index page routing. /// </summary> /// <returns>Renders the view of the index.</returns> public IActionResult Index() { //Retrieves all assets types from AssetType table. var assetTypes = AssetTypeManager.GetAllAssetTypes(); //Adds a new AssetType at index 0 with an Id of 0 so that we can show all AssetTypes. assetTypes.Insert(0, new Domain.AssetType { Id = 0, Name = "All Types" }); //Stores information in a ViewBag to be shared with the view. ViewBag.AssetTypes = assetTypes; return(View()); }
public IActionResult AddAsset(Asset asset) { try { //Attempt to add the new object to the database context. AssetManager.Add(asset); //If the update is successful, redirect to index. return(RedirectToAction("Index")); } catch { //If the update fails, reinitialize the asset types DropDownList and return the view. var assetTypes = AssetTypeManager.GetAllAssetTypes(); ViewBag.AssetTypes = assetTypes; return(View()); } }
public IActionResult Edit(Asset asset) { try { AssetManager.Update(asset); //Attempt to update the asset. return(RedirectToAction("Index")); //Attempt to redirect. } catch { //If update fails, reinitialize the page and DropDownList. var assetTypes = AssetTypeManager.GetAllAssetTypes(); ViewBag.AssetTypes = assetTypes; //Re-select the asset that the user was trying to edit. var currentAsset = AssetManager.Find(asset.Id); return(View(currentAsset)); } }
// GET: Assets public IActionResult Index() { var model = AssetManager.GetAllAssets(); // create select list var types = AssetTypeManager.GetAllAssetTypes(). Select(at => new SelectListItem { Text = at.Name, Value = at.Id.ToString() }).ToList(); types.Insert(0, new SelectListItem { Text = "All Assets", Value = "0" }); // assign select list to a ViewBag property to pass into View ViewBag.AssetTypes = types; return(View(model)); }
// GET: Assets/Create public IActionResult Create() { // create select list var types = AssetTypeManager.GetAllAssetTypes(). Select(at => new SelectListItem { Text = at.Name, Value = at.Id.ToString() }).ToList(); // create customized ViewModel var model = new AssetViewModel { Types = types, AssetTypeId = null, Description = null, Manufacturer = null, Model = null, SerialNumber = null, TagNumber = null }; // pass created ViewModel to View return(View(model)); }
// GET: AssetTypes/Edit/5 public ActionResult Edit(int id) { var model = AssetTypeManager.GetAllAssetTypes().SingleOrDefault(at => at.Id == id); return(View(model)); }
// GET: AssetTypes public ActionResult Index() { var model = AssetTypeManager.GetAllAssetTypes(); return(View(model)); }
// GET: AssetTypes public ActionResult Index() { var AssetTypeList = AssetTypeManager.GetAllAssetTypes(); return(View(AssetTypeList)); }