Ejemplo n.º 1
0
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            var context = new NewsPortalContext();

            Seed(context);
        }
Ejemplo n.º 2
0
 protected void Button1_Click1(object sender, EventArgs e)
 {
     using (var context = new NewsPortalContext())
     {
         var users = context.Users.ToList();
         if (users.FirstOrDefault(x => x.Login == TextBox1.Text && x.Password == TextBox2.Text) != null)
         {
             Response.Redirect(ResolveUrl("index.aspx"));
         }
     }
 }
Ejemplo n.º 3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var context = new NewsPortalContext())
            {
                var users = context.Users.ToList();
                if (TextBox2.Text == TextBox3.Text)
                {
                    if (users.FirstOrDefault(x => x.Login == TextBox1.Text) == null)
                    {
                        context.Users.Add(new User()
                        {
                            Login    = TextBox1.Text,
                            Password = TextBox2.Text,
                            Email    = TextBox4.Text
                        });

                        context.SaveChanges();
                        Response.Redirect(ResolveUrl("login.aspx"));
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public NewsPortalUnitOfWork(NewsPortalContext context)
 {
     _context = context;
 }
Ejemplo n.º 5
0
        protected override void Seed(NewsPortalContext context)
        {
            // Add Users
            context.Users.AddOrUpdate(
                new User {
                Id = 1, Username = "******", Name = "Publisher 1", Password = "******", Role = Role.Publisher
            },
                new User {
                Id = 2, Username = "******", Name = "Publisher 2", Password = "******", Role = Role.Publisher
            },
                new User {
                Id = 3, Username = "******", Name = "Publisher 3", Password = "******", Role = Role.Publisher
            },
                new User {
                Id = 4, Username = "******", Name = "Publisher 4", Password = "******", Role = Role.Publisher
            },
                new User {
                Id = 5, Username = "******", Name = "Employee 1", Password = "******", Role = Role.Employee, Likes = 10
            },
                new User {
                Id = 6, Username = "******", Name = "Employee 2", Password = "******", Role = Role.Employee, Likes = 1
            },
                new User {
                Id = 7, Username = "******", Name = "Employee 3", Password = "******", Role = Role.Employee
            },
                new User {
                Id = 8, Username = "******", Name = "Employee 4", Password = "******", Role = Role.Employee
            }
                );
            context.SaveChanges();

            // Add Users
            context.Authors.AddOrUpdate(
                new Author {
                Id = 1, Name = "Author 1"
            },
                new Author {
                Id = 2, Name = "Author 2"
            },
                new Author {
                Id = 3, Name = "Author 3"
            }
                );
            context.SaveChanges();

            User   publisher = context.Users.First(u => u.Id == 1);
            Author author    = context.Authors.First(u => u.Id == 1);

            // Add Articles
            context.Articles.AddOrUpdate(
                new Article {
                Id = 1, Title = "News Article 1", Author = author, Publisher = publisher, Body = "This is a sample body for News Article 1", ArticleType = ArticleType.News, PublishDate = DateTime.Now, Likes = 10
            },
                new Article {
                Id = 2, Title = "News Article 2", Author = author, Publisher = publisher, Body = "This is a sample body for News Article 2", ArticleType = ArticleType.News, PublishDate = DateTime.Now
            },
                new Article {
                Id = 3, Title = "Technology Article 1", Author = author, Publisher = publisher, Body = "This is a sample body for Technology Article 1", ArticleType = ArticleType.Technology, PublishDate = DateTime.Now, Likes = 45
            }
                );
            context.SaveChanges();
        }
Ejemplo n.º 6
0
 public EfUnitOfWork()
 {
     _db = new NewsPortalContext();
 }
Ejemplo n.º 7
0
        public void Initilise()
        {
            INewsPortalContext context = new NewsPortalContext();

            _userRepository = new UserRepository(context);
        }
Ejemplo n.º 8
0
 public Repository(NewsPortalContext context)
 {
     _db = context;
 }
Ejemplo n.º 9
0
 public NewsPortalGenericRepository(NewsPortalContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }