コード例 #1
0
        public IActionResult UpdateIncident([FromRoute] int id, [FromBody] UpdateIncidentRequest requestBody)
        {
            var incident = _incidentsManager.GetIncident(id);

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

            if (incident.State == IncidentState.Resolved)
            {
                return(BadRequest(new
                {
                    message = "You may not edit a resolved incident."
                }));
            }

            incident.Title        = requestBody?.Title ?? incident.Title;;
            incident.CausedStatus = requestBody?.CausedStatus ?? incident.CausedStatus;
            _incidentsManager.UpdateIncident(incident);

            var service = _servicesManager.GetService(incident.ServiceId);

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

            return(Ok(incident));
        }
コード例 #2
0
        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));
        }