public IActionResult Edit(int?id)
        {
            ProductInformationViewModel model = new ProductInformationViewModel();

            //编辑界面
            if (id != null)
            {
                ProductInformation product = _productInformationService.GetProductById((int)id);
                model = new ProductInformationViewModel
                {
                    ProductId         = product.Id,
                    ProductCode       = product.ProductCode,
                    ProductName       = product.ProductName,
                    ProductStatusType = product.ProductStatus,
                    StockStatusType   = product.StockType,
                    ClassType         = product.Type,
                    Description       = product.Description,
                    BatchId           = product.BatchId
                };
            }
            PopulateClassDropDownList();
            PopulateProductStatusDropDownList();
            PopulateStockStatusDropDownList();
            PopulateBatchDropDownList();
            return(View(model));
        }
        /// <summary>
        /// 将照片保存到指定的路径中,并返回唯一的文件名
        /// </summary>
        /// <returns></returns>
        private List <string> ProcessUploadedFile(ProductInformationViewModel model)
        {
            var photoFileNameList = new List <string>();

            if (model.Photos.Count > 0)
            {
                foreach (var photo in model.Photos)
                {
                    string uniqueFileName = null;
                    //必须将图像上传到wwwroot中的images文件夹
                    //而要获取wwwroot文件夹的路径,我们需要注入 ASP.NET Core提供的HostingEnvironment服务
                    //通过HostingEnvironment服务去获取wwwroot文件夹的路径
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                    //为了确保文件名是唯一的,我们在文件名后附加一个新的GUID值和一个下划线

                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                    //因为使用了非托管资源,所以需要手动进行释放
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        //使用IFormFile接口提供的CopyTo()方法将文件复制到wwwroot/images文件夹
                        photo.CopyTo(fileStream);
                    }

                    photoFileNameList.Add(uniqueFileName);
                }
            }
            return(photoFileNameList);
        }
        /// <summary>
        /// 新增编辑界面
        /// </summary>
        /// <returns></returns>
        public IActionResult Create()
        {
            ProductInformationViewModel model = new ProductInformationViewModel();

            PopulateClassDropDownList();
            PopulateProductStatusDropDownList();
            PopulateStockStatusDropDownList();
            PopulateBatchDropDownList();
            return(View(model));
        }
        public frmProductInformation(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, int entityPrimaryKey,
                                     OperationMode operationMode, string title = "Product Master")
        {
            InitializeComponent();

            this.mdiChild     = mdiChild;
            vm                = new ProductInformationViewModel(userInformation, mdiChild, entityPrimaryKey, operationMode, title);
            this.DataContext  = vm;
            mdiChild.Closing += vm.CloseMethod;
            if (vm.CloseAction == null && mdiChild.IsNotNullOrEmpty())
            {
                vm.CloseAction = new Action(() => mdiChild.Close());
            }

            bll = new FeasibleReportAndCostSheet(userInformation);

            List <ProcessDesigner.Model.V_TABLE_DESCRIPTION> lstTableDescription = bll.GetTableColumnsSize("PRD_MAST");

            this.SetColumnLength <TextBox>(lstTableDescription);
        }
        public IActionResult EditSave(ProductInformationViewModel model)
        {
            if (ModelState.IsValid)
            {
                List <string> uniqueFileNameList = null;

                if (model.Photos != null && model.Photos.Count > 0)
                {
                    uniqueFileNameList = ProcessUploadedFile(model);
                }
                var details = new List <ProductDetail>();
                if (uniqueFileNameList != null)
                {
                    foreach (var uniqueFileName in uniqueFileNameList)
                    {
                        details.Add(new ProductDetail {
                            PhotoPath = uniqueFileName
                        });
                    }
                }
                ProductInformation product = new ProductInformation
                {
                    Id            = model.ProductId,
                    ProductCode   = model.ProductCode,
                    ProductName   = model.ProductName,
                    StockType     = model.StockStatusType,
                    ProductStatus = model.ProductStatusType,
                    Type          = model.ClassType,
                    BatchId       = model.BatchId,
                    Details       = details
                };

                _productInformationService.UpdateProduct(product);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemple #6
0
        public IActionResult ProductListData(int page, int limit)
        {
            List <ProductInformationViewModel> productList = new List <ProductInformationViewModel>();
            var productinfos = _productInformationService.GetList(page, limit);

            if (productinfos.Item1 != null && productinfos.Item1.Count > 0)
            {
                foreach (var product in productinfos.Item1)
                {
                    BatchInformation            batchInfo = _batchInformationService.GetBatchInfoById(product.BatchId);
                    ProductInformationViewModel vm        = new ProductInformationViewModel();
                    vm.Id                = product.Id;
                    vm.Code              = product.ProductCode;
                    vm.Name              = product.ProductName;
                    vm.StockStatusType   = product.StockType;
                    vm.ProductStatusType = product.ProductStatus;
                    vm.ClassType         = product.Type;
                    vm.BatchId           = product.BatchId;
                    vm.BatchName         = batchInfo != null ? batchInfo.Name : string.Empty;
                    productList.Add(vm);
                }
            }
            return(Json(new { code = 0, msg = "", count = productinfos.Item2, data = productList.ToArray() }));
        }