示例#1
0
        public Preparedness Allocation([FromBody] Preparedness preparedness)
        {
            //Create the new preparedness
            preparedness.CreationTime = DateTimeOffset.UtcNow;

            var existingVehicle = _context.Vehicles.Include(s => s.Status).FirstOrDefault(x => x.ID == preparedness.Vehicle.ID);

            var existingStatus = _context.Status.FirstOrDefault(x => x.ID == preparedness.Vehicle.Status.ID);

            var existingIncident = _context.Incidents.FirstOrDefault(x => x.ID == preparedness.Incident.ID);

            existingVehicle.Status = existingStatus;

            preparedness.Incident.Journals = null;

            preparedness.Status = "Aktiv";

            _context.Preparednesses.Attach(preparedness);

            _context.SaveChanges();

            //Remove the other preparedness
            var exisitngPreparedness = _context.Preparednesses.Include(v => v.Vehicle).FirstOrDefault(x => x.ID == preparedness.ID);

            var TheOtherPreparedness = _context.Preparednesses.Include(x => x.Incident).Where(x => x.Vehicle.ID == exisitngPreparedness.Vehicle.ID).Where(x => x.Status == "Aktiv").FirstOrDefault(x => x.CreationTime != exisitngPreparedness.CreationTime);

            TheOtherPreparedness.Status  = "Inaktiv";
            TheOtherPreparedness.Vehicle = null;

            var existingOldIncident = _context.Incidents.FirstOrDefault(x => x.ID == TheOtherPreparedness.Incident.ID);

            var logger = new Logger();

            logger.Preparedness = exisitngPreparedness;
            logger.Time         = DateTimeOffset.UtcNow;
            logger.LogMessage   = "Vogn omdisponeret";
            logger.Incident     = existingIncident;
            _context.Loggers.Add(logger);

            var logger2 = new Logger();

            logger2.Preparedness = TheOtherPreparedness;
            logger2.Time         = DateTimeOffset.UtcNow;
            logger2.LogMessage   = "Vognen er flyttet";
            logger2.Incident     = existingOldIncident;
            _context.Loggers.Add(logger2);

            _context.SaveChanges();

            preparedness.Vehicle       = null;
            preparedness.Loggers       = null;
            preparedness.Incident      = null;
            preparedness.EmergencyCode = null;

            _messageHubContext.Clients.All.InvokeAsync("PreparednessAllocation", preparedness);

            return(exisitngPreparedness);
        }
示例#2
0
        public (bool, string) UpdateTask(Preparedness preparedness)
        {
            updateTask updateTask = new updateTask
            {
                Message            = GetMessage(preparedness.Incident),
                TaskIdentification = GetTaskType(preparedness).Identification,
                Task = new TaskType
                {
                    IncidentIdentification = GetIncidentType(preparedness.Incident).Identification,
                }
            };

            updateTask.Task.Identification = GetTaskType(preparedness).Identification;

            updateTask.Task.Vehicle = GetTaskType(preparedness).Vehicle;

            updateTask.Task.PriorityToIncident = preparedness.EmergencyCode.Code;

            //Status for Task
            updateTaskStatus updateTaskStatus = new updateTaskStatus
            {
                TaskIdentification = GetTaskType(preparedness).Identification,
                Message            = GetMessage(preparedness.Incident),
                Status             = new TaskStatusType
                {
                    Code = GetConvertedEnums(preparedness),
                    Time = DateTime.UtcNow.ToString("yyyy'-'MM'-'ddTHH':'mm':'ss':'fff")
                }
            };

            ppjInterfaceClient client = GetClient();

            var securityHeader = new SecurityHeaderType();
            var header         = new Header();

            var response           = client.updateTask(ref securityHeader, ref header, updateTask);
            var tastStatusResponse = client.updateTaskStatus(ref securityHeader, ref header, updateTaskStatus);

            if (response.Error != null || tastStatusResponse.Error != null)
            {
                return(response.Type == ControlType.POSITIVE, response.Error.Description);
            }
            else
            {
                return(response.Type == ControlType.POSITIVE, "");
            }
        }
