예제 #1
0
        public FakeNorthwindDbContext()
        {
            AlphabeticalListOfProducts = new FakeDbSet <AlphabeticalListOfProduct>("ProductId", "ProductName", "Discontinued", "CategoryName");
            Categories                   = new FakeDbSet <Category>("CategoryId");
            CategorySalesFor1997         = new FakeDbSet <CategorySalesFor1997>("CategoryName");
            CurrentProductLists          = new FakeDbSet <CurrentProductList>("ProductId", "ProductName");
            Customers                    = new FakeDbSet <Customer>("CustomerId");
            CustomerAndSuppliersByCities = new FakeDbSet <CustomerAndSuppliersByCity>("CompanyName", "Relationship");
            CustomerDemographics         = new FakeDbSet <CustomerDemographic>("CustomerTypeId");
            Employees                    = new FakeDbSet <Employee>("EmployeeId");
            Invoices                   = new FakeDbSet <Invoice>("CustomerName", "Salesperson", "OrderId", "ShipperName", "ProductId", "ProductName", "UnitPrice", "Quantity", "Discount");
            Orders                     = new FakeDbSet <Order>("OrderId");
            OrderDetails               = new FakeDbSet <OrderDetail>("OrderId", "ProductId");
            OrderDetailsExtendeds      = new FakeDbSet <OrderDetailsExtended>("OrderId", "ProductId", "ProductName", "UnitPrice", "Quantity", "Discount");
            OrdersQries                = new FakeDbSet <OrdersQry>("OrderId", "CompanyName");
            OrderSubtotals             = new FakeDbSet <OrderSubtotal>("OrderId");
            Products                   = new FakeDbSet <Product>("ProductId");
            ProductsAboveAveragePrices = new FakeDbSet <ProductsAboveAveragePrice>("ProductName");
            ProductSalesFor1997        = new FakeDbSet <ProductSalesFor1997>("CategoryName", "ProductName");
            ProductsByCategories       = new FakeDbSet <ProductsByCategory>("CategoryName", "ProductName", "Discontinued");
            Regions                    = new FakeDbSet <Region>("RegionId");
            SalesByCategories          = new FakeDbSet <SalesByCategory>("CategoryId", "CategoryName", "ProductName");
            SalesTotalsByAmounts       = new FakeDbSet <SalesTotalsByAmount>("OrderId", "CompanyName");
            Shippers                   = new FakeDbSet <Shipper>("ShipperId");
            SummaryOfSalesByQuarters   = new FakeDbSet <SummaryOfSalesByQuarter>("OrderId");
            SummaryOfSalesByYears      = new FakeDbSet <SummaryOfSalesByYear>("OrderId");
            Suppliers                  = new FakeDbSet <Supplier>("SupplierId");
            Territories                = new FakeDbSet <Territory>("TerritoryId");

            InitializePartial();
        }
예제 #2
0
        public ActionResult Edit(Category category)
        {
            if (ModelState.IsValid)
            {
                Category entry = db.Entry(category).Entity;
                System.Data.Entity.DbSet <Category> dbset = db.Categories;
                //If we changed index, we need to shift other elements
                int oldIndex = dbset.First(x => x.Id == entry.Id).Index;

                shiftIndexes(entry, oldIndex, dbset);

                //Ugly workaround
                Category dbQ = dbset.First(x => x.Id == entry.Id);
                dbQ.Index            = entry.Index;
                dbQ.Annotation       = entry.Annotation;
                dbQ.Weight           = entry.Weight;
                dbQ.Title            = entry.Title;
                dbQ.ImageDisplayFlag = entry.ImageDisplayFlag;
                db.SaveChanges();

                //db.Entry(category).State = EntityState.Modified;
                //db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
        private IQueryable <T> GetEntitiesInternal <T>() where T : class
        {
            System.Data.Entity.DbSet <T> set = context.Set <T>();
            IQueryable <T> queryableSet      = !trackEntities?set.AsNoTracking() : set;

            return(new DataLocalizationQueryable <T>(queryableSet));
        }
예제 #4
0
        private static List <PersonaViewModel> GetListPersonaViewModel(System.Data.Entity.DbSet <Persona> personas)
        {
            var personasList = new List <PersonaViewModel>();

            foreach (var item in personas)
            {
                var personaVm = Map(item);
                personasList.Add(personaVm);
            }

            return(personasList);
        }
예제 #5
0
        private static List <DireccionViewModel> GetListDireccionesViewModel(System.Data.Entity.DbSet <Direccion> direcciones)
        {
            List <DireccionViewModel> direccionesList = new List <DireccionViewModel>();

            foreach (var item in direcciones)
            {
                var direccionVM = Map(item);

                direccionesList.Add(direccionVM);
            }
            return(direccionesList);
        }
 public CorretorOnline obterCorretor(System.Data.Entity.DbSet <TEntity> value, DbSet <CorretorOnline> listCorretores)
 {
     if (value.Cast <PinheiroSereni.Dominio.Entidades.Chat>().Count() > 0)
     {
         CorretorOnline ultimoCorretor = listCorretores.Find(value.Cast <PinheiroSereni.Dominio.Entidades.Chat>().OrderByDescending(m => m.chatId).First().corretorId);
         CorretorOnline proxCorretor   = listCorretores.Where(m => m.indexEscala > ultimoCorretor.indexEscala && m.situacao == "A").OrderBy(j => j.indexEscala).FirstOrDefault() ?? listCorretores.Where(m => m.situacao == "A").OrderBy(m => m.indexEscala).FirstOrDefault();
         return(proxCorretor);
     }
     else
     {
         return(listCorretores.Where(m => m.situacao == "A").OrderBy(m => m.indexEscala).FirstOrDefault());
     }
 }
예제 #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = db.Categories.Find(id);

            System.Data.Entity.DbSet <Category> dbset = db.Categories;
            int oldIndex = category.Index;

            category.Index = dbset.Count() + 100;

            shiftIndexes(category, oldIndex, dbset);

            db.Categories.Remove(category);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #8
0
        private void shiftIndexes(Category entry, int oldIndex, System.Data.Entity.DbSet <Category> dbset)
        {
            if (entry.Index - oldIndex == 1)
            {
                //Move forward by 1 step
                try
                {
                    dbset.First(x => x.Index == entry.Index).Index = oldIndex; //If was last row - it will throw an exception
                }
                catch (Exception e)
                { }
            }
            else if (entry.Index > oldIndex)
            {
                //We moved forward
                foreach (var q in dbset.ToList())
                {
                    if (oldIndex < q.Index && q.Index < entry.Index)
                    {
                        q.Index = q.Index - 1;
                    }
                }
                entry.Index = entry.Index - 1;
            }
            else if (entry.Index < oldIndex)
            {
                //We moved backwards
                foreach (var q in dbset.ToList())
                {
                    if (entry.Index <= q.Index && q.Index < oldIndex)
                    {
                        q.Index = q.Index + 1;
                    }
                }
            }

            if (entry.Index > dbset.Count())
            {
                entry.Index = dbset.Count();
            }
            else if (entry.Index < 1)
            {
                entry.Index = 1;
            }
        }
예제 #9
0
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                category.ImageDisplayFlag = true;

                category.RiskRanges = new List <RiskRange>();
                category.RiskRanges.Add(new RiskRange(1));
                category.RiskRanges.Add(new RiskRange(2));
                category.RiskRanges.Add(new RiskRange(3));
                db.Categories.Add(category);

                Category entry = db.Entry(category).Entity;
                System.Data.Entity.DbSet <Category> dbset = db.Categories;

                db.SaveChanges();
                return(RedirectToAction("Edit/" + category.Id));
            }

            return(View(category));
        }
