public void gvCategories_UpdateItem(int id) { var context = new NewsSiteDbContext(); Category item = context.Categories.Find(id); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } var editTextBox = this.gvCategories.Rows[this.gvCategories.EditIndex].Controls[0].Controls[0] as TextBox; if (editTextBox != null) { item.Name = editTextBox.Text; } TryUpdateModel(item); if (ModelState.IsValid) { context.SaveChanges(); } }
public UserController(UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, NewsSiteDbContext newsSiteDbContext) { this.userManager = userManager; this.signInManager = signInManager; this.newsSiteDbContext = newsSiteDbContext; newsSiteDbContext.Database.EnsureCreatedAsync(); }
public DataAccessAdapter(IConnStringWrapper connStr) { if (connStr == null) { throw new NullReferenceException("IConnStringWrapper must be initialized"); } _dbContext = new NewsSiteDbContext(connStr.ConnectionName); }
public IQueryable<Category> gvCategories_GetData() { var context = new NewsSiteDbContext(); var categories = context.Categories.OrderBy(c => c.Name); return categories; }
public IQueryable<Category> lvCategories_GetData() { var context = new NewsSiteDbContext(); var categories = context.Categories; return categories; }
protected void btnInsert_Click(object sender, EventArgs e) { var categoryName = this.tbInsertCategory.Text; var categoryToInsert = new Category() { Name = categoryName }; var context = new NewsSiteDbContext(); context.Categories.Add(categoryToInsert); context.SaveChanges(); }
public IEnumerable<Article> repeaterArticle_GetData() { var context = new NewsSiteDbContext(); var articlesByLikes = context.Articles .OrderByDescending(a => a.Likes) .Take(3) .ToList(); return articlesByLikes; }
public void lvArticles_DeleteItem(int id) { var context = new NewsSiteDbContext(); var article = context.Articles.Find(id); if (article != null) { context.Articles.Remove(article); context.SaveChanges(); } }
public IEnumerable<Article> lvCategoryArticles_GetData(string categoryName) { var context = new NewsSiteDbContext(); var articlesByDate = context.Articles .Where(a => a.Category.Name == categoryName) .OrderByDescending(a => a.DateCreated) .Take(3) .ToList(); return articlesByDate; }
public Article fvArticle_GetData([QueryString]string id) { var context = new NewsSiteDbContext(); var queryId = int.Parse(id); if (queryId != 0) { return context.Articles.Find(queryId); } else { return null; } }
public IQueryable<Article> lvArticles_GetData([QueryString]string orderBy) { var context = new NewsSiteDbContext(); var articles = context.Articles; if (string.IsNullOrEmpty(orderBy)) { articles.OrderByDescending(a => a.Likes); } else { articles.OrderBy(orderBy + " Ascending"); } return articles; }
public void lvArticles_UpdateItem(int id) { var context = new NewsSiteDbContext(); var item = context.Articles.Find(id); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); if (ModelState.IsValid) { context.SaveChanges(); } }
public void gvCategories_DeleteItem(int id) { var context = new NewsSiteDbContext(); var category = context.Categories.Find(id); if (category != null) { var articles = category.Articles.ToList(); for (int i = 0; i < articles.Count; i++) { context.Articles.Remove(articles[i]); } context.Categories.Remove(category); } context.SaveChanges(); }
public void lvArticles_InsertItem() { var context = new NewsSiteDbContext(); var item = new Article(); TryUpdateModel(item); var authorId = Page.User.Identity.GetUserId(); item.AuthorId = authorId; item.DateCreated = DateTime.Now; item.Likes = 0; if (ModelState.IsValid) { context.Articles.Add(item); context.SaveChanges(); } }
public News() { this.db = new NewsSiteDbContext(); }
public ArticleDetails() { this.db = new NewsSiteDbContext(); }
public EFTextFieldRepository(NewsSiteDbContext context) { _context = context; }
public EFNewsItemRepository(NewsSiteDbContext context) { _context = context; }
public Like() { this.db = new NewsSiteDbContext(); }
public Categories() { this.db = new NewsSiteDbContext(); }