示例#3
0
        public Preparedness UpdatePreparedness([FromBody] Preparedness preparedness)
        {
            var existingPreparedness = _context.Preparednesses.Include(x => x.Vehicle).FirstOrDefault(x => x.ID == preparedness.ID);

            existingPreparedness.CreationTime = DateTimeOffset.UtcNow;

            var existingCode = _context.EmergencyCodes.FirstOrDefault(x => x.ID == preparedness.EmergencyCode.ID);

            var existingStatus = _context.Status.FirstOrDefault(x => x.ID == preparedness.Vehicle.Status.ID);

            existingPreparedness.EmergencyCode  = existingCode;
            existingPreparedness.Vehicle.Status = existingStatus;

            var existingIncident = _context.Incidents.FirstOrDefault(x => x.ID == preparedness.Incident.ID);

            var logger = new Logger();

            logger.Time = DateTimeOffset.UtcNow;

            preparedness.Vehicle.Status = existingStatus;

            preparedness.EmergencyCode = _context.EmergencyCodes.FirstOrDefault(x => x.ID == preparedness.EmergencyCode.ID);

            var updatePreparedness = iParser.CreatePreparedness(preparedness);

            if (updatePreparedness.Item2 == ErrorHandling.Positive)
            {
                updatePreparedness.Item1 = "Beredskab opdateret";
            }

            logger.LogMessage = updatePreparedness.Item1;
            logger.Success    = updatePreparedness.Item2;

            logger.Incident = existingIncident;
            _context.Loggers.Add(logger);

            existingPreparedness.Loggers = new List <Logger>();
            existingPreparedness.Loggers.Add(logger);

            _context.SaveChanges();

            existingPreparedness.Loggers = null;

            _messageHubContext.Clients.All.InvokeAsync("PreparednessUpdated", preparedness);

            return(existingPreparedness);
        }
示例#4
0
        public Preparedness RemovePreparedness([FromBody] Preparedness preparedness)
        {
            var exisitngPreparedness = _context.Preparednesses.Include(v => v.Vehicle).FirstOrDefault(x => x.ID == preparedness.ID);

            var existingVehicle = _context.Vehicles.FirstOrDefault(x => x.ID == preparedness.Vehicle.ID);

            var existingIncident = _context.Incidents.FirstOrDefault(x => x.ID == preparedness.Incident.ID);

            exisitngPreparedness.Status = "Inaktiv";

            var status = new Status();

            status.ID = 3;

            var existingStatus = _context.Status.FirstOrDefault(x => x.ID == status.ID);

            existingStatus.ID = 3;

            existingVehicle.Status = existingStatus;

            var fjernlogger = new Logger();

            fjernlogger.Preparedness = exisitngPreparedness;
            fjernlogger.Time         = DateTimeOffset.UtcNow;

            preparedness.EmergencyCode = _context.EmergencyCodes.FirstOrDefault(x => x.ID == preparedness.EmergencyCode.ID);

            var removedPreparedness = iParser.RemovePreparedness(preparedness);

            fjernlogger.LogMessage = removedPreparedness.Item1;
            fjernlogger.Success    = removedPreparedness.Item2;
            fjernlogger.Incident   = existingIncident;
            _context.Loggers.Add(fjernlogger);

            exisitngPreparedness.Loggers = new List <Logger>();
            exisitngPreparedness.Loggers.Add(fjernlogger);

            _context.SaveChanges();

            preparedness.Vehicle       = null;
            preparedness.Loggers       = null;
            preparedness.EmergencyCode = null;

            _messageHubContext.Clients.All.InvokeAsync("PreparednessRemoved", preparedness);

            return(exisitngPreparedness);
        }
        public (string, ErrorHandling) RemovePreparedness(Preparedness preparedness)
        {
            var proxy     = new ProxyController(states);
            var proxyCall = proxy.CloseTask(preparedness);

            if (proxyCall.Item2 != "")
            {
                el.Error(proxyCall.Item2);
                ErrorHandling e = ErrorHandling.Negative;
                return(proxyCall.Item2, e);
            }
            else
            {
                ErrorHandling e = ErrorHandling.Positive;
                return("Beredskab fjernet", e);
            }
        }
        public (string, ErrorHandling) CreatePreparedness(Preparedness preparedness)
        {
            var proxy     = new ProxyController(states);
            var proxyCall = proxy.UpdateTask(preparedness);

            if (proxyCall.Item2 != "")
            {
                //Write error message to file
                el.Error(proxyCall.Item2);
                ErrorHandling e = ErrorHandling.Negative;
                return(proxyCall.Item2, e);
            }
            else
            {
                ErrorHandling e = ErrorHandling.Positive;
                return("Beredskab tilføjet", e);
            }
        }
示例#7
0
        public Preparedness CreatePreparedness([FromBody] Preparedness preparedness)
        {
            preparedness.CreationTime = DateTimeOffset.UtcNow;

            var existingVehicle = _context.Vehicles.Include(s => s.Status).FirstOrDefault(x => x.ID == preparedness.Vehicle.ID);

            var existingStatus = _context.Status.FirstOrDefault(x => x.ID == preparedness.Vehicle.Status.ID);

            existingVehicle.Status = existingStatus;

            preparedness.Incident.Journals = null;

            preparedness.Status = "Aktiv";

            preparedness.EmergencyCode = _context.EmergencyCodes.FirstOrDefault(x => x.ID == preparedness.EmergencyCode.ID);

            _context.Preparednesses.Attach(preparedness);

            _context.SaveChanges();

            var logger = new Logger();

            logger.Preparedness = preparedness;
            logger.Time         = DateTimeOffset.UtcNow;


            var createdPreparedness = iParser.CreatePreparedness(preparedness);

            logger.LogMessage = createdPreparedness.Item1;
            logger.Success    = createdPreparedness.Item2;
            logger.Incident   = preparedness.Incident;
            _context.Loggers.Add(logger);

            _context.SaveChanges();

            preparedness.EmergencyCode = null;

            preparedness.Loggers  = null;
            preparedness.Incident = null;
            preparedness.Vehicle  = null;
            _messageHubContext.Clients.All.InvokeAsync("PreparednessAdded", preparedness);
            return(preparedness);
        }
示例#8
0
        public (bool, string) CloseTask(Preparedness preparedness)
        {
            closeTask closeTask = new closeTask
            {
                Message            = GetMessage(preparedness.Incident),
                TaskIdentification = GetTaskType(preparedness).Identification
            };

            ppjInterfaceClient client = GetClient();

            var securityHeader = new SecurityHeaderType();
            var header         = new Header();
            var response       = client.closeTask(ref securityHeader, ref header, closeTask);

            if (response.Error != null)
            {
                return(response.Type == ControlType.POSITIVE, response.Error.Description);
            }
            else
            {
                return(response.Type == ControlType.POSITIVE, "");
            }
        }
示例#9
0
        public TaskType GetTaskType(Preparedness preparedness)
        {
            TaskType taskType = new TaskType();

            taskType.Identification = new IdentificationType
            {
                Identification       = preparedness.ID.ToString(),
                IdentificationSchema = "UUID"
            };

            taskType.PriorityToIncident = preparedness.EmergencyCode.Code;
            taskType.Vehicle            = new PPJReference.VehicleType
            {
                Identification = new IdentificationType
                {
                    Identification       = preparedness.Vehicle.Name,
                    IdentificationSchema = "AmPHIEmsUnitID_V1"
                },
                ResponsibleUnit = GetIncidentType(preparedness.Incident).ResponsibleUnit,
                Operator        = "Falck",
                Type            = new VehicleTypeValues(),
                Name            = "Ambulance",
                Telephone       = "8888"
            };
            //taskType.Staff = new StaffType
            //{
            //    Identification = new IdentificationType
            //    {
            //        Identification = "staff1",
            //        IdentificationSchema = "sdss"
            //    },
            //    Name = "staffNavn",
            //    Role = "Rolle"
            //};
            return(taskType);
        }
示例#10
0
        //Convert controlrum status codes to enum
        public TaskStatusValues GetConvertedEnums(Preparedness preparedness)
        {
            var convertedStatusCodesToEnums = Enum.Parse(typeof(TaskStatusValues), preparedness.Vehicle.Status.Code, true);

            return((TaskStatusValues)convertedStatusCodesToEnums);
        }