public IActionResult CreateIncident([FromRoute] int id, [FromBody] CreateIncidentRequest requestBody)
        {
            var service = _servicesManager.GetService(id);

            if (service == null)
            {
                return(NotFound(new
                {
                    message = "A service with this ID does not exist."
                }));
            }

            var incident = requestBody.ToIncident();

            incident.ServiceId = service.Id;
            incident           = _incidentsManager.CreateIncident(incident);

            var incidentUpdate = requestBody.ToIncidentUpdate();

            incidentUpdate.IncidentId = incident.Id;
            incidentUpdate            = _incidentUpdatesManager.CreateIncidentUpdate(incidentUpdate);

            incident.MostRecentUpdateId = incidentUpdate.Id;
            _incidentsManager.UpdateIncident(incident);

            if (service.Status < incident.CausedStatus)
            {
                service.Status = incident.CausedStatus;
                _servicesManager.Update(service);
            }

            return(Ok(incident));
        }
        public IActionResult AddUpdate([FromRoute] int id, [FromBody] CreateUpdateRequest requestBody)
        {
            var incident = _incidentsManager.GetIncident(id);

            if (incident == null)
            {
                return(NotFound(new
                {
                    message = "An incident with this ID does not exist."
                }));
            }

            var update = requestBody.ToIncidentUpdate();

            if (incident.State == IncidentState.Resolved)
            {
                return(BadRequest(new
                {
                    message = "This incident has already been marked as resolved."
                }));
            }

            update.IncidentId = incident.Id;
            update            = _incidentUpdatesManager.CreateIncidentUpdate(update);

            incident.State = update.State;
            incident.MostRecentUpdateId = update.Id;
            if (incident.State == IncidentState.Resolved)
            {
                incident.ResolvedAt = DateTime.UtcNow;

                var service             = _servicesManager.GetService(incident.ServiceId);
                var incidents           = _incidentsManager.GetIncidents(incident.ServiceId);
                var unresolvedIncidents = incidents.Where(x => x.ResolvedAt == null && x.Id != incident.Id);

                if (!unresolvedIncidents.Any())
                {
                    service.Status = ServiceStatus.Normal;
                    _servicesManager.Update(service);
                }
                else
                {
                    var nextStatus = unresolvedIncidents
                                     .OrderByDescending(x => x.CausedStatus)
                                     .First()
                                     .CausedStatus;
                    service.Status = nextStatus;
                    _servicesManager.Update(service);
                }
            }

            _incidentsManager.UpdateIncident(incident);

            return(Ok(_incidentsManager.GetIncident(id)));
        }