Example #1
0
        public ActionResult Details(int id)
        {
            var asset = _assetRepository.Get(id, "AllocatedUser.Person");

            if (asset == null)
            {
                return(HttpNotFound());
            }

            var allocations = _assetAllocationRepository.GetAllBy(a => a.AssetId == asset.Id, "AllocatedUser.Person,AllocatedByUser.Person").ToList();
            var vm          = new AssetDetailsViewModel(asset)
            {
                AssetAllocations = allocations
            };

            // If we have snapshots, set snapshot variable
            var snapshot = _systemSnapshotRepository.GetBy(s => s.AssetId == asset.Id);

            if (snapshot != null)
            {
                vm.HasSoftwareInfo = true;
                vm.Softwares       = JsonConvert.DeserializeObject <List <SoftwareModel> >(snapshot.Softwares);

                vm.HasHardwareInfo = true;
                vm.Hardware        = JsonConvert.DeserializeObject <HardwareModel>(snapshot.Hardwares);
            }

            var assetDocs = _assetDocumentRepository.GetAllBy(a => a.AssetId == asset.Id);

            vm.AssetDocuments = assetDocs.ToList();

            return(View(vm));
        }
        public ActionResult DetailsPartial(string id)
        {
            var asset = this.assetService.GetById(id);

            if (!this.IsMegaAdmin())
            {
                //Verify if asset is from user organisation
                if (asset.Site.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                {
                    return(Redirect("/Home/NotAuthorized"));
                }
            }

            var viewModel = new AssetDetailsViewModel
            {
                Brand           = asset.Brand,
                Guarantee       = asset.Guarantee,
                InventoryNumber = asset.InventoryNumber,
                ItemModel       = asset.Model,
                Price           = asset.Price.Value,
                Producer        = asset.Producer,
                Type            = asset.Type,
                Status          = asset.Status,
                Currency        = asset.Price.Currency.Code
            };

            if (asset.Location != null)
            {
                viewModel.Location = new LocationViewModel
                {
                    Country      = asset.Location.Country != null ? asset.Location.Country : "",
                    Latitude     = asset.Location.Latitude != null ? asset.Location.Latitude : "",
                    Longitude    = asset.Location.Longitude != null ? asset.Location.Longitude : "",
                    Street       = asset.Location.Street != null ? asset.Location.Street : "",
                    StreetNumber = asset.Location.StreetNumber != null ? asset.Location.StreetNumber.Value : 0,
                    Town         = asset.Location.Town != null ? asset.Location.Town : "",
                };
            }

            if (asset.User != null)
            {
                viewModel.UserName = (asset.User.FirstName != null) ?
                                     asset.User.FirstName + " " + asset.User.SecondName + " " + asset.User.LastName :
                                     asset.User.Email;
            }

            viewModel.SiteName = asset.Site.Name;

            return(PartialView(viewModel));
        }
        //Create asset viewmodel from base model
        public AssetDetailsViewModel CreateAssetViewModel(string id)
        {
            var asset = this.assetService.GetById(id);

            var viewModel = new AssetDetailsViewModel
            {
                Brand           = asset.Brand,
                Guarantee       = asset.Guarantee,
                InventoryNumber = asset.InventoryNumber,
                ItemModel       = asset.Model,
                Price           = asset.Price.Value,
                Producer        = asset.Producer,
                Type            = asset.Type,
                Status          = asset.Status,
                Currency        = asset.Price.Currency.Code
            };

            if (asset.Location != null)
            {
                viewModel.Location = new LocationViewModel
                {
                    Country      = asset.Location.Country != null ? asset.Location.Country : "",
                    Latitude     = asset.Location.Latitude != null ? asset.Location.Latitude : "",
                    Longitude    = asset.Location.Longitude != null ? asset.Location.Longitude : "",
                    Street       = asset.Location.Street != null ? asset.Location.Street : "",
                    StreetNumber = asset.Location.StreetNumber != null ? asset.Location.StreetNumber.Value : 0,
                    Town         = asset.Location.Town != null ? asset.Location.Town : "",
                };
            }

            if (asset.User != null)
            {
                viewModel.UserName = (asset.User.FirstName != null) ?
                                     asset.User.FirstName + " " + asset.User.SecondName + " " + asset.User.LastName :
                                     asset.User.Email;
            }

            viewModel.SiteName = asset.Site.Name;

            return(viewModel);
        }
Example #4
0
        public static AssetDetailsViewModel GetCatalogAssetDetails(string catalogID, string accountItemID)
        {
            CatalogItemDetails dataModel = CatalogModel.GetCatalogItem(catalogID, accountItemID);
            CatalogDetails     catalog   = CatalogModel.GetCatalogDetails(catalogID);

            var vm = new AssetDetailsViewModel
            {
                Details = MapAssetDetails(dataModel, catalog)
            };

            if (string.IsNullOrEmpty(vm.Details.AccountItemID))
            {
                vm.Details.AccountItemID = accountItemID;
            }
            if (string.IsNullOrEmpty(vm.Details.CatalogID))
            {
                vm.Details.CatalogID = catalogID;
            }

            return(vm);
        }