public News getNews(int id) { using (var ctx = new Models.Model()) { Models.News n = ctx.news.FirstOrDefault(x => x.newsId == id); News n1 = new News(); n1.newsId = n.newsId; n1.title = n.title; n1.description = n.description; n1.datetime = n.datetime; n1.tag = n.tag; n1.newsCity = n.newsCity; n1.image = n.image; n1.imagedata = getImage(n.image); n1.author = new Author(); n1.author.authorId = n.author.authorId; n1.author.authorName = n.author.authorName; n1.author.authorImage = n.author.authorImage; n1.author.authorCity = n.author.authorCity; n1.author.imagedata = getImage(n.author.authorImage); return(n1); } }
public int addNews(News n) { using (var ctx = new Models.Model()) { Models.News n1 = new Models.News(); n1.title = n.title; n1.description = n.description; n1.datetime = DateTime.Now; n1.tag = n.tag; n1.newsCity = n.newsCity; n1.image = n.image; bool flag = uploadImage(n.imagedata, n.image); Models.Author a = ctx.authors.FirstOrDefault(x => x.authorId == n.author.authorId); n1.author = a; ctx.news.Add(n1); ctx.SaveChanges(); return(n1.newsId); } }
public News updateNews(News n) { using (var ctx = new Models.Model()) { Models.News n1 = ctx.news.FirstOrDefault(x => x.newsId == n.newsId); if (n.title != null) { n1.title = n.title; } if (n.description != null) { n1.description = n.description.ToString(); } n1.datetime = DateTime.Now; if (n.tag != null) { n1.tag = n.tag; } if (n.newsCity != null) { n1.newsCity = n.newsCity; } if (n.image != null) { n1.image = n.image; bool flag = uploadImage(n.imagedata, n.image); } ctx.SaveChanges(); return(n); } }