Beispiel #1
0
        public IActionResult Edit(long id, softwareViewModel softwareViewModel, string productChild, bool?goToProductSupplier, bool?goToProductDetail, [Bind("ProductID,StatusID,SoftwareTypeID,SoftwareVersion,ProductTypeID,ProductSupplierID,Name,Description,InfoUrl,Image,SpecificationFile")] Software software)
        {
            if (id != software.ProductID)
            {
                return(NotFound());
            }

            Tuple <string, string, bool> filePath = service.UploadProductPdf(softwareViewModel.software.ProductID, softwareViewModel.FileDescription, softwareViewModel.File);

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

            if (ModelState.IsValid)
            {
                try
                {
                    service.Update(software);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SoftwareExists(software.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (goToProductSupplier == true)
                {
                    return(RedirectToAction("Create", "ProductSupplier", new { productID = software.ProductID, productChild }));
                }
                else if (goToProductDetail == true)
                {
                    return(RedirectToAction("Create", "ProductDetail", new { productID = software.ProductID, productChild }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["ProductTypeID"]  = new SelectList(service.GetSelectListProductTypeSoftware(), software.ProductTypeID);
            ViewData["SoftwareTypeID"] = new SelectList(service.GetSelectListSoftwareTypes(), software.SoftwareTypeID);
            ViewData["StatusID"]       = new List <SelectListItem>(service.GetSelectListStatusProduct());

            return(View(software));
        }
        public IActionResult Update(long id, [FromBody] Software device)
        {
            var existingSoftware = _softwareService.Get(id);

            if (existingSoftware == null)
            {
                return(new NotFoundObjectResult(string.Format("No device found for id: {0}", id)));
            }

            existingSoftware.Name      = device.Name;
            existingSoftware.IsDeleted = device.IsDeleted;
            existingSoftware.Package   = device.Package;

            var updatedSoftware = _softwareService.Update(existingSoftware);

            return(new OkObjectResult(updatedSoftware));
        }