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();
 }
示例#3
0
 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;
        }
示例#5
0
        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();
        }
示例#7
0
        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();
            }
        }
示例#9
0
        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;
            }            
        }
示例#11
0
        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;
        }
示例#12
0
        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();
        }
示例#14
0
        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();
            }
        }
示例#15
0
 public News()
 {
     this.db = new NewsSiteDbContext();
 }
示例#16
0
 public ArticleDetails()
 {
     this.db = new NewsSiteDbContext();
 }
示例#17
0
 public EFTextFieldRepository(NewsSiteDbContext context)
 {
     _context = context;
 }
 public EFNewsItemRepository(NewsSiteDbContext context)
 {
     _context = context;
 }
示例#19
0
 public Like()
 {
     this.db = new NewsSiteDbContext();
 }
示例#20
0
 public Categories()
 {
     this.db = new NewsSiteDbContext();
 }