示例#1
0
        public void GetDataTest_by_id()
        {
            var testGood     = TestGood();
            var controller   = new GoodsContext();
            var resultActual = controller.GetData(1).ToList();

            Assert.AreEqual(testGood[0].Id, resultActual[0].Id);
        }
        public void Test_PickSerialNumber()
        {
            string formatSerialNumber = null;
            bool   saveFailed;

            do
            {
                saveFailed = false;
                using (var context = new GoodsContext())
                {
                    try
                    {
                        var serialNumber = context.SerialNumbers.Where(s => s.Date == DateTime.Now.Date).SingleOrDefault();

                        if (serialNumber == null)
                        {
                            serialNumber = new SerialNumber()
                            {
                                Date = DateTime.Now.Date, SomethingCount = 1
                            };
                            context.SerialNumbers.Add(serialNumber);
                        }
                        else
                        {
                            serialNumber.SomethingCount += 1;
                        }

                        context.SaveChanges();

                        formatSerialNumber = String.Format("{0:MMdd}-{1:00}", serialNumber.Date, serialNumber.SomethingCount);
                    }
                    catch (DbUpdateConcurrencyException concurrencyException)
                    {
                        saveFailed = true;

                        //發生Concurrency update的問題,將memory中現有欄位值更新為資料庫的值
                        var entry = concurrencyException.Entries.Single();
                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());

                        // Waiting 1~99ms
                        Thread.Sleep(new Random(Guid.NewGuid().GetHashCode()).Next(1, 100));
                    }
                }
            } while (saveFailed);
        }
示例#3
0
 public BaseRepository(GoodsContext dbContext)
 {
     goodsContext = dbContext;
 }
 public ImportanceRepository(GoodsContext goodsContext) : base(goodsContext)
 {
 }
示例#5
0
 public LoginController(GoodsContext context)
 {
     _context = context;
 }
示例#6
0
 public GoodRepository(GoodsContext goodsContext) : base(goodsContext)
 {
 }
示例#7
0
 public BillRepository(GoodsContext goodsContext) : base(goodsContext)
 {
 }
示例#8
0
 public GoodRepository(GoodsContext context)
 {
     _context = context;
 }
示例#9
0
 public AccountRepository(GoodsContext db) : base(db)
 {
 }
示例#10
0
 public UserRepository(GoodsContext goodsContext) : base(goodsContext)
 {
 }
示例#11
0
 public UsersController(GoodsContext context)
 {
     _context = context;
 }
示例#12
0
 public ImagesController(GoodsContext context)
 {
     _context = context;
 }
示例#13
0
 public TypesController(GoodsContext context)
 {
     _context = context;
 }
        /*
         * /// <summary>
         *
         * public string ReturnUrl { get; set; }
         * public async Task OnGetAsync(string returnUrl = null)
         * {
         *  using (var context = new CategoriesContext())
         *  {
         *      ViewData["categories"] = await context.Categories.ToListAsync();
         *      ReturnUrl = returnUrl;
         *  }
         * }
         * /// </summary>
         */

        public Goods1Controller(GoodsContext context, ICategoryRepository categoryRepository, IWebHostEnvironment hostEnvironment)
        {
            _context            = context;
            _categoryRepository = categoryRepository;
            webHostEnvironment  = hostEnvironment;
        }
示例#15
0
 public CustomerService(ILifetimeScope container, IConfiguration configuration, ICacheService cacheService, GoodsContext goodsContext)
 {
     cacheService.InitCacheService(configuration.GetSection("modules:2:properties:RedisConnection").Value); //启动缓存客户端
     goodsContext.Database.EnsureCreated();                                                                 //自动迁移数据库
 }
示例#16
0
 public GoodsController(GoodsContext context)
 {
     db = context;
 }