public static List<MyBlog.Models.Blog> SelectAll() { using (MyBlogEntities entities = new MyBlogEntities()) { return entities.Blogs.Select(e => new MyBlog.Models.Blog() { Title = e.Title, Description = e.Description, BlogId = e.BlogID, CreationDate = e.TStamp}).OrderByDescending(e => e.CreationDate).ToList(); } }
public ActionResult Index() { using (var c = new MyBlogEntities()) { } return Redirect("/Login"); }
public static bool CheckExists(string title) { bool result = false; using (MyBlogEntities entities = new MyBlogEntities()) { if (entities.Blogs.Where(e => e.Title.ToLower().Equals(title)).Select(e => e).Count() > 0) { result = true; } } return result; }
public static void DeleteBlog(int blogId) { using (MyBlogEntities entities = new MyBlogEntities()) { try { entities.Blogs.Remove(entities.Blogs.Where(e => e.BlogID == blogId).Select(e => e).First()); entities.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public static void InsertBlog(Blog blog) { using (MyBlogEntities entities = new MyBlogEntities()) { entities.Blogs.Add(blog); try { entities.SaveChanges(); } catch (Exception ex) { throw ex; } } }
public ActionResult Index(int? id) { using (var c = new MyBlog.Data.MyBlogEntities()) { id = Int32.Parse(Request.Cookies["UserId"].Value); User user = c.Users.Where(u => u.Id == id).Single(); UserInfo userInfo = new UserInfo { Email = user.Email, City = user.City, Country = user.Country.Value.ToString(), Icq = user.Icq, Phone = user.Phone, Sex = UserInfo.GetSex(user.Sex.Value), Skype = user.Skype }; return View("Index", userInfo); } }