public DeviceRepositoryTests() { Repository = new DeviceRepository(new RepositoryContext()); Unit = new Unit { Created = DateTime.Now, Name = "Test Unit", DataType = DataType.DataPoint, DeviceId = 1, MeasurementUnitId = 1 }; }
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 }); }
public async Task CreateAsync(Unit unit) { Context.Units.Add(unit); await Context.SaveChangesAsync(); }