public ActionResult TermekUj(TermekAdatlap model, HttpPostedFileBase file) { try { model.RouteNev = script.RouteNev(model.Tipus); if (file != null && file.ContentLength > 0 && file.ContentType == "image/jpg" || file.ContentType == "image/jpeg") { string fileName = script.FileNev(Path.GetFileName(file.FileName)); var path = Path.Combine(Server.MapPath("~/Content/Termekek"), fileName); file.SaveAs(path); model.Kep = fileName; unitOfWork.TermekAdatlapRepository.Insert(model); unitOfWork.Save(); return RedirectToAction("Termek"); } } catch (DataException) { ModelState.AddModelError(string.Empty,"Nem sikerült a mentés"); } return View(model); }
public ActionResult TermekEdit(TermekAdatlap model) { try { model.TermekKategoriaId = Convert.ToInt32(model.TermekKategoriaId); model.TermekMarkaId = Convert.ToInt32(model.TermekMarkaId); if (ModelState.IsValid) { unitOfWork.TermekAdatlapRepository.Update(model); unitOfWork.Save(); return RedirectToAction("Termek"); } } catch (DataException) { ModelState.AddModelError(string.Empty, "Nem sikerült a mentés"); } return View(model); }