public async Task <IActionResult> Register(RegisterViewModel registerVm) { if (ModelState.IsValid) { Users user = await _context.Users.FirstOrDefaultAsync( u => u.Email == registerVm.Email).ConfigureAwait(true); if (user == null) { Users newUser = new Users { Email = registerVm.Email, Password = registerVm.Password, Surname = registerVm.Surname, Forename = registerVm.Forename }; _context.Add(newUser); await _context.SaveChangesAsync().ConfigureAwait(true); await Authenticate(newUser.UserId, registerVm.Email).ConfigureAwait(true); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Некорректные эл. почта и/или пароль"); } } return(View(registerVm)); }
public async Task <IActionResult> Create([Bind("SensorId,Name,Metadata,DataType,CommunicationProtocolId,IpAddress,Port")] SensorCreateViewModel sensorVm) { if (ModelState.IsValid) { Datatypes newDatatype = new Datatypes { Schema = sensorVm.DataType }; _context.Add(newDatatype); await _context.SaveChangesAsync().ConfigureAwait(true); Sensors newSensor = new Sensors { SensorId = sensorVm.SensorId, Name = sensorVm.Name, Metadata = sensorVm.Metadata, CommunicationProtocolId = sensorVm.CommunicationProtocolId, IpAddress = sensorVm.IpAddress, Port = sensorVm.Port, DataTypeId = newDatatype.DataTypeId }; _context.Add(newSensor); await _context.SaveChangesAsync().ConfigureAwait(true); return(RedirectToAction(nameof(Index))); } ViewData["CommunicationProtocolId"] = new SelectList( _context.CommunicationProtocols, "CommunicationProtocolId", "ProtocolName", sensorVm.CommunicationProtocolId); return(View(sensorVm)); }
public async Task <IActionResult> Create([Bind("Name,Metadata,DurationSeconds,ExperimentId,ExperimentName,ExperimentSensorName")] TestCreateViewModel testVm) { if (!DoesUserHaveAccess(testVm.ExperimentId)) { return(NotFound()); } if (ModelState.IsValid) { Tests test = new Tests { Name = testVm.Name, Metadata = testVm.Metadata, ExperimentId = testVm.ExperimentId, StartedTime = DateTime.Now }; test.EndedTime = test.StartedTime.AddSeconds(testVm.DurationSeconds); db.Add(test); await db.SaveChangesAsync().ConfigureAwait(true); var sensorId = db.ExperimentSensors.FirstOrDefault(m => m.ExperimentId == test.ExperimentId).SensorId; var sensor = await db.Sensors.FirstOrDefaultAsync(m => m.SensorId == sensorId).ConfigureAwait(true); var sensorConnectorCommand = CommandBuilder.BuildSensorListenerStartCommand(test.TestId, sensor.IpAddress, sensor.Port, testVm.DurationSeconds); System.Diagnostics.Process.Start( @"SensorListener\SensorListener", sensorConnectorCommand); testVm.StartedTime = test.StartedTime; return(View("Measurement", testVm)); } return(View(testVm)); }
public async Task <IActionResult> Create([Bind("Name,Metadata,SensorId")] ExperimentCreateViewModel experimentVm) { if (ModelState.IsValid) { Experiments experiment = new Experiments { Name = experimentVm.Name, Metadata = experimentVm.Metadata, CreatedAt = DateTime.Now }; db.Add(experiment); await db.SaveChangesAsync().ConfigureAwait(true); ExperimentSensors experimentSensor = new ExperimentSensors { ExperimentId = experiment.ExperimentId, SensorId = experimentVm.SensorId }; db.Add(experimentSensor); await db.SaveChangesAsync().ConfigureAwait(true); UserExperiments userExperiment = new UserExperiments { UserId = GetCurrUserId(), ExperimentId = experiment.ExperimentId }; db.Add(userExperiment); await db.SaveChangesAsync().ConfigureAwait(true); return(RedirectToAction(nameof(Index))); } ViewData["SensorId"] = new SelectList( db.Sensors, "SensorId", "Name", experimentVm.SensorId); return(View(experimentVm)); }