public IEnumerable <PromotionAdminView> Gets() { try { List <PromotionAdminView> promotions = new List <PromotionAdminView>(); var _lst = from p in DbContext.Promotions from v in DbContext.Staffs where p.EndDate >= DateTime.Now && p.Staff == v.ID && p.Status == true select new { ID = p.ID, Title = p.Title, Avatar = p.Avatar, Desc = p.Desc, Content = p.Content, StartDate = p.StartDate, EndDate = p.EndDate, Type = p.Type, Code = p.Code, Staff = v.Name }; if (_lst != null && _lst.Count() > 0) { foreach (var item in _lst) { PromotionAdminView promotion = new PromotionAdminView(); promotion.Avatar = item.Avatar; promotion.Content = item.Content; promotion.Desc = item.Desc; promotion.EndDate = item.EndDate; promotion.ID = item.ID; promotion.StartDate = item.StartDate; promotion.Title = item.Title; promotion.Type = item.Type; promotion.Code = item.Code; promotion.Staff = item.Staff; promotions.Add(promotion); } return(promotions); } return(null); } catch (System.Exception) { return(null); } }
public PromotionAdminView GetDetail(long id) { try { var _item = (from p in DbContext.Promotions from v in DbContext.Staffs where p.EndDate >= DateTime.Now && p.Staff == v.ID && p.Status == true && p.ID == id select new { ID = p.ID, Title = p.Title, Avatar = p.Avatar, Desc = p.Desc, Content = p.Content, StartDate = p.StartDate, EndDate = p.EndDate, Type = p.Type, Code = p.Code, Staff = v.Name }).FirstOrDefault(); if (_item != null && _item.ID != 0) { PromotionAdminView promotion = new PromotionAdminView(); promotion.Avatar = _item.Avatar; promotion.Content = _item.Content; promotion.Desc = _item.Desc; promotion.EndDate = _item.EndDate; promotion.ID = _item.ID; promotion.StartDate = _item.StartDate; promotion.Title = _item.Title; promotion.Type = _item.Type; promotion.Code = _item.Code; promotion.Staff = _item.Staff; return(promotion); } return(null); } catch (System.Exception) { return(null); } }