public ActionResult New(NewsNew newsNew, HttpPostedFileBase image, int?ID) { if (Database.Session.Query <News>().Any(x => (x.SeoLink.Equals(newsNew.SeoLink)) && (x.ID != ID))) { ModelState.AddModelError("", "SeoLink adı kullanılıyor"); } if (!ModelState.IsValid) { return(View(newsNew)); } News news = new News { Title = newsNew.Title, Body = newsNew.Body, Summary = newsNew.Summary, SeoLink = newsNew.SeoLink, CategoryID = newsNew.CategoryID, CoverPhoto = FileUpload.FileName(image, FileUpload.UploadFolder.News) }; if (ID == null) { Database.Session.Save(news); } else { news.ID = (int)ID; Database.Session.Update(news); } return(RedirectToAction("Index")); }
public bool InsertProd(NewsNew news_new) { try { return(this.News_dal.Insert(news_new)); } catch (Exception ex) { throw new Exception($"NewsService:{ex.Message}"); } }
public bool UpdateProd(NewsNew news_new) { try { return(this.News_dal.Update(news_new)); } catch (Exception ex) { return(false); } }
/// <summary> /// 取得產品細節 /// </summary> /// <param name="num"></param> /// <returns></returns> public NewsNew GetProductDetail(int num) { NewsNew result = null; try { return(this.News_dal.Get(num)); } catch (Exception ex) { return(result); } }
public bool Update(NewsNew product) { { Func <bool> func = new Func <bool>(() => { _entity.Entry(product).State = EntityState.Modified; _entity.SaveChanges(); return(true); }); return(_adapter.Catch <bool>(func)); } }
public bool Delete(NewsNew product) { { Func <bool> func = new Func <bool>(() => { var product_new = _entity.NewsNew.Where(e => e.Num == product.Num).FirstOrDefault(); _entity.NewsNew.Remove(product); _entity.SaveChanges(); return(true); }); return(_adapter.Catch <bool>(func)); } }
public ActionResult ShowNews(string seo_link) { News news = Database.Session.Query <News>().SingleOrDefault(x => x.SeoLink.Equals(seo_link)); if (news != null) { NewsNew newsNew = new NewsNew { Title = news.Title, Body = news.Body, Summary = news.Summary, SeoLink = news.SeoLink, CoverPhoto = news.CoverPhoto, CategoryID = news.CategoryID }; return(View(newsNew)); } return(RedirectToRoute("Home")); }
public ActionResult New(int?ID) { if (ID != null) { News news = Database.Session.Get <News>(ID); if (news != null) { NewsNew newsNew = new NewsNew { Title = news.Title, Body = news.Body, Summary = news.Summary, SeoLink = news.SeoLink, CategoryID = news.CategoryID }; return(View(newsNew)); } } return(View(new NewsNew())); }