コード例 #1
0
        public IActionResult Index()
        {
            fruteriashopContext context = new fruteriashopContext();

            Repositories.Repository <Categorias> repos = new Repositories.Repository <Categorias>(context);
            return(View(repos.GetAll().OrderBy(x => x.Nombre)));
        }
コード例 #2
0
        public void DeleteFriendUsingGenericRepo()
        {
            using (var context = new PluralSightBookContext())
            {
                var initializer = new TestDbInitializer();
                initializer.Reseed(context);

                int friendCount = context.Friends.Count();
                var testUserId  = context.aspnet_Users.FirstOrDefault().UserId;

                var repo   = new Repositories.Repository <Friend>(context);
                var friend = new Friend()
                {
                    UserId = testUserId, EmailAddress = "*****@*****.**"
                };
                repo.Add(friend);
                repo.Save();

                // Hence always use the same context while saving and deleting the same object/entity
                // Fails because we're using a different object context
                //var repo2 = new Repositories.Repository<Friend>();
                var repo2 = new Repositories.Repository <Friend>(context);
                repo2.Remove(friend);
                repo2.Save();

                Assert.AreEqual(friendCount, context.Friends.Count());
            }
        }
コード例 #3
0
        public void DeleteFriendUsingGenericRepoAndIoC()
        {
            var context = _container.TryGetInstance<DbContext>() as PluralSightBookContext;
            var initializer = new TestDbInitializer();
            initializer.Reseed(context);

            int friendCount = context.Friends.Count();
            var testUserId = context.Users
                .FirstOrDefault(u => u.UserName == TestDbInitializer.TEST_USERNAME)
                .UserId;

            var repo = new Repositories.Repository<Friend>(context);
            var friend = new Friend()
            {
                UserId = testUserId,
                EmailAddress = "*****@*****.**"
            };
            repo.Add(friend);
            repo.Save();

            var anotherContext = _container.TryGetInstance<DbContext>() as PluralSightBookContext;
            var repo2 = new Repositories.Repository<Friend>(anotherContext);
            repo2.Remove(friend);
            repo2.Save();

            Assert.AreEqual(friendCount, context.Friends.Count());
        }
コード例 #4
0
 public MarcasServices()
 {
     using (sistem14_ropa_mexicanaContext context = new sistem14_ropa_mexicanaContext())
     {
         Repositories.Repository <MarcaAfiliada> repos = new Repositories.Repository <MarcaAfiliada>(context);
         marcaAfiliadas = repos.GetAll().OrderBy(x => x.Marca).ToList();
     }
 }
コード例 #5
0
 public CategoriasService()
 {
     using (fruteriashopContext context = new fruteriashopContext())
     {
         Repositories.Repository <Categorias> repos = new Repositories.Repository <Categorias>(context);
         Categorias = repos.GetAll().OrderBy(x => x.Nombre).ToList();
     }
 }
コード例 #6
0
        public IActionResult Index(string id)
        {
            celularesContext context = new celularesContext();

            Repositories.Repository repos = new Repositories.Repository();

            return(View(repos.GetAll().OrderBy(x => x.Id)));
        }
コード例 #7
0
        public IActionResult Index()
        {
            animalesContext context = new animalesContext();

            Repositories.Repository <Especies> repos = new Repositories.Repository <Especies>(context);

            return(View(repos.GetAll().OrderBy(x => x.Id)));
        }
コード例 #8
0
        /// <summary>
        /// Gets the specified repository for the <typeparamref name="TEntity"/>.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <returns>An instance of type inherited from <see cref="IRepository{TEntity}"/> interface.</returns>
        public Repositories.IRepository <TEntity> GetRepository <TEntity>() where TEntity : class, IEntity <Guid>
        {
            if (repositories == null)
            {
                repositories = new Dictionary <Type, object>();
            }

            var type = typeof(TEntity);

            if (!repositories.ContainsKey(type))
            {
                repositories[type] = new Repositories.Repository <TEntity>(_context);
            }

            return((Repositories.IRepository <TEntity>)repositories[type]);
        }
コード例 #9
0
        public void AddFriendUsingGenericRepo()
        {
            using (var context = new PluralSightBookContext())
            {
                var initializer = new TestDbInitializer();
                initializer.Reseed(context);

                int friendCount = context.Friends.Count();
                var testUserId  = context.aspnet_Users
                                  .FirstOrDefault(u => u.UserName == TestDbInitializer.TEST_USERNAME)
                                  .UserId;

                var repo = new Repositories.Repository <Friend>();
                repo.Add(new Friend()
                {
                    UserId = testUserId, EmailAddress = "*****@*****.**"
                });
                repo.Save();

                Assert.AreEqual(friendCount + 1, context.Friends.Count());
            }
        }