public async Task <IActionResult> Edit(CustomFilesCreateViewModel model) { if (model.file != null && model.file.Length > 0) { string fileName = String.Empty; string filePath = String.Empty; byte[] bytes; var fileExtension = "pdf"; fileName = String.Format("CustomFile_{0}.{1}", Guid.NewGuid().ToString(), fileExtension); filePath = Path.Combine(Path.Combine(_hostingEnvironment.ContentRootPath, "customfiles"), fileName); using (var ms = new MemoryStream()) { model.file.CopyTo(ms); bytes = ms.ToArray(); } await System.IO.File.WriteAllBytesAsync(filePath, bytes); model.is_active = model.isActive; model.path = filePath; var result = await CustomFiles.Update(_ctx, model); return(RedirectToAction(nameof(CustomFilesController.Index))); } else { ModelState.AddModelError(String.Empty, "File is required."); return(View(model)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(int id) { var item = await CustomFiles.GetItem(_ctx, id); var model = new CustomFilesCreateViewModel(); model.customfile_id = item.customfile_id; model.description = item.description; model.isActive = item.is_active ?? false; model.created_at = item.created_at; model.path = item.path; return(View(model)); }
public async Task <IActionResult> Create() { var model = new CustomFilesCreateViewModel(); return(View(model)); }