Пример #1
0
        public async Task <IActionResult> Edit(HardwareViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var hardware = model.FromView() !;

                if (hardware.Id == 0)
                {
                    await _hardwaresRepository.AddAsync(hardware).ConfigureAwait(false);
                }
                else
                {
                    await _hardwaresRepository.UpdateAsync(hardware).ConfigureAwait(false);
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                LogError(ex);
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// OnConfigureHardware opens the Configure Hardware Wizard
        /// so that the user can set up the licensing.
        /// </summary>
        private void OnConfigureHardware()
        {
            //Create a HardwareWizard and Show it
            HardwareViewModel hwVM = this._unity.Resolve <HardwareViewModel>();
            HardwareView      hwV  = this._unity.Resolve <HardwareView>();

            //Register the Instance of the HardwareView
            this._unity.RegisterInstance <HardwareView>(Strings.HardwareWizardName, hwV);

            //Wire up the View with the ViewModel and vice-versa
            hwV.DataContext = hwVM;
            hwVM.HookEvents(hwV);

            //Get a reference to the Shell and make it
            //the Owner of the Wizard
            ShellView sv = this._unity.Resolve <ShellView>(Strings.ShellViewName);

            hwV.Owner = sv;

            //Show the Dialog
            Nullable <Boolean> result = hwV.ShowDialog();

            //If the user Finished the Dialog, fire the event
            //to notify of UI changes
            if (result == true)
            {
                this._eventAggregator.GetEvent <HardwareChangedEvent>().Publish(null);
            }
        }
Пример #3
0
        public HardwareViewModel Save(HardwareViewModel hardware)
        {
            var hard = FromHard(hardware);

            db.Entry(hard).State = EntityState.Modified;
            db.SaveChanges();
            return(HardDto(hard));
        }
Пример #4
0
 public static IHardwareInfo AssembleFromViewModel(HardwareViewModel viewModel)
 {
     return(new HardwareInformation()
     {
         ShortName = viewModel.ShortName,
         UnitSymbol = viewModel.UnitSymbol,
         MainValue = viewModel.MainValue
     });
 }
        public IActionResult Edit(long id, HardwareViewModel hardwareViewModel, string productChild, bool?goToProductSupplier, bool?goToProductDetail, [Bind("ProductID,ProductTypeID,Name,Description,StatusID,InfoUrl,SpecificationFile")] Hardware hardware)
        {
            if (id != hardware.ProductID)
            {
                return(NotFound());
            }

            //if (hardwareViewModel.File != null)
            //{
            //upload file
            Tuple <string, string, bool> filePath = service.UploadProductPdf(hardwareViewModel.hardware.ProductID, hardwareViewModel.FileDescription, hardwareViewModel.File);

            //add FileName and FilePath to hardware so that this will be saved to the database
            hardware.SpecificationFileName = filePath.Item1;
            hardware.SpecificationFilePath = filePath.Item2;
            hardware.HasFile = filePath.Item3;
            //}

            ModelState.Clear();
            TryValidateModel(hardware);

            if (ModelState.IsValid)
            {
                try
                {
                    service.Update(hardware);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HardwareExists(hardware.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                if (goToProductSupplier == true)
                {
                    return(RedirectToAction("Create", "ProductSupplier", new { productID = hardware.ProductID, productChild }));
                }
                else if (goToProductDetail == true)
                {
                    return(RedirectToAction("Create", "ProductDetail", new { productID = hardware.ProductID, productChild }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ProductTypeDropDown(hardware.ProductTypeID);
            StatusDropDown(hardware.StatusID);
            //ViewData["ProductTypeID"] = new List<SelectListItem>(service.GetSelectListProductTypeHardware());
            return(View(hardware));
        }
Пример #6
0
 public ActionResult Edit([Bind(Include = "HardwareId,Product,ProdDesc,AdvOverBeijer,AdditionalSpecs")] HardwareViewModel hardware)
 {
     if (ModelState.IsValid)
     {
         _hardwareService.Save(hardware);
         return(RedirectToAction("Index"));
     }
     return(View(hardware));
 }
Пример #7
0
        public HardwareViewModel Create(HardwareViewModel hardware)
        {
            var hard = FromHard(hardware);

            db.Hardwares.Add(hard);
            db.SaveChanges();

            hard.HardwareId = hardware.HardwareId;
            return(HardDto(hard));
        }
Пример #8
0
        public void GivenHardwareInfo_WhenConvertToString_ThenItFormatsProper()
        {
            HardwareViewModel subject = new HardwareViewModel()
            {
                MainValue  = "TEST",
                ShortName  = "T",
                UnitSymbol = "PASSED"
            };

            Assert.Equal("TEST PASSED", subject.ToString());;
        }
Пример #9
0
        private static Hardware FromHard(HardwareViewModel hardware)
        {
            var hard = new Hardware
            {
                HardwareId      = hardware.HardwareId,
                Product         = hardware.Product,
                ProdDesc        = hardware.ProdDesc,
                AdditionalSpecs = hardware.AdditionalSpecs,
                AdvOverBeijer   = hardware.AdvOverBeijer
            };

            return(hard);
        }
Пример #10
0
        // GET: Hardware/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HardwareViewModel hardware = _hardwareService.FindById(id.Value);

            if (hardware == null)
            {
                return(HttpNotFound());
            }
            return(View(hardware));
        }
Пример #11
0
        public void GivenModel_WhenAssemble_ThenItAssembleToViewModel()
        {
            Mock <IHardwareInfo> model = new Mock <IHardwareInfo>();

            model.SetupGet(m => m.ShortName).Returns(ShortName);
            model.SetupGet(m => m.UnitSymbol).Returns(Unit);
            model.SetupGet(m => m.MainValue).Returns(MainValue);

            HardwareViewModel vm = HardwareAssembler.AssembleFromModel(model.Object);

            Assert.NotNull(vm);
            Assert.Equal(ShortName, vm.ShortName);
            Assert.Equal(Unit, vm.UnitSymbol);
            Assert.Equal(MainValue, vm.MainValue);
        }
        public HardwareViewModel loadHardwareViewModel(long id)
        {
            HardwareViewModel hardwareViewModel = new HardwareViewModel();

            //Get the specific hardware (product) info...
            hardwareViewModel.hardware        = FindById(id);
            hardwareViewModel.FileDescription = hardwareViewModel.hardware.SpecificationFileName;

            //and get then all suppliers for this hardware (product)...
            hardwareViewModel.productSuppliers = repositoryProductSupplier.GetAllProductSuppliersPerProduct(id);

            //and geet then all product details for this hardware (product).
            hardwareViewModel.productDetails = repositoryProductDetail.GetAllProductDetailsPerProduct(id);

            hardwareViewModel.purchaseItems = repositoryPurchaseItem.GetAllPurchaseItemsOfProduct(id);

            return(hardwareViewModel);
        }
Пример #13
0
        public DeviceManageViewModel()
        {
            DevicemaCommand = new DelegateCommand <object>(DevicemaShow);
            UseCommand      = new DelegateCommand <object>(UseShow);
            NetCommand      = new DelegateCommand <object>(NetShow);
            UpgradeCommand  = new DelegateCommand <object>(UpgradeShow);
            AbnormalCommand = new DelegateCommand <object>(AbnormalShow);
            HardwareCommand = new DelegateCommand <object>(HardwareShow);

            _DevicemaViewModel = new DevicemaViewModel();
            _UserViewModel     = new UserViewModel();
            _NetViewModel      = new NetViewModel();
            _UpgradeViewModel  = new UpgradeViewModel();
            _AbnormalViewModel = new AbnormalViewModel();
            _HardwareViewModel = new HardwareViewModel();



            bShowPage = DeviceVisibleEnum.DeviceVisibleEnum_Device;
        }
        public IActionResult RemoveSpecificationFilePdf(long id, HardwareViewModel hardwareViewModel, [Bind("ProductID,ProductTypeID,Name,Description,StatusID,InfoUrl,SpecificationFile")] Hardware hardware)
        {
            if (id != hardware.ProductID)
            {
                return(NotFound());
            }

            Tuple <string, string, bool> removePDF = service.RemoveSpecificationFilePdf(hardwareViewModel.hardware.ProductID);

            hardware.SpecificationFileName = "";
            hardware.SpecificationFilePath = "";
            hardware.HasFile = false;

            ModelState.Clear();
            TryValidateModel(hardware);

            if (ModelState.IsValid)
            {
                try
                {
                    service.Update(hardware);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HardwareExists(hardware.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction(nameof(Index));
                //return RedirectToAction("Edit", "Hardware", new { id = hardware.ProductID });
            }

            return(RedirectToAction("Edit", "Hardware", new { id = hardware.ProductID }));
        }
        public IActionResult Edit(long?id, long?assetID)
        {
            if (id == null)
            {
                return(NotFound());
            }

            HardwareViewModel hardware = service.loadHardwareViewModel(id.Value);

            if (hardware == null)
            {
                return(NotFound());
            }

            ProductTypeDropDown(hardware.hardware.ProductTypeID);
            StatusDropDown(hardware.hardware.StatusID);
            //ViewData["ProductTypeID"] = new List<SelectListItem>(service.GetSelectListProductTypeHardware());

            ViewData["assetID"] = assetID;

            return(View(hardware));
        }
        public IActionResult Create(HardwareViewModel hardwareViewModel, [Bind("ProductID,ProductTypeID,Name,Description,StatusID,InfoUrl,SpecificationFile")] Hardware hardware)
        {
            //upload file
            Tuple <string, string, bool> filePath = service.UploadProductPdf(hardwareViewModel.hardware.ProductID, hardwareViewModel.FileDescription, hardwareViewModel.File);

            //add FileName and FilePath to hardware so that this will be saved to the database
            hardware.SpecificationFileName = filePath.Item1;
            hardware.SpecificationFilePath = filePath.Item2;
            hardware.HasFile = filePath.Item3;

            if (ModelState.IsValid)
            {
                hardware = service.Add(hardware);

                return(RedirectToAction("Edit", "Hardware", new { id = hardware.ProductID }));
                //return RedirectToAction(nameof(Index));
            }

            ProductTypeDropDown(hardware.ProductTypeID);
            StatusDropDown(hardware.StatusID);

            //ViewData["ProductTypeID"] = new List<SelectListItem>(service.GetSelectListProductTypeHardware());
            return(View(hardwareViewModel));
        }