public ActionResult Create(string topic) { Download download = new Download(); download.Topic = topic; return View(download); }
public ActionResult Create(Download download, HttpPostedFileBase file) { if (ModelState.IsValid) { string fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath(_documentPath), fileName)); download.FileName = fileName; UpdateModel<Download>(download); _downloadRepository.Add(download); UnitOfWork.Save(); return RedirectToAction("Index", "Download"); } return View(download); }
public ActionResult Edit(int id, Download download, HttpPostedFileBase file) { var formInDb = _downloadRepository.GetById(id); if (file != null) { string fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath(_documentPath), fileName)); formInDb.FileName = fileName; } if (TryUpdateModel(formInDb)) { UnitOfWork.Save(); return RedirectToAction("Index", "Download"); } return View(download); }