public ActionResult Create(string topic) { Bio bio = new Bio(); bio.Topic = topic; IEnumerable<Category> categories = _categoryRepository.FindByType("bio"); ViewData["categories"] = new SelectList(categories, "ID", "Name", categories.FirstOrDefault()); return View(bio); }
public ActionResult Create(Bio bio, int categoryId, HttpPostedFileBase file) { if (ModelState.IsValid) { string fileName = "no_image.gif"; if (file != null) { fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath(_bioImagePath), fileName)); } bio.Category = _categoryRepository.GetById(categoryId); bio.ImageName = fileName; UpdateModel<Bio>(bio); _bioRepository.Add(bio); UnitOfWork.Save(); return RedirectToAction("Index", "Bio"); // action = BoardAndStaff } return View(bio); }
public ActionResult Edit(int id, Bio bio, int categoryId, HttpPostedFileBase file) { var BioInDb = _bioRepository.GetById(id); BioInDb.Category = _categoryRepository.GetById(categoryId); if (file != null) { string fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath(_bioImagePath), fileName)); BioInDb.ImageName = fileName; } if (TryUpdateModel(BioInDb)) { UnitOfWork.Save(); return RedirectToAction("Index", "Bio"); } return View(bio); }