public List <Posted> Search(string name) { List <Posted> ls = new List <Posted>(); var list = db.Posts.Where(x => x.title.Contains(name) || name == null).ToList(); foreach (var item in list) { var posted = new Posted() { Content = item.content, id = item.id, Title = item.title }; ls.Add(posted); } return(ls); }
public List <Posted> GetPosts() { List <Posted> ls = new List <Posted>(); var list = db.Posts.ToList(); foreach (var item in list) { var posted = new Posted() { Content = item.content, id = item.id, Title = item.title }; ls.Add(posted); } return(ls); }