PDA

View Full Version : سوال: نمایش اخبار مربوط به یک دسته خاص



haamidd
جمعه 08 آبان 1394, 00:11 صبح
public class BaseEntity
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity )]
public long Id { get; set; }
public DateTime InsertTime { get; set; }
public DateTime? UpdateTime { get; set; }
[DefaultValue(false)]
public bool Delete { get; set; }
public DateTime? DeleteTime { get; set; }
}


public class News : BaseEntity
{
//public News()
//{
// this.Categories = new List<Category>();
//}
public string Title { get; set; }
public string HeadTitle { get; set; }
public string Description { get; set; }
public string Content { get; set; }
public string Image { get; set; }
[DefaultValue(0)]
public long Visit { get; set; }
[DefaultValue(0)]
public int Like { get; set; }
[DefaultValue(0)]
public int Dislike { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
public virtual User Users { get; set; }
}

public class Category : BaseEntity
{
[Required]
public string Title { get; set; }
public int? ParentID { get; set; }
public string Image { get; set; }
[Index(IsClustered = false, IsUnique = true, Order = -1)]
public int Order { get; set; }
[DefaultValue(false)]
public bool ShowInSidebar { get; set; }
public virtual ICollection<News> News { get; set; }


}





کد کلاس اخبار =======> در اینجا خطا میده





public List<Domain.News> GetByCategory(Domain.Category category)
{
return DB.News.Where(Current => Current.Categories.Equals(category)).OrderByDescen ding(Current => Current.Id).Take(Setting.GetAll().CountNewsInSideb ar).ToList();
}



136344
لطفا راهنمایی کنید این select رو چطوری بزنم






کد PartialView پوسته


@{
Mosque.Models.Repository.Category category = new Mosque.Models.Repository.Category();
Mosque.Models.Repository.News news = new Mosque.Models.Repository.News();
}
<div class="box_right">
<!-- jquery - tab -->
<table border="0" cellpadding="0" cellspacing="0" class="pageme">
@{
int TitleColor = 0;
foreach (var itemCategory in category.GetShowInSidebar())
{
TitleColor++;
<tr>
<td>
<div class="title_more0" style="background:url(img/img_01-@(TitleColor).jpg)"><b>آخرین اخبار @itemCategory.Title</b></div>
<div class="pad">


<ul class="box_news_i">
@{
foreach (var itemNews in news.GetByCategory(itemCategory))
{
<li>
<img src="@itemNews.Image" width="60" height="45" />
@(itemNews.Description.Substring(0,20))...
</li>
}
}


</ul>


</div>
</td>
</tr>
}
}
</table>
<div class="pager"></div>
<div class="cls"></div>
<!-- jquery - tab-end -->
<div class="title_more"><b>مروری بر اخبار روز</b></div>
<div class="pad">


<ul class="box_news_i">
<li>
<img src="~/Content/Images/DefaultSkinImages/n00134155-s.jpg" width="60" />
متاسفانه با پیگیری کمیته حمایت از انقلاب اسلامی مردم فلسطین زیر ...
</li>


<li>
<img src="~/Content/Images/DefaultSkinImages/n00134155-s.jpg" width="60" />
متاسفانه با پیگیری کمیته حمایت از انقلاب اسلامی مردم فلسطین زیر ...
</li>


<li>
<img src="~/Content/Images/DefaultSkinImages/n00134155-s.jpg" width="60" />
متاسفانه با پیگیری کمیته حمایت از انقلاب اسلامی مردم فلسطین زیر ...
</li>
</ul>
</div>
<div class="title_more"><b>مروری بر اخبار روز</b></div>
<div class="pad">
<ul class="link_box1">
<li><a href="/"> واكنش صادق طباطبایی به خبر كشف پیكر امام موسی صدر </a></li>
<li><a href="/"> ایان حبس ۷۰ ساله اسناد اشغال ایران از سوی متفقین </a></li>
<li><a href="/"> عکسی از دیدار مصباح‌یزدی با آیت‌الله بهجت </a></li>
<li><a href="/"> تهدید مسعود فراستی از سوی یک سینماگر: با ماشین از رویت رد می‌شوم </a></li>
<li><a href="/"> پست جدید مدیرعامل سابق فارس در سپاه </a></li>
<li><a href="/"> عکسی از دیدار مصباح‌یزدی با آیت‌الله بهجت </a></li>
<li><a href="/"> علی مطهری: اظهارات احمدی‌نژاد مرا یاد خاتمی انداخت </a></li>
</ul>


</div>
</div>