コード例 #1
0
        /// <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());
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        /// <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());
        }
コード例 #4
0
        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());
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        // 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));
        }
コード例 #7
0
        // 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));
        }
コード例 #8
0
        // GET: AssetTypes/Edit/5
        public ActionResult Edit(int id)
        {
            var model = AssetTypeManager.GetAllAssetTypes().SingleOrDefault(at => at.Id == id);

            return(View(model));
        }
コード例 #9
0
        // GET: AssetTypes
        public ActionResult Index()
        {
            var model = AssetTypeManager.GetAllAssetTypes();

            return(View(model));
        }
コード例 #10
0
        // GET: AssetTypes
        public ActionResult Index()
        {
            var AssetTypeList = AssetTypeManager.GetAllAssetTypes();

            return(View(AssetTypeList));
        }