public ActionResult 消息(int page = 1) { MotaiDataEntities db = new MotaiDataEntities(); int cpage = page < 1 ? 1 : page; //資料庫讀取 tPromotions 為資料庫名稱 var promotion = db.tPromotions.OrderByDescending(c => c.PromotionId).ToList(); //開新List 取值 List <news> reslsit = new List <news>(); foreach (var items in promotion) { //實體化 class news res = new news(); NewPromotionViewModel npv = new NewPromotionViewModel(); //Prom 讀取入get set npv.sPromotinoCategory = items.tPromotionCategory.PromtionCategory; npv.PromotionDescription = items.PromotionDescription; npv.pADimage = items.pADimage; npv.pPromotionWeb = items.pPromotionWeb; npv.pPromotionPostDate = items.pPromotionPostDate; res.newPrmotion = npv; reslsit.Add(res); } var result = reslsit.ToPagedList(cpage, pageSize); return(View(result)); }
public ActionResult 消息(int page = 1) { MotaiDataEntities db = new MotaiDataEntities(); if (Session[CSession關鍵字.SK_LOGINED_CUSTOMER] != null) { tCustomer cust = Session[CSession關鍵字.SK_LOGINED_CUSTOMER] as tCustomer; int count = db.tStatus.Where(c => c.sCustomerId == cust.CustomerId).ToList().Count; ViewBag.Count = count + "項"; } int cpage = page < 1 ? 1 : page; //資料庫讀取 tPromotions 為資料庫名稱 var promotion = db.tPromotions.OrderByDescending(c => c.PromotionId).ToList(); //開新List 取值 List <news> reslsit = new List <news>(); foreach (var items in promotion) { //實體化 class news res = new news(); NewPromotionViewModel npv = new NewPromotionViewModel(); //Prom 讀取入get set npv.sPromotinoCategory = items.tPromotionCategory.PromtionCategory; //npv.PromotionDescription = items.PromotionDescription; if (items.PromotionDescription.Length > 10) { npv.PromotionDescription = items.PromotionDescription.Substring(0, 10) + "..."; } else { npv.PromotionDescription = items.PromotionDescription; } npv.PromotionName = items.PromotionName; npv.pADimage = items.pADimage; npv.pPromotionPostDate = items.pPromotionPostDate; npv.PromotionId = items.PromotionId; res.newPromotion = npv; reslsit.Add(res); } var result = reslsit.ToPagedList(cpage, pageSize); return(View(result)); }
public ActionResult New() { var model = new NewPromotionViewModel(ControllersEnum.Home); return(View(model)); }