public async Task <IActionResult> Edit(int id, [Bind("PageNumber,ServerPath,PageBaseId,Id")] GoldenTip goldenTip) { if (id != goldenTip.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(goldenTip); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoldenTipExists(goldenTip.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(goldenTip)); }
public IActionResult UploadEditGoldenTips(string pageBaseId, int id, int goldenTipsPageNumber) { Guid PageBaseId = Guid.Parse(pageBaseId); string message = ""; bool result = false; try { long size = 0; var files = Request.Form.Files; string ServerPath = ""; foreach (var file in files) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var editfilename = filename.Replace("zip", "htm"); ServerPath = "/pagegoldentips/" + editfilename; filename = _webHostEnvironment.WebRootPath + "\\pagegoldentips" + $@"\{filename}"; var filePath = _webHostEnvironment.WebRootPath + "\\pagegoldentips"; size += file.Length; string startPath = filePath; string zipPath = filePath + "\\" + file.FileName; string extractPath = filePath; using (FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); } ZipFile.ExtractToDirectory(zipPath, extractPath, true); } GoldenTip gT = _context.GoldenTips.Where(C => C.Id == id).FirstOrDefault(); gT.ServerPath = ServerPath; _context.GoldenTips.Update(gT); _context.SaveChanges(); result = true; } catch (Exception) { message = "عملیات ذخیره با شکست روبرو شد"; result = false; } return(Json(new { result = result, message = message })); }
public async Task <IActionResult> Create([Bind("PageNumber,ServerPath,PageBaseId,Id")] GoldenTip goldenTip) { if (ModelState.IsValid) { _context.Add(goldenTip); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(goldenTip)); }