public ActionResult Create([Bind(Include = "ExpOption,ID")] Participant participant) { try { if (ModelState.IsValid) { db.Participants.Add(participant); db.SaveChanges(); return(RedirectToAction("InitializeExp", "Home", new { id = participant.ID })); } } catch (DataException e) { if (db.Participants.Find(participant.ID) != null) { TempData["ErrorMessage"] = "מספר הזיהוי שהזנת כבר קיים במערכת. אנא חזור ונסה מספר זיהוי אחר."; } else { ModelState.AddModelError("", "Unable to save changes." + e.Message); TempData["ErrorMessage"] = "שגיאה באתחול הנבדק " + e.Message; } return(RedirectToAction("Error", "Home")); } return(View(participant)); }
public ActionResult Create([Bind(Include = "Id,MatricNumber,Name,ThesisTitle,ClassGroup,BatchYear,Faculty")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult BaselineAudio(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Participant participant = db.Participants.Find(id); if (participant == null) { return(HttpNotFound()); } //add audio file name participant.AudioBaselinePath = "AudioBaseline" + participant.ID + ".wav"; db.Entry(participant).State = EntityState.Modified; db.SaveChanges(); return(View(participant)); }
public ExperimentController(ExperimentContext context) { this.context = context; if (context.AccelData.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. context.AccelData.Add(new AccelData { Time = DateTime.Now, Acceleration = 0.04M }); context.SaveChanges(); } }
public void UpadateExperimentHandler() { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); var task = Task.Run(async() => { using var consumerBuilder = new ConsumerBuilder <Null, ExperimentModel>(consumerConfig) .SetValueDeserializer(new JsonDeserializer <ExperimentModel>().AsSyncOverAsync()) .Build(); { consumerBuilder.Subscribe("UpadateExperimentCommand"); try { while (true) { try { var consumeResult = consumerBuilder.Consume(cancellationTokenSource.Token); if (consumeResult != null && consumeResult.Message.Value != null) { var Experiment = GetExperiment(consumeResult.Message.Value.Id); if (Experiment.IsSuccess) { using (var experimentContext = new ExperimentContext()) { var existExperiment = Experiment.Value; existExperiment.Name = consumeResult.Message.Value.Name; existExperiment.TimeStamp = consumeResult.Message.Value.TimeStamp; experimentContext.Experiments.Update(existExperiment); experimentContext.SaveChanges(); await _experimentEventsService.ExperimentUpadatedEvent(existExperiment); } } } } catch (ConsumeException consumeException) { } } } catch (OperationCanceledException) { consumerBuilder.Close(); } } }); }
public Result CreateExperimentHandler() { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); var task = Task.Run(() => { using var consumerBuilder = new ConsumerBuilder <Null, ExperimentModel>(consumerConfig) .SetValueDeserializer(new JsonDeserializer <ExperimentModel>().AsSyncOverAsync()) .Build(); consumerBuilder.Subscribe("CreateExperimentCommand"); try { while (true) { try { var consumeResult = consumerBuilder.Consume(cancellationTokenSource.Token); if (consumeResult != null && consumeResult.Message != null) { using var experimentContext = new ExperimentContext(); try { var experiment = consumeResult.Message.Value; experimentContext.Experiments.Add(experiment); experimentContext.SaveChanges(); _experimentEventsService.ExperimentCreatedEvent(experiment); } catch (Exception exception) { } } } catch (ConsumeException consumeException) { } } } catch (OperationCanceledException) { consumerBuilder.Close(); } }); return(Result.Ok()); }
public bool Save() { return(_context.SaveChanges() >= 0); }