Exemple #1
0
        public async Task <IActionResult> AddEditProductManual(int id)
        {
            ProductMenualViewModel model = new ProductMenualViewModel();

            if (id > 0)
            {
                ProductManual productManual = await _unitOfWork.Repository <ProductManual>().GetSingleIncludeAsync(p => p.Id == id, pro => pro.Product);

                model.ProductId   = productManual.ProductId;
                model.ProductName = productManual.Product.Name;
            }
            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> AddEditProductManual(int id, ProductMenualViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Something Wrong ");
                return(View(model));
            }
            if (id > 0)
            {
                ProductManual pManual = await _unitOfWork.Repository <ProductManual>().GetByIdAsync(id);

                pManual.ProductId    = model.ProductId;
                pManual.ModifiedDate = DateTime.Now;
            }
            else
            {
                ProductManual productManual = new ProductManual
                {
                    AddedDate    = DateTime.Now,
                    ProductId    = model.ProductId,
                    ModifiedDate = DateTime.Now
                };

                if (model.ProductFile != null && model.ProductFile.ContentType == "application/pdf")
                {
                    var uploads  = Path.Combine(_hostingEnv.WebRootPath, "uploads/ProductManuals");
                    var fileName = Path.Combine(uploads, model.ProductName + "_" + model.ProductId + ".pdf");
                    productManual.ManualName = Path.GetFileName(fileName);
                    await _unitOfWork.Repository <ProductManual>().InsertAsync(productManual);

                    using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                    {
                        await model.ProductFile.CopyToAsync(fileStream);
                    }

                    //await model.ImageFile.CopyToAsync(new FileStream(fileName,FileMode.Create));
                }
                else
                {
                    ModelState.AddModelError("", "Wrong file Type. Please Upload only PDF file");
                }
            }

            return(View());
        }
Exemple #3
0
        public async Task UploadProductManual(IFormFile file, int productId, string productName)
        {
            var pManual = new ProductManual
            {
                AddedDate    = DateTime.Now,
                ModifiedDate = DateTime.Now,
                ProductId    = productId
            };

            if (file != null && file.ContentType == "application/pdf")
            {
                var uploads  = Path.Combine(_hosingEnv.WebRootPath, "uploads/ProductManuals");
                var fileName = Path.Combine(uploads, productName + "_" + productId + ".pdf");
                pManual.ManualName = Path.GetFileName(fileName);
                await _unitOfWork.Repository <ProductManual>().InsertAsync(pManual);

                using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }

                //await model.ImageFile.CopyToAsync(new FileStream(fileName,FileMode.Create));
            }
        }