コード例 #1
0
        public ActionResult ChartData()
        {
            using (var context = new WaterContext())
            {
                var data = context.Stations.Select(s => new
                {
                    label = s.Name,
                    data = s.Samples.Take(50).Select(d => new
                    {
                        time = d.DateTime,
                        oxy = d.Oxygen
                    })
                }).ToList();

                /* Time in JavaScript is stored as milliseconds ellapsed since the Unix epoch */
                var epochTicks = new DateTime(1970, 1, 1).Ticks;

                var json = data.Select(s => new
                {
                    label = s.label,
                    data = s.data.Select(p => new double[]{
                        ((p.time.Ticks - epochTicks) / TimeSpan.TicksPerMillisecond),
                        (double)p.oxy
                    })
                });

                return Json(json, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #2
0
        public ActionResult ChartData()
        {
            using (var context = new WaterContext())
            {
                var data = context.Stations.Select(s => new
                {
                    label = s.Name,
                    data  = s.Samples.Take(50).Select(d => new
                    {
                        time = d.DateTime,
                        oxy  = d.Oxygen
                    })
                }).ToList();

                /* Time in JavaScript is stored as milliseconds ellapsed since the Unix epoch */
                var epochTicks = new DateTime(1970, 1, 1).Ticks;

                var json = data.Select(s => new
                {
                    label = s.label,
                    data  = s.data.Select(p => new double[] {
                        ((p.time.Ticks - epochTicks) / TimeSpan.TicksPerMillisecond),
                        (double)p.oxy
                    })
                });

                return(Json(json, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
 public ActionResult Test()
 {
     using (var context = new WaterContext())
     {
         var samples = context.Samples.Take(50).ToList();
         return View(samples);
     }
 }
コード例 #4
0
 public ActionResult Test()
 {
     using (var context = new WaterContext())
     {
         var samples = context.Samples.Take(50).ToList();
         return(View(samples));
     }
 }
コード例 #5
0
 public async Task <Customer> UpdateAsync(Customer updatedCustomer)
 {
     using (WaterContext waterContext = new WaterContext())
     {
         waterContext.Entry(updatedCustomer).State = EntityState.Modified;
         await waterContext.SaveChangesAsync();
     }
     return(updatedCustomer);
 }
コード例 #6
0
        public async Task DeleteAsync(int id)
        {
            using (WaterContext waterContext = new WaterContext())
            {
                var removableCustomer = await waterContext.Customers.FindAsync(id);

                waterContext.Entry(removableCustomer).State = EntityState.Deleted;
                await waterContext.SaveChangesAsync();
            }
        }
コード例 #7
0
        public async Task <Water> AddAsync(Water addedWater)
        {
            Water newWater = null;

            using (WaterContext waterContext = new WaterContext())
            {
                newWater = waterContext.Waters.Add(addedWater);
                await waterContext.SaveChangesAsync();
            }
            return(newWater);
        }
コード例 #8
0
        public async Task <Customer> AddAsync(Customer addedCustomer)
        {
            Customer newCustomer = null;

            using (WaterContext waterContext = new WaterContext()) // Вопрос: можем ли мы не использовать using? он нужен для безопасного выхода из подключения?
            {
                newCustomer = waterContext.Customers.Add(addedCustomer);
                await waterContext.SaveChangesAsync();
            }
            return(newCustomer);
        }
コード例 #9
0
        public async Task <IEnumerable <Customer> > GetAllAsync()
        {
            var allCustomers = new List <Customer>();

            using (WaterContext waterContext = new WaterContext())
            {
                allCustomers = await waterContext.Customers.ToListAsync();
            }
            return(allCustomers);
            // можно и так: return await waterContext.Customers.ToListAsync();
        }
コード例 #10
0
        public void PropagateTest()
        {
            var propagator = new Propagator(Propagator.DefaultNeighborsGetter);
            var context    = new WaterContext(_map, propagator);
            var drop       = new WaterDrop(0.1);

            context.AddDrop(drop, (2, 2));
            context.PropagateWater(WaterContext.DefaultNeighborsGetter);
            var drops = context.Drops;

            Assert.Equal(4, drops.Count);
        }
コード例 #11
0
        public async Task StepAsync()
        {
            var propagator = new PropagateManager(PropagateManager.DefaultNeighborsGetter);
            var merger     = new MergeManager();
            var absorber   = new AbsorptionManager(AbsorptionManager.DefaultAbsorbtion);
            var context    = new WaterContext(Maps["plato"], propagator, merger, absorber);

            for (var i = 0; i < 10; i++)
            {
                await context.StepAsync();
            }
        }
コード例 #12
0
        public async Task <Customer> GetAsync(int id)
        {
            Customer someCustomer = null;

            using (WaterContext waterContext = new WaterContext())
            {
                someCustomer = await waterContext.Customers.FindAsync(id);

                // someCustomer = await waterContext.Customers.FirstOrDefaultAsync(f=>f.Id == id) ???
                await waterContext.SaveChangesAsync();
            }
            return(someCustomer);
        }
コード例 #13
0
ファイル: SampleData.cs プロジェクト: IvanIachmenev/HwWEB
        public static void Initialize(WaterContext context)
        {
            Brand Slavda = new Brand {
                Name = "Slavda", Country = "Russia"
            };
            Brand Swallow = new Brand {
                Name = "Swallow", Country = "Russia"
            };
            Brand Monastry = new Brand {
                Name = "Monastry", Country = "Russia"
            };

            if (!context.Brands.Any())
            {
                context.Brands.AddRange(Slavda, Swallow, Monastry);
                context.SaveChanges();
            }

            if (!context.Waters.Any())
            {
                context.Waters.AddRange(
                    new Water
                {
                    Name   = "Bottle 0.5L",
                    Count  = 10,
                    Price  = 65,
                    Brand  = Swallow,
                    Volume = 0.5,
                },
                    new Water
                {
                    Name   = "Bottle 1L",
                    Count  = 20,
                    Price  = 75,
                    Brand  = Monastry,
                    Volume = 1,
                },
                    new Water
                {
                    Name   = "Bottle 19L",
                    Count  = 5,
                    Price  = 110,
                    Brand  = Slavda,
                    Volume = 19,
                }
                    );
                context.SaveChanges();
            }
        }
コード例 #14
0
        public void MergeTest()
        {
            var propagator = new Propagator(Propagator.DefaultNeighborsGetter);
            var context    = new WaterContext(_map, propagator);
            var drop       = new WaterDrop(0.1);

            context.AddDrop(drop, (2, 2));
            context.PropagateWater(WaterContext.DefaultNeighborsGetter);
            context.PropagateWater(WaterContext.DefaultNeighborsGetter);
            var dropsBefore = context.Drops.ToDictionary(x => x.Key, x => x.Value);

            context.Merge();
            var dropsAfter = context.Drops.ToDictionary(x => x.Key, x => x.Value);

            Assert.Equal(16, dropsBefore.Count);
            Assert.Equal(9, dropsAfter.Count);
        }
コード例 #15
0
ファイル: UnitOfWork.cs プロジェクト: RinatAshirbekov/Water
 public UnitOfWork(string connectionString)
 {
     _context = new WaterContext(connectionString);
 }
コード例 #16
0
 public HomeController(ICustomerService customerService) // Вопрос: почему мы в конструктор передаем наш сервис, можно ли не передавать? или мы тем самым в конструкторе инициализируем данный сервис и контекст БД?
 {
     _customerService = customerService;
     _waterContext    = new WaterContext("WaterContext");
 }
コード例 #17
0
 public SypumpsController(WaterContext context)
 {
     _context = context;
 }
コード例 #18
0
ファイル: TableController.cs プロジェクト: lightxsout/nto
 /// <summary>
 /// Конструктор контроллера таблицы
 /// </summary>
 /// <param name="context"></param>
 public TableController(WaterContext context)
 {
     db = context;
 }
コード例 #19
0
 public CustomerRepository(WaterContext context) // Вопрос: зачем мы в конструктор передаем параметр? для чего он нужен? и как его используем?
 {
     this._context = context;
 }
コード例 #20
0
 /// <summary>
 /// Конструктор контроллера графика
 /// </summary>
 /// <param name="context"></param>
 public GraphController(WaterContext context)
 {
     db = context;
 }
コード例 #21
0
 public WaterRepository(WaterContext waterContext)
 {
     this.waterContext = waterContext;
 }
コード例 #22
0
 public DefaultController(WaterContext context)
 {
     _context = context;
 }
コード例 #23
0
 public WaterRepository(WaterContext context)
 {
     this._context = context;
 }
コード例 #24
0
 public HomeController(WaterContext context)
 {
     db = context;
 }