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)); }
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()); }