public IActionResult Create(ProductGroup productGroup) { if (!ModelState.IsValid) { return(View()); } kavanContext.ProductGroups.Add(productGroup); kavanContext.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CreateImage(ProductImage productImage, IFormFile upload) { if (ModelState.IsValid) { if (upload != null && upload.Length > 0) { string ImageName = System.IO.Path.GetFileName(upload.FileName); string ImageText = Path.GetExtension(upload.FileName); if (ImageText == ".png" || ImageText == ".jpg") { string physicalPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", ImageName); using (var stream = new FileStream(Path.Combine("wwwroot/image", ImageName), FileMode.Create)) { upload.CopyTo(stream); } } var entity = new ProductImage { FileId = Guid.NewGuid().ToString().Replace("-", ""), FileName = System.IO.Path.GetFileName(upload.FileName), ProductId = productImage.ProductId, }; using (var ms = new MemoryStream()) { upload.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); } kavanContext.ProductImages.Add(entity); kavanContext.SaveChanges(); } return(RedirectToAction("index")); } return(View()); }