public PartialViewResult UpdateAsset(AssetFormViewModel avm)
        {
            avm.Manufacturers = _repo.GetManufacturers();
            avm.Models        = _repo.GetModels();
            avm.Locations     = _repo.GetLocations();
            avm.ClientSites   = _repo.GetClientSites();
            avm.Products      = _repo.GetProducts();

            if (ModelState.IsValid)
            {
                Response.StatusCode = 200;
                var a = new Asset
                {
                    Product        = _repo.GetProductById(avm.SelectedProductId),
                    Manufacturer   = _repo.GetManufacturerById(avm.SelectedManufacturerId),
                    Model          = _repo.GetModelById(avm.SelectedModelId),
                    Location       = _repo.GetLocationById(avm.SelectedLocationId),
                    ClientSite     = _repo.GetClientSiteById(avm.SelectedClientSiteId),
                    AssetKey       = int.Parse(avm.AssetTag),
                    SerialNumber   = avm.SerialNumber,
                    ItemName       = avm.ItemName,
                    InventoryOwner = avm.InventoryOwner,
                    InventoriedBy  = avm.InventoriedBy,
                    InventoryDate  = avm.InventoryDate,
                    IsDisposed     = avm.IsDisposed
                };
                _repo.UpdateAsset(a);
                return(PartialView("_modifyAssetModal", avm));
            }

            Response.StatusCode = 422;
            return(PartialView("_modifyAssetForm", avm));
        }
        public PartialViewResult EditAsset(int assetKey)
        {
            ViewBag.ModalName = "Edit";

            var a    = _repo.FindAssetByKey(assetKey);
            var afvm = new AssetFormViewModel
            {
                AssetTag               = a.AssetKey.ToString(),
                ItemName               = a.ItemName,
                SerialNumber           = a.SerialNumber,
                InventoriedBy          = a.InventoriedBy,
                InventoryOwner         = a.InventoryOwner,
                PurchaseDate           = a.PurchaseDate,
                IsDisposed             = a.IsDisposed,
                InventoryDate          = a.InventoryDate,
                SelectedManufacturerId = a.Manufacturer.Id,
                SelectedModelId        = a.Model.Id,
                SelectedProductId      = a.Product.Id,
                SelectedClientSiteId   = a.ClientSite.Id,
                SelectedLocationId     = a.Location.Id,
                Manufacturers          = _repo.GetManufacturers(),
                Models      = _repo.GetModels(),
                Locations   = _repo.GetLocations(),
                ClientSites = _repo.GetClientSites(),
                Products    = _repo.GetProducts()
            };

            return(PartialView("_modifyAssetModal", afvm));
        }
예제 #3
0
        // GET: Assets/Create
        public ActionResult Create()
        {
            var assetTypes = _assetTypeService.GetAll();

            var viewModel = new AssetFormViewModel()
            {
                AssetTypes = assetTypes.Select(_autoMapper.Map <AssetType, AssetTypeDto>),
                //Asset = new AssetDto()
            };

            return(View(viewModel));
        }
예제 #4
0
        public async Task <ActionResult <Asset> > PostAssets([FromBody] AssetFormViewModel asset)
        {
            VerifyUser();
            var model = new Asset()
            {
                AssetNumber           = asset.AssetNumber,
                AssetName             = asset.AssetName,
                AssetType             = asset.AssetType,
                FullNameEmployeeAsset = asset.FullNameEmployeeAsset,
                AcquisitionDate       = asset.AcquisitionDate
            };

            EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent);
            _context.Assets.Add(model);
            await _context.SaveChangesAsync();

            return(Created("", model));
        }
        public PartialViewResult AddAsset(string assetKey = "", string inventoryOwner = "")
        {
            var avm = new AssetFormViewModel
            {
                AssetTag       = assetKey,
                InventoryOwner = inventoryOwner,
                Manufacturers  = _repo.GetManufacturers(),
                Models         = _repo.GetModels(),
                Locations      = _repo.GetLocations(),
                ClientSites    = _repo.GetClientSites(),
                Products       = _repo.GetProducts()
            };


            ViewBag.ModalName = "Add";


            return(PartialView("_modifyAssetModal", avm));
        }
예제 #6
0
        public ActionResult Save(AssetDto assetDto)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new AssetFormViewModel
                {
                    AssetTypes = _assetTypeService.GetAll().Select(_autoMapper.Map <AssetType, AssetTypeDto>),
                    //Asset = assetDto
                };

                return(View("Create", viewModel));
            }
            try
            {
                // TODO: Add insert logic here
                if (assetDto.Id == 0)
                {
                    assetDto.NumberAvailable = assetDto.NumberInStock;

                    _assetService.Add(_autoMapper.Map <AssetDto, Asset>(assetDto));
                }
                else
                {
                    var assetInDb = _assetService.GetById(assetDto.Id);

                    assetInDb.Name          = assetDto.Name;
                    assetInDb.Description   = assetDto.Description;
                    assetInDb.AssetTypeId   = assetDto.AssetTypeId;
                    assetInDb.NumberInStock = assetDto.NumberInStock;
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
예제 #7
0
        public async Task <IActionResult> PutAssets(int id, [FromBody] AssetFormViewModel asset)
        {
            /*if (id != informalEducation.Id)
             * {
             *  return BadRequest();
             * }*/

            try
            {
                VerifyUser();
                var model = await _context.Assets.FindAsync(id);

                {
                    model.AssetNumber           = asset.AssetNumber;
                    model.AssetName             = asset.AssetName;
                    model.AssetType             = asset.AssetType;
                    model.FullNameEmployeeAsset = asset.FullNameEmployeeAsset;
                    model.AcquisitionDate       = asset.AcquisitionDate;
                };
                EntityExtension.FlagForUpdate(model, _identityService.Username, UserAgent);
                _context.Assets.Update(model);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!assetExist(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }