Exemplo n.º 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)));
        }
        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());
            }
        }
        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());
        }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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)));
        }
Exemplo n.º 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)));
        }
        /// <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]);
        }
        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());
            }
        }