public async Task <IActionResult> OnPostAddNewPhoto() { string newfileName = string.Empty; if (imgf != null && imgf.Length > 0) { string fn = imgf.FileName; if (IsImagValidate(fn)) { string extension = Path.GetExtension(fn); newfileName = Guid.NewGuid().ToString() + extension; string filename = Path.Combine(_host.WebRootPath + "/Img/", newfileName); await imgf.CopyToAsync(new FileStream(filename, FileMode.Create)); } else { return(Page()); } } TempProdImg v = new TempProdImg { ImgFile = newfileName }; _db.TempProdImg.Add(v); await _db.SaveChangesAsync(); return(Page()); }
public async Task <IActionResult> OnPost() { string newfileName = string.Empty; if (img != null && img.Length > 0) { string fn = img.FileName; if (IsImagValidate(fn)) { string extension = Path.GetExtension(fn); newfileName = Guid.NewGuid().ToString() + extension; string filename = Path.Combine(_host.WebRootPath + "/img/", newfileName); await img.CopyToAsync(new FileStream(filename, FileMode.Create)); } else { return(Page()); } } var ProductFromDB = await _db.ProdInfo.FirstOrDefaultAsync(m => m.Id == ProdInfo.Id); if (ProductFromDB == null) { return(NotFound()); } ProductFromDB.ProdCode = ProdInfo.ProdCode; ProductFromDB.ProdName = ProdInfo.ProdName; ProductFromDB.ProdCategory = ProdInfo.ProdCategory; ProductFromDB.ProdDescription = ProdInfo.ProdDescription; ProductFromDB.CreatedById = ProdInfo.CreatedById; // ProductFromDB.CreatedDateTime = ProdInfo.CreatedDateTime; // ProductFromDB.ImgFile = img.FileName.ToString(); // ProdInfo.ImgFile; ProductFromDB.CostPrice = ProdInfo.CostPrice; ProductFromDB.RetailPrice = ProdInfo.RetailPrice; ProductFromDB.WholePrice = ProdInfo.WholePrice; TempProdImg v = new TempProdImg { ImgFile = newfileName }; if (v.ImgFile != null) { _db.TempProdImg.Add(v); await _db.SaveChangesAsync(); } // ImgFile = newfileName; AddPhoto = await _db.TempProdImg.ToListAsync(); AddPhoto = await _db.TempProdImg.ToListAsync(); foreach (var item in AddPhoto) { var AddPhoto = new ProdImg { ImgFile = item.ImgFile, ProdId = ProdInfo.Id }; _db.ProdImg.Add(AddPhoto); ProductFromDB.ImgFile = AddPhoto.ImgFile; } _db.TempProdImg.RemoveRange(AddPhoto); await _db.SaveChangesAsync(); StatusMessage = "تم التعديل على المادة"; return(RedirectToPage("Index")); }