示例#1
0
 public void AddNews(string title, int cid, string content, string userId)
 {
     CategoryRepository cpository = new CategoryRepository();
     if (cpository.ExistedCategory(cid))
     {
         News n = Context.News.Create();
         n.Title = title;
         n.CategoryID = cid;
         n.Content = content;
         n.UserID = userId;
         n.PublishTime = DateTime.Now;
         Context.News.Add(n);
         Context.SaveChanges();
     }
     else
     {
         throw new NotFoundCategoryException();
     }
 }
示例#2
0
 public void EditNews(int nid, string title, int? cid = null, string conetnt = null)
 {
     if (!ExistedNews(nid))
     {
         throw new NotFoundNewsException();
     }
     CategoryRepository crepositroy = new CategoryRepository();
     if (cid != null && !crepositroy.ExistedCategory(cid.Value))
     {
         throw new NotFoundCategoryException();
     }
     News n = GetNewsById(nid);
     if (n != null)
     {
         n.Title = title ?? n.Title;
         n.CategoryID = cid ?? n.CategoryID;
         n.Content = conetnt ?? n.Content;
         Context.News.Attach(n);
         Context.SaveChanges();
     }
 }