Example #1
0
        public void GetDbContext_When_Called_Several_Times_Returns_DbContext_That_Was_Set_During_Init()
        {
            // Arrange
            DbContext         dbContext         = new Mock <DbContext>().Object;
            DbContextProvider dbContextProvider = new DbContextProvider(dbContext);

            // Act
            var dbContextReturned1 = dbContextProvider.GetDbContext(new LogModel());
            var dbContextReturned2 = dbContextProvider.GetDbContext(new LogModel());

            // Arrange
            Assert.AreEqual(dbContext, dbContextReturned1);
            Assert.AreEqual(dbContext, dbContextReturned2);
        }
 public static IEnumerable <DiscountCriteriaInfo> FetchByDiscountId(int discountId)
 {
     using (var db = DbContextProvider.GetDbContext())
     {
         foreach (var entity in db.DiscountCriteria.Where(x => x.DiscountId == discountId))
         {
             yield return(CreateInternal(entity));
         }
     }
 }
Example #3
0
        public void GetDbContext_When_Called_With_Null_LogModel_Returns_DbContext_That_Was_Set_During_Init()
        {
            // Arrange
            DbContext         dbContext         = new Mock <DbContext>().Object;
            DbContextProvider dbContextProvider = new DbContextProvider(dbContext);

            // Act
            var dbContextReturned = dbContextProvider.GetDbContext(null as LogModel);

            // Arrange
            Assert.AreEqual(dbContext, dbContextReturned);
        }
Example #4
0
    private TMongoDbContext GetDbContext()
    {
        // Multi-tenancy unaware entities should always use the host connection string
        if (!EntityHelper.IsMultiTenant <TEntity>())
        {
            using (CurrentTenant.Change(null))
            {
                return(DbContextProvider.GetDbContext());
            }
        }

        return(DbContextProvider.GetDbContext());
    }
Example #5
0
        public static ProductInfo Fetch(int id)
        {
            ProductInfo item = null;

            using (var db = DbContextProvider.GetDbContext())
            {
                var entity = db.Product.SingleOrDefault(x => x.Id == id);
                if (entity != null)
                {
                    item = CreateInternal(entity);
                }
            }
            return(item);
        }
Example #6
0
 public IEnumerable <MenuItemsDisplayModel> GetData(MenuRequestModel lm)
 {
     try
     {
         using (var db = DbContextProvider.GetDbContext().InReadContext())
         {
             var param = new Dapper.DynamicParameters();
             //param.Add("Id", lm.Id, System.Data.DbType.Int32, System.Data.ParameterDirection.Input);
             param.Add("Name", lm.Name, System.Data.DbType.String, System.Data.ParameterDirection.Input);
             var result = db.ExecProcWithResults <MenuItemsDisplayModel>("dbo.spFetchMenu", param);//.ToList().First();
             return(result);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message.ToString());
     }
     return(null);
 }
        /// <summary>
        /// Funkcija vraća popuste koji zadovoljavaju kriterije ovisno o vrsti i količini proizvoda
        /// </summary>
        /// <param name="productQuantites"></param>
        /// <returns></returns>
        public static IEnumerable <DiscountInfo> FetchApplicableDiscounts(ProductQuantity[] productQuantites)
        {
            if (productQuantites == null)
            {
                throw new ArgumentNullException("productQuantites");
            }

            using (var db = DbContextProvider.GetDbContext())
            {
                var query = db.Discount.AsQueryable();
                if (productQuantites.Length == 0)
                {
                    query = query.Where(x => x.DiscountCriteria.Count == 0);
                }
                else
                {
                    query = query.Where(x => x.DiscountCriteria.Count == 0 || x.DiscountCriteria.All(xx => productQuantites.Where(xxx => xxx.ProductId == xx.ProductId).Sum(xxx => xxx.Quantity) >= xx.Quantity));
                }
                foreach (var item in query)
                {
                    yield return(CreateInternal(item));
                }
            }
        }
 public TestControllerBase()
 {
     context = DbContextProvider.GetDbContext();
 }