public ActionResult Create(CreateTutorialViewModel model) { if (ModelState.IsValid && model.Archive != null && model.Archive.ContentLength > 0) { try { byte[] byteArray = null; using (var memory = new MemoryStream()) { model.Archive.InputStream.CopyTo(memory); byteArray = memory.GetBuffer(); } var fileName = string.Format(GlobalPatternConstants.VERSION_NAME, DateTime.Now.ToUniversalTime(), model.Archive.FileName); var fullPath = storage.UploadFile(byteArray, fileName, GlobalConstants.STORAGE_FOLDER); var userId = this.User.Identity.GetUserId(); var tutorial = new ThesisTutorial() { FilePath = fullPath, TeacherId = userId, FileName = fileName }; this.Data.ThesisTutorials.Add(tutorial); this.Data.SaveChanges(); } catch (Exception) { return View(model); } return RedirectToAction("Index", "Tutorial"); } return View(model); }
public ActionResult Create(CreateTutorialViewModel model) { if (ModelState.IsValid && model.Archive != null && model.Archive.ContentLength > 0) { try { byte[] byteArray = null; using (var memory = new MemoryStream()) { model.Archive.InputStream.CopyTo(memory); byteArray = memory.GetBuffer(); } var fileName = string.Format(GlobalPatternConstants.VERSION_NAME, DateTime.Now.ToUniversalTime(), model.Archive.FileName); var fullPath = storage.UploadFile(byteArray, fileName, GlobalConstants.STORAGE_FOLDER); var userId = this.User.Identity.GetUserId(); var tutorial = new ThesisTutorial() { FilePath = fullPath, TeacherId = userId, FileName = fileName }; this.Data.ThesisTutorials.Add(tutorial); this.Data.SaveChanges(); } catch (Exception) { return(View(model)); } return(RedirectToAction("Index", "Tutorial")); } return(View(model)); }