Esempio n. 1
0
        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"));
        }
Esempio n. 2
0
 public bool InsertProd(NewsNew news_new)
 {
     try
     {
         return(this.News_dal.Insert(news_new));
     }
     catch (Exception ex)
     {
         throw new Exception($"NewsService:{ex.Message}");
     }
 }
Esempio n. 3
0
 public bool UpdateProd(NewsNew news_new)
 {
     try
     {
         return(this.News_dal.Update(news_new));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 4
0
        /// <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);
            }
        }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
        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));
            }
        }
Esempio n. 7
0
        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"));
        }
Esempio n. 8
0
 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()));
 }