예제 #10
0
        private TDestination GetMapping <TSource, TDestination>(TSource source, System.Data.Entity.DbSet <TDestination> destDbSet) where TDestination : MappableEntity, new() where TSource : IMappableDTO
        //private static TDestination GetMapping<TSource, TDestination>(TSource source, IEnumerable<TDestination> destDbSet) where TDestination : MappableEntity, new() where TSource : IMappableDTO
        {
            //return GetMapping<TSource, TDestination, TDestination>(source, destDbSet);
            TDestination dest = null;

            if (source?.MappingId != null)
            {
                //dest = destDbSet.SingleOrDefault(x => x.MappingId == source.MappingId);
                dest = destDbSet.Find(source.MappingId);
            }

            if (dest == null)
            {
                dest = new TDestination();
                //DbContext.SaveChanges();
                //destDbSet.Add(dest);
            }

            return(dest);
        }
 public Repository()
 {
     db    = new LibrarySystemContext();
     dbSet = db.Set <T>();
 }
예제 #12
0
 public GenericRepository(ADAContext context)
 {
     Context = context;
     Set     = context.Set <T>();
 }
 protected GenericController()
 {
     Database = new Context.UniOpetDbContext();
     _dbSet   = Database.Set <TEntity>();
 }
예제 #14
0
 private TDestination GetMapping <TSource, TDestination>(TSource source, TDestination dest, System.Data.Entity.DbSet <TDestination> destDbSet) where TDestination : MappableEntity where TSource : IMappableDTO
 //private static TDestination GetMapping<TSource, TDestination>(TSource source, TDestination dest, IEnumerable<TDestination> destDbSet) where TDestination : MappableEntity where TSource : IMappableDTO
 {
     if (dest == null || source.MappingId != dest.MappingId)
     {
         if (source?.MappingId != null)
         {
             //dest = destDbSet.SingleOrDefault(x => x.MappingId == source.MappingId);
             dest = destDbSet.Find(source.MappingId);
             return(dest);
         }
         else
         {
             return(null);
         }
     }
     return(dest);
 }
예제 #15
0
 public DataRepository(TxnFlowDBEntities dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = _dbContext.Set <TEntity>();
 }
예제 #16
0
 public Repository()
 {
     db    = new EventManagerSystemContext();
     dbSet = db.Set <T>();
 }
예제 #17
0
 public RepositoryBase()
 {
     _context = new EventsDataContext();
     _dbSet   = _context.Set <T>();
 }
예제 #18
0
 public Repository()
 {
     db    = new SchoolDBContext();
     dbSet = db.Set <T>();
 }
예제 #19
0
 public BaseDal()
 {
     _dbset = db.Context.Set <T>();
 }
예제 #20
0
 /// <summary>
 /// Aggregration Connection với data set
 /// </summary>
 /// <param name="context"></param>
 public GenericRepository(DbContext context)
 {
     _context   = context;
     _entitySet = context.Set <TEntity>();
 }
예제 #21
0
 public SQLRepository(DataContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <T>();
 }
예제 #22
0
 public RepositoryBase(IBaseContext context, IBulkWorker <TEntity> bulkWorker)
 {
     _bulkWorker  = bulkWorker;
     this.Context = context;
     this.DbSet   = context.Set <TEntity>();
 }
예제 #23
0
 public void Dispose()
 {
     DbSet = null;
     Context.Dispose();
     GC.SuppressFinalize(this);
 }
예제 #24
0
 public GenericResposity(QJModelContext dbContext)
 {
     this.dbContext = dbContext;
     this.entities  = dbContext.Set <TEntity>();
 }