public List <IncidentViewModel> GetIncidentReportByTowerId([FromRoute] string TowerId) { var reports = IncidentRepository.GetAll(UserEmail); var reportsByTowerId = reports.Where(r => r.TowerId == TowerId).Adapt <IEnumerable <Incident>, List <IncidentViewModel> >(); return(reportsByTowerId); }
public void RemoveById_AddANewIncidentThenRemoveIt_ReturnTrue() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); //Room(and it's floor) var floor = new FloorTO { Number = 2 }; var addedFloor1 = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1 }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); //Component var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); //Issue var issue = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); //Incident var incident = new IncidentTO { Description = "No coffee", Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, Room = addedRoom }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); //ACT var result = incidentRepository.Remove(addedIncident.Id); context.SaveChanges(); //ASSERT Assert.IsTrue(result); }
public IHttpActionResult List() { var repository = new IncidentRepository(); var incidents = repository.List(); return(this.Ok(incidents.ToModel())); }
public RedirectToActionResult Delete(Incident incident) { IncidentRepository.Delete(incident); UnitOfWork.Save(); TempData["message"] = $"{incident.Title} deleted from database"; return(RedirectToAction("List", "Incident")); }
/// <summary> /// Initializes a new instance of the <see cref="T:UCLouvain.AmbulanceSystem.Server.AmbulanceAllocator"/> class. /// </summary> /// <param name="db">Db. Do not share among threads.</param> public AmbulanceAtStationAllocator(MapService mapService, IDatabase db) { ambulanceRepository = new AmbulanceRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); this.mapService = mapService; this.incidentsToProcess = new BlockingCollection <Incident>(); new Thread(this.Start).Start(); }
public Cancelator(IDatabase db) { ambulanceRepository = new AmbulanceRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); allocationRepository = new AllocationRepository(db); sender = new RabbitMQMessageSender(); allocationsToProcess = new BlockingCollection <Allocation>(); new Thread(Start).Start(); }
public void Update_ThrowException_WhenNullIsSupplied() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); IIncidentRepository incidentRepository = new IncidentRepository(context); //ACT & ASSERT Assert.ThrowsException <ArgumentNullException>(() => incidentRepository.Update(null)); }
public void RemoveById_ThrowException_WhenInvalidIdIsSupplied() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); IIncidentRepository incidentRepository = new IncidentRepository(context); //ACT & ASSERT Assert.ThrowsException <ArgumentException>(() => incidentRepository.Remove(0)); Assert.ThrowsException <ArgumentException>(() => incidentRepository.Remove(-1)); }
public IHttpActionResult ListId(long Id) { try { var repository = new IncidentRepository(); var incident = repository.GetId(Id); var model = incident.ToModel(); return(this.Ok(model)); } catch (Exception ex) { return(this.BadRequest(ex.Message)); } }
public ApiController() { var provider = new PostgreSQLDatabaseProvider(); var connectionString = ConfigurationManager.ConnectionStrings["postgres"].ConnectionString; var config = DatabaseConfiguration.Build() .UsingConnectionString(connectionString) .UsingProvider(provider) .UsingDefaultMapper <ConventionMapper>(); var db = new Database(config); ambulanceRepository = new AmbulanceRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); allocationRepository = new AllocationRepository(db); }
public void Update_ThrowException_WhenUnexistingIncidentIsSupplied() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); IIncidentRepository incidentRepository = new IncidentRepository(context); var incident = new IncidentTO { Id = 999 }; //ACT & ASSERT Assert.ThrowsException <KeyNotFoundException>(() => incidentRepository.Update(incident)); }
public virtual IActionResult GetIncidentReportById([FromRoute] long id) { var rptModel = IncidentRepository.Find(id); var report = new IncidentViewModel(); if (rptModel != null) { report = rptModel.Adapt <IncidentViewModel>(); return(new ObjectResult(report)); } else { return(new ObjectResult(new ResponseMsg { HttpStatusCode = (int)HttpStatusCode.BadRequest, Message = "Report does not exist" })); } }
public ViewResult TechIncident(IncidentViewModel inc) { var techId = inc.CurrentIncident.TechnicianID; var technician = TechnicianRepository.Get(t => t.TechnicianID == techId).Single(); var model = new IncidentViewModel { ActiveIncident = inc.ActiveIncident, Incidents = IncidentRepository.Get(orderBy: i => i.OrderBy(ii => ii.Title)).ToList(), Technicians = TechnicianRepository.Get(orderBy: t => t.OrderBy(tt => tt.Name)).ToList(), Customers = CustomerRepository.Get(orderBy: c => c.OrderBy(cc => cc.FirstName)).ToList(), Products = ProductRepository.Get(orderBy: p => p.OrderBy(pp => pp.Name)).ToList(), ActiveTechnician = technician.Name }; return(View(model)); }
private void InitializeRepositories() { ClientRepository = new ClientRepository(this.context); ClientConditionRepository = new ClientConditionRepository(this.context); ClientDrinkRepository = new ClientDrinkRepository(this.context); ClientFoodRepository = new ClientFoodRepository(this.context); ClientIncidentRepository = new ClientIncidentRepository(this.context); ClientInformationRepository = new ClientInformationRepository(this.context); DrinkRepository = new DrinkRepository(this.context); FoodRepository = new FoodRepository(this.context); IncidentRepository = new IncidentRepository(this.context); IncidentPhotoRepository = new IncidentPhotoRepository(this.context); UserRepository = new UserRepository(this.context); UserIncidentRepository = new UserIncidentRepository(this.context); UserTypeRepository = new UserTypeRepository(this.context); MessageRepository = new MessageRepository(this.context); }
public IActionResult EditIncident(IncidentViewModel model) { string Action = "EditIncident"; if (ModelState.IsValid) { IncidentRepository.Update(model.CurrentIncident); UnitOfWork.Save(); TempData["message"] = $"{model.CurrentIncident.Title} {Action}ed to database"; return(RedirectToAction("List", "Incident")); } else { //model.Action = Action; model.CurrentIncident = IncidentRepository.Get(model.CurrentIncident.IncidentID); return(View("EditIncident", model)); } }
public void ListTest() { var mockIncident = new Incident { Description = "Mock Description" }; var mockContext = new IncidentDataContext { Incidents = new[] { mockIncident } }; var target = new IncidentRepository(mockContext); var actuals = target.List(); Assert.IsNotNull(actuals); Assert.IsTrue(actuals.Success); Assert.IsNotNull(actuals.Output); Assert.AreEqual(1, actuals.Output.Count()); Assert.AreEqual(mockIncident.Description, actuals.Output.ToList()[0].Description); }
public virtual IActionResult DeleteReport([FromRoute] long id) { var reports = IncidentRepository.Find(id); if (reports != null) { IncidentRepository.Remove(reports.IncidentId); return(new ObjectResult(new ResponseMsg { HttpStatusCode = (int)HttpStatusCode.OK, Message = "Report deleted successfully." })); } else { return(new ObjectResult(new ResponseMsg { HttpStatusCode = (int)HttpStatusCode.OK, Message = "Not deleted.Report does not exist" })); } }
public HomeController() { // var provider = new MonoSQLiteDatabaseProvider(); var provider = new PostgreSQLDatabaseProvider(); var connectionString = ConfigurationManager.ConnectionStrings["postgres"].ConnectionString; var config = DatabaseConfiguration.Build() .UsingConnectionString(connectionString) .UsingProvider(provider) .UsingDefaultMapper <ConventionMapper>(); var db = new Database(config); // connection.Open(); //logger.Info (db.ExecuteScalar<int>("select count(*) from ambulances where ambulances.ambulanceId = 'A9';")); ambulanceRepository = new AmbulanceRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); allocationRepository = new AllocationRepository(db); }
public Checker(IDatabaseBuildConfiguration config) { this.config = config; var db = new Database(config); ambulanceRepository = new AmbulanceRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); allocationRepository = new AllocationRepository(db); configurationRepository = new ConfigurationRepository(db); mapService = new MapService(); allocator = new DefaultAmbulanceAllocator(mapService, new LoggedDatabase(config)); configurationRepository.UpdateActiveAllocator("DefaultAmbulanceAllocator"); mobilizator = new AmbulanceMobilizator(new Database(config)); trafficJamReallocator = new TrafficJamReallocator(mapService, new LoggedDatabase(config)); cancelator = new Cancelator(new Database(config)); }
public Orchestrator(IDatabaseBuildConfiguration config) { var db = new Database(config); ambulanceRepository = new AmbulanceRepository(db); ambulanceStationRepository = new AmbulanceStationRepository(db); hospitalRepository = new HospitalRepository(db); incidentRepository = new IncidentRepository(db); allocationRepository = new AllocationRepository(db); mapService = new MapService(); ip = new IncidentProcessor(this); //allocator = new AmbulanceAllocator(mapService, new LoggedDatabase(config)); //mobilizator = new AmbulanceMobilizator(new Database (config)); //trafficJamReallocator = new TrafficJamReallocator(mapService, new LoggedDatabase(config)); //cancelator = new Cancelator(new Database(config)); checker = new Checker(config); checker.Start(); }
public ViewResult ListByTech(string activeIncident = "All", string activeTechnician = "All") { var model = new IncidentViewModel { //ActiveIncident = activeIncident, ActiveTechnician = activeTechnician, //Incidents = context.Incidents.OrderBy(i => i.Title).ToList(), Technicians = TechnicianRepository.Get(orderBy: technicians => technicians.OrderBy(c => c.Name)).ToList() }; IEnumerable <Incident> query = IncidentRepository.Get(); if (activeIncident != "All") { query = IncidentRepository.Get(incident => incident.IncidentID.ToString() == activeIncident); } if (activeTechnician != "All") { query = IncidentRepository.Get(i => i.Technician.TechnicianID.ToString() == activeTechnician); } model.Incidents = query.ToList(); return(View(model)); }
public ViewResult EditIncident(int id) { Incident activeIncident = IncidentRepository.Get(id); var model = new IncidentViewModel { Action = "EditIncident", Technicians = TechnicianRepository.Get(orderBy: t => t.OrderBy(tt => tt.Name)).ToList(), Customers = CustomerRepository.Get(orderBy: c => c.OrderBy(cc => cc.FirstName)).ToList(), Products = ProductRepository.Get(orderBy: p => p.OrderBy(pp => pp.Name)).ToList(), CurrentIncident = IncidentRepository.Get(id) }; IEnumerable <Incident> query = IncidentRepository.Get(); if (activeIncident.IncidentID != 0) { query = IncidentRepository.Get(i => i.IncidentID == activeIncident.IncidentID); } model.Incidents = query.ToList(); model.CurrentIncident = IncidentRepository.Get(id); return(View("EditIncident", model)); }
public ViewResult TechIncident(string activeIncident = "All", string activeTechnician = "All") { var model = new IncidentViewModel { ActiveIncident = activeIncident, ActiveTechnician = activeTechnician, Incidents = IncidentRepository.Get(orderBy: i => i.OrderBy(ii => ii.Title)).ToList(), Technicians = TechnicianRepository.Get(orderBy: t => t.OrderBy(tt => tt.Name)).ToList(), Customers = CustomerRepository.Get(orderBy: c => c.OrderBy(cc => cc.FirstName)).ToList(), Products = ProductRepository.Get(orderBy: p => p.OrderBy(pp => pp.Name)).ToList() }; IEnumerable <Incident> query = IncidentRepository.Get(); if (activeIncident != "All") { query = IncidentRepository.Get(i => i.IncidentID.ToString() == activeIncident); } if (activeTechnician != "All") { query = IncidentRepository.Get(i => i.Technician.TechnicianID.ToString() == activeIncident); } model.Incidents = query.ToList(); return(View(model)); }
public void UpdateComment_AddNewCommentThenUpdateIt_ReturnsUpdatedComment() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident = new IncidentTO { Description = "This thing is broken !", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); var comment = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 1 }; var commentAdded = commentRepository.Add(comment); context.SaveChanges(); // Act var later = DateTime.Now.AddHours(2); commentAdded.Message = "Updated message"; commentAdded.SubmitDate = later; var result = commentRepository.Update(commentAdded); context.SaveChanges(); // Assert Assert.IsNotNull(result); Assert.AreEqual("Updated message", result.Message); Assert.AreEqual(later, result.SubmitDate); }
public void GetCommentsByIncidentId_AddMultipleComments_ReturnRelevantComments() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident1 = new IncidentTO { Description = "This thing is broken!", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var incident2 = new IncidentTO { Description = "This thing is still broken after a week!", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now.AddDays(7), UserId = 1, }; var addedIncident1 = incidentRepository.Add(incident1); var addedIncident2 = incidentRepository.Add(incident2); context.SaveChanges(); var comment1 = new CommentTO { Incident = addedIncident1, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 2 }; var comment2 = new CommentTO { Incident = addedIncident1, Message = "New ETA is Monday morning.", SubmitDate = DateTime.Now.AddDays(1), UserId = 2 }; var comment3 = new CommentTO { Incident = addedIncident2, Message = "It should be fixed very soon, sorry for the inconvenience!", SubmitDate = DateTime.Now.AddDays(8), UserId = 2 }; commentRepository.Add(comment1); commentRepository.Add(comment2); commentRepository.Add(comment3); context.SaveChanges(); // Act var result1 = commentRepository.GetCommentsByIncident(addedIncident1.Id); var result2 = commentRepository.GetCommentsByIncident(addedIncident2.Id); // Assert Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.AreEqual(2, result1.Count); Assert.AreEqual(1, result2.Count); }
public ViewResult Delete(int id) { var incident = IncidentRepository.Get(id); return(View(incident)); }
public List <IncidentViewModel> GetAllIncidentReport() { var reports = IncidentRepository.GetAll(UserEmail).Adapt <IEnumerable <Incident>, List <IncidentViewModel> >(); return(reports); }
public CaptureSafe() { InitializeComponent(); incidentRepository = new IncidentRepository(); }
public IncidentService(DataContext context, IMapper mapper) { this._incidentRepository = new IncidentRepository(context); this._mapper = mapper; }
public void RemoveCommentById_AddNewCommentThenRemoveIt_ReturnsTrue() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident = new IncidentTO { Description = "This thing is broken !", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); var comment = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 1 }; var addedComment = commentRepository.Add(comment); context.SaveChanges(); // Act var result = commentRepository.Remove(addedComment.Id); context.SaveChanges(); // Assert Assert.IsTrue(result); Assert.ThrowsException <KeyNotFoundException>(() => commentRepository.GetById(addedComment.Id)); }