private async void Un_alerte() { var mockRepo = new MockAlertesRepository(); var alertes = await mockRepo.GetAll(); _alerte = alertes.First(); }
public IHttpActionResult PutAlerte(int id, Alerte alerte) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != alerte.AlerteId) { return(BadRequest()); } db.Entry(alerte).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AlerteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void une_alerte() { //TODO : Mettre l'application en mode Mocks et aller chercher un joueur dans le Mock var mockRepo = new MockAlertesRepository(); _alerte = mockRepo.GetById(1).Result; }
public async Task <IActionResult> Edit(int id, [Bind("Event_Nature,Sector,Risk,Ressource,Advice,Published")] Alerte alerte) { if (id != alerte.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _alertesRepository.Update(alerte); } catch (DbUpdateConcurrencyException) { if (!AlerteExists(alerte.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(alerte)); }
public async Task <IActionResult> Create([Bind("Event_Nature,Sector,Risk,Ressource,Advice,Published")] Alerte alerte) { if (ModelState.IsValid) { await _alertesRepository.Add(alerte); return(RedirectToAction(nameof(Index))); } return(View(alerte)); }
public async Task <IActionResult> Create([Bind("Nature,Secteur,Risque,Ressource,Conseil,Publié,Id")] Alerte alerte) { if (ModelState.IsValid) { await _repository.Add(alerte); return(RedirectToAction(nameof(Index))); } return(View(alerte)); }
public IHttpActionResult GetAlerte(int id) { Alerte alerte = db.Alertes.Find(id); if (alerte == null) { return(NotFound()); } return(Ok(alerte)); }
public IHttpActionResult PostAlerte(Alerte alerte) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Alertes.Add(alerte); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = alerte.AlerteId }, alerte)); }
private bool AlerteExists(int id) { Alerte alerte = _repository.GetById(id).Result; if (alerte == null) { return(false); } else { return(true); } }
public async Task <IActionResult> Modifier(Guid id, Alerte alerte, CancellationToken token) { if (id != alerte.IdErabliere) { return(BadRequest("L'id de la route ne concorde pas avec l'id de l'alerte à modifier.")); } var entity = _depot.Update(alerte); await _depot.SaveChangesAsync(token); return(Ok(entity.Entity)); }
public async Task <IActionResult> Supprimer(Guid id, Alerte alerte, CancellationToken token) { if (id != alerte.IdErabliere) { return(BadRequest("L'id de la route ne concorde pas avec l'id de l'alerte à supprimer.")); } _depot.Remove(alerte); await _depot.SaveChangesAsync(token); return(NoContent()); }
public IHttpActionResult DeleteAlerte(int id) { Alerte alerte = db.Alertes.Find(id); if (alerte == null) { return(NotFound()); } db.Alertes.Remove(alerte); db.SaveChanges(); return(Ok(alerte)); }
public Danger GetDangerByAlert(Alerte alerte) { if (alerte.Danger == null) { return(null); } foreach (var danger in GetMany(c => c.Id > 0).ToList()) { if (alerte.Danger.Id == danger.Id) { return(danger); } } return(null); }
public async void Test_Publish_WhenNotPublished_ShouldPublish() { //Arrange Alerte alert = new Alerte() { Id = 0, Event_Nature = "Rats!!", Sector = "Ste-Foy", Risk = "Moyen", Ressource = "Exterminateurs", Advice = "S'enfuir", Status = Status.Attente }; //Act var result = await _alertesController.Publish(alert.Id, alert); //Assert Status EXPECTED_STATUS = Status.Publiee; Alerte updatedAlert = await _mockRepo.GetById(alert.Id); Assert.Equal(EXPECTED_STATUS, updatedAlert.Status); }
public async void Test_Update_ShouldUpdate() { //Arrange Alerte alert = new Alerte() { Id = 0, Event_Nature = "Rats!!", Sector = "Ste-Foy", Risk = "Moyen", Ressource = "Exterminateurs", Advice = "S'enfuir", Status = Status.Publiee }; Alerte alertUpdated = new Alerte() { Id = 0, Event_Nature = "Test!!", Sector = "Ste-Foy", Risk = "Faible", Ressource = "Exterminateurs", Advice = "S'enfuir", Status = Status.Publiee }; //Act var result = await _alertesController.Edit(alert.Id, alertUpdated); //Assert Alerte updatedAlert = await _mockRepo.GetById(alert.Id); string alertString = updatedAlert.ToString(); string alertStringExpected = alertUpdated.ToString(); Assert.Equal(alertStringExpected, alertString); }
public async Task <IActionResult> Desactiver(Guid id, Guid idAlerte, Alerte alerte, CancellationToken token) { if (id != alerte.IdErabliere) { return(BadRequest("L'id de l'érablière dans la route ne concorde pas avec l'id de l'érablière de l'alerte à désactiver.")); } if (idAlerte != alerte.Id) { return(BadRequest("L'id de la route ne concorde pas avec l'id de l'alerte à désactiver.")); } var entity = await _depot.Alertes.FindAsync(new object?[] { alerte.Id }, cancellationToken : token); if (entity is not null && entity.IdErabliere == id) { entity.IsEnable = false; await _depot.SaveChangesAsync(token); return(Ok()); } return(NotFound(alerte)); }
public async Task <IActionResult> Withdraw(int id, [Bind("Id")] Alerte alerte) { if (id != alerte.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Alerte oldAlert = await _repository.GetById(alerte.Id); alerte.Publié = false; alerte.Nature = oldAlert.Nature; alerte.Ressource = oldAlert.Ressource; alerte.Risque = oldAlert.Risque; alerte.Secteur = oldAlert.Secteur; alerte.Conseil = oldAlert.Conseil; await _repository.Update(alerte); } catch (DbUpdateConcurrencyException) { if (!AlerteExists(alerte.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(alerte)); }
private void MaybeTriggerAlerte(Alerte alerte, ILogger <TriggerAlertAttribute> logger) { if (_donnee == null) { throw new InvalidOperationException("La donnée membre '_donnee' doit être initialiser pour utiliser la fonction d'alertage."); } var validationCount = 0; var conditionMet = 0; if (alerte.NiveauBassinThresholdHight != null && short.TryParse(alerte.NiveauBassinThresholdHight, out short nbth)) { validationCount++; if (nbth > _donnee.NB) { conditionMet++; } } if (alerte.NiveauBassinThresholdLow != null && short.TryParse(alerte.NiveauBassinThresholdLow, out short nbtl)) { validationCount++; if (nbtl < _donnee.NB) { conditionMet++; } } if (alerte.VacciumThresholdHight != null && short.TryParse(alerte.VacciumThresholdHight, out short vth)) { validationCount++; if (vth > _donnee.V) { conditionMet++; } } if (alerte.VacciumThresholdLow != null && short.TryParse(alerte.VacciumThresholdLow, out short vtl)) { validationCount++; if (vtl < _donnee.V) { conditionMet++; } } if (alerte.TemperatureThresholdHight != null && short.TryParse(alerte.TemperatureThresholdHight, out short tth)) { validationCount++; if (tth > _donnee.T) { conditionMet++; } } if (alerte.TemperatureThresholdLow != null && short.TryParse(alerte.TemperatureThresholdLow, out short ttl)) { validationCount++; if (ttl < _donnee.T) { conditionMet++; } } if (validationCount > 0 && validationCount == conditionMet) { TriggerAlerte(alerte, logger); } }
public ActionResult Create(AlerteVM avm) { IServiceDisease service = new ServiceDisease(); IServiceAlerte serviceAlerte = new ServiceAlerte(); IServiceDanger servicedanger = new ServiceDanger(); IWContext context = new IWContext(); avm.NameDiseas = avm.NameDiseas.Trim(); Disease disease = context.Diseases.Where(d => d.Name.Equals(avm.NameDiseas)).FirstOrDefault(); //context.Entry(disease).State = System.Data.Entity.EntityState.Unchanged; //Disease disease = service.FindByName(avm.NameDiseas); if (disease != null) { string userid = User.Identity.GetUserId(); ApplicationUser user = context.Users.FirstOrDefault(x => x.Id == userid); Alerte LastAlerte = serviceAlerte.GetAlerteByUser(user); if ((LastAlerte != null && LastAlerte.DateTime.Subtract(DateTime.Today).Days >= 7) || LastAlerte == null) { if (user != null) { Alerte a = context.Alertes.Where(c => c.Disease.Name.Equals(disease.Name)).FirstOrDefault(); if (a != null) { Alerte alerte = new Alerte() { Disease = disease, User = user, DateTime = DateTime.Today, Danger = a.Danger }; context.Alertes.Add(alerte); context.SaveChanges(); } else { Danger d = new Danger() { Date = DateTime.Now }; Alerte alerte = new Alerte() { Disease = disease, User = user, DateTime = DateTime.Today, Danger = d }; context.Alertes.Add(alerte); context.SaveChanges(); } /* ICollection<Danger> Dangers = context.Dangers.Include("Alertes").ToList(); * Danger danger = new Danger(); * foreach(var D in Dangers) * { * foreach(var x in D.Alertes) * { * Alerte y = context.Alertes.Include("Disease").Where(c => c.Id == x.Id).SingleOrDefault(); * if (y.Disease.Name.Equals(alerte.Disease.Name)) * danger = D; * } * } * danger.Date = DateTime.Now; * //Danger danger = servicedanger.GetDangerByAlert(alerte); * if(danger == null) * { * * danger.Alertes.Add(alerte); * context.Dangers.Add(danger); * alerte.Danger = danger; * context.SaveChanges(); * * } * else * { * danger.Alertes.Add(alerte); * context.SaveChanges(); * }*/ context.Dispose(); return(View("Sucess")); } } else { context.Dispose(); return(View("Error")); } } context.Dispose(); return(Create()); }
public async Task <IActionResult> Publish(int id, [Bind("Event_Nature,Sector,Risk,Ressource,Advice,Published")] Alerte alerte) { await _alertesRepository.Publish(id); return(RedirectToAction(nameof(Index))); }