public ActionResult NewsAdd(NewsModel model, HttpPostedFileBase Photo) { if (Photo != null) { var fileName = Path.GetFileNameWithoutExtension(Photo.FileName); var extension = Path.GetExtension(Photo.FileName); var fileFullName = Guid.NewGuid() + fileName.Replace(" ", "").Replace(".", "") + extension; var path = Path.Combine(Server.MapPath("~/Content/images/haber"), fileFullName); Photo.SaveAs(path); News news = new News { Active = model.Active, Content = model.Content, Photo = "images/haber/" + fileFullName, Creator = model.Creator, Date = model.Date, Title = model.Title, SeoUrl = Change(model.Title) }; _newsService.Insert(news); _uow.SaveChanges(); } return RedirectToAction("ListNews"); }
// GET: Admin/News public ActionResult ListNews() { NewsModel _newsModel = new NewsModel(); _newsModel.NewsList = _newsService.GetAll().ToList(); return View(_newsModel); }
public ActionResult Edit(int id) { News news = _newsService.Find(id); NewsModel _newsModel = new NewsModel { Id = news.Id, Active = news.Active, Content = news.Content, Creator = news.Creator, Date = news.Date, Title = news.Title }; return View(_newsModel); }
public ActionResult NewsEdit(NewsModel model, HttpPostedFileBase Photo) { int id = int.Parse(Request.Form["hfId"]); News news = _newsService.Find(id); if (Photo != null) { var fileName = Path.GetFileNameWithoutExtension(Photo.FileName); var extension = Path.GetExtension(Photo.FileName); var fileFullName = Guid.NewGuid() + fileName.Replace(" ", "").Replace(".", "") + extension; var path = Path.Combine(Server.MapPath("~/Content/images/haber"), fileFullName); Photo.SaveAs(path); news.Photo = "images/haber/" + fileFullName; } news.Active = model.Active; news.Content = model.Content; news.Creator = model.Creator; news.Date = model.Date; news.Title = model.Title; news.SeoUrl = Change(model.Title); _newsService.Update(news); _uow.SaveChanges(); return RedirectToAction("ListNews"); }