public async Task <IActionResult> Edit(int id, [Bind("id,ProductId,ProductImageId")] PrelPIs prelPIs) { if (id != prelPIs.id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(prelPIs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PrelPIsExists(prelPIs.id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(prelPIs)); }
public async Task <IActionResult> Create([Bind("id,ProductId,ProductImageId")] PrelPIs prelPIs) { if (ModelState.IsValid) { _context.Add(prelPIs); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(prelPIs)); }
private JsonResult FileUploadAndBound(int PID) { bool isSavedSuccessfully = true; string fName = ""; foreach (var file in files) { try { fName = file.FileName; if (file != null && file.Length > 0) { var originalDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", fName); using (var stream = new FileStream(originalDirectory, FileMode.Create)) { file.CopyTo(stream); } } ProductImagess entity = new ProductImagess() { image_url = "/upload/" + file.FileName, name = file.FileName.Split(".")[0], seo_url = Tools.toSlug(file.FileName.Split(".")[0]), is_active = true, is_delete = false, c_date = DateTime.Now, desc = file.FileName.Split(".")[0] }; _context.Add(entity); _context.SaveChanges(); var temp = new PrelPIs() { ProductId = PID, ProductImageId = entity.id }; _context.Add(temp); _context.SaveChanges(); } catch (Exception ex) { isSavedSuccessfully = false; } } if (isSavedSuccessfully) { return(Json(new { Message = fName })); } else { return(Json(new { Message = "Error in saving file" })); } }