コード例 #1
0
        public DeviceRepositoryTests()
        {
            Repository = new DeviceRepository(new RepositoryContext());

            Unit = new Unit
            {
                Created = DateTime.Now,
                Name = "Test Unit",
                DataType = DataType.DataPoint,
                DeviceId = 1, 
                MeasurementUnitId = 1
            };
        }
コード例 #2
0
        public async Task<ActionResult> Unit(CreateUnit model)
        {
            if (model == null || !ModelState.IsValid)
            {
                ModelState.AddModelError("", "Failed to add unit to device.");
                return View("Unit", model);
            }

            Unit unit = new Unit
            {
                Name = model.Name,
                DeviceId = model.DeviceId,
                MeasurementUnitId = model.MeasurementUnitId
            };

            await deviceRepository.CreateAsync(unit);

            return RedirectToAction("Details", new { id = unit.DeviceId });
        }
コード例 #3
0
 public async Task CreateAsync(Unit unit)
 {
     Context.Units.Add(unit);
     await Context.SaveChangesAsync();
 }