コード例 #1
0
        public IActionResult Edit(string id)
        {
            var partDetails = _partService.GetPartById(Convert.ToInt32(id));

            if (partDetails != null)
            {
                var model = LoadData();

                var partViewModel = partDetails.ToViewModel();
                partViewModel.PartCategoryItems     = model.PartCategoryItems;
                partViewModel.PartTypeItems         = model.PartTypeItems;
                partViewModel.CurrencyItems         = model.CurrencyItems;
                partViewModel.UnitItems             = model.UnitItems;
                partViewModel.MaterialCategoryItems = model.MaterialCategoryItems;
                partViewModel.APItems        = model.APItems;
                partViewModel.ACItems        = model.ACItems;
                partViewModel.ASCItems       = model.ASCItems;
                partViewModel.ShelfLifeItems = model.ShelfLifeItems;
                partViewModel.LeadTimeItems  = model.LeadTimeItems;
                partViewModel.OSIItems       = model.OSIItems;
                partViewModel.UnitCubeItems  = model.UnitCubeItems;
                partViewModel.SecurityItems  = model.SecurityItems;


                var folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads");

                partViewModel.PictureFileName = $"\\Uploads\\{partViewModel.PictureFileName}";

                var cageInfo = _partService.GetCageInfo(Convert.ToInt32(partViewModel.ManufacturerId)).FirstOrDefault();

                if (cageInfo != null)
                {
                    partViewModel.ManufacturerName = cageInfo.ManufacturerName;
                    partViewModel.CageCode         = model.GroupModelId;
                }

                return(View("AddParts", partViewModel));
            }
            else
            {
                TempData.Put("Message", new NotificationViewModel()
                {
                    Message = "Part not found.", MessageType = NotificationType.error
                });
            }
            return(View());
        }