Пример #1
0
        public virtual IActionResult IncidentsGet([FromQuery] string type, [FromQuery] string status, [FromQuery] int?take, [FromQuery] int?skip, [FromHeader][Required()] string Authorization)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.SelectMany(x => x.Value.Errors).First();
                if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
                {
                    return(BadRequest(error.ErrorMessage));
                }
                else if (error.Exception?.Message != null)
                {
                    return(BadRequest("Faulty input"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            int defaultTake = 1000;
            int defaultSkip = 0;

            if (take == null)
            {
                take = defaultTake;
            }
            if (skip == null)
            {
                skip = defaultSkip;
            }
            if (Authorization != settings.testToken)
            {
                return(BadRequest("Not allowed"));
            }
            long            newZoneID    = 0;
            string          errorMessage = "";
            List <Incident> results      = new List <Incident>();

            try
            {
                DatabaseInterface.DBIncident dBi = new DatabaseInterface.DBIncident();
                if (!dBi.ListIncidents(type, status, (int)take, (int)skip, ref errorMessage, ref results))
                {
                    return(BadRequest("Internal Server Error:" + errorMessage));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error:" + e.Message));
            }


            return(new ObjectResult(results));
        }
Пример #2
0
        public virtual IActionResult IncidentIncidentIdGet([FromRoute][Required] string incidentId, [FromHeader][Required()] string Authorization)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.SelectMany(x => x.Value.Errors).First();
                if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
                {
                    return(BadRequest(error.ErrorMessage));
                }
                else if (error.Exception?.Message != null)
                {
                    return(BadRequest("Faulty input"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            if (Authorization != settings.testToken)
            {
                return(BadRequest("Not allowed"));
            }
            string   errorMessage  = "";
            Incident foundIncident = null;

            try
            {
                DatabaseInterface.DBIncident dBi = new DatabaseInterface.DBIncident();

                if (!dBi.GetIncident(int.Parse(incidentId), ref errorMessage, ref foundIncident))
                {
                    return(BadRequest("Internal Server Error:" + errorMessage));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error:" + e.Message));
            }



            return(new ObjectResult(foundIncident));
        }
Пример #3
0
        public virtual IActionResult IncidentPost([FromBody] Incident incidentType, [FromHeader][Required()] string Authorization)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.SelectMany(x => x.Value.Errors).First();
                if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
                {
                    return(BadRequest(error.ErrorMessage));
                }
                else if (error.Exception?.Message != null)
                {
                    return(BadRequest("Faulty input"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            if (Authorization != settings.testToken)
            {
                return(BadRequest("Not allowed"));
            }
            long   newThingID   = 0;
            string errorMessage = "";

            try
            {
                DatabaseInterface.DBIncident dBi = new DatabaseInterface.DBIncident();

                if (!dBi.AddIncident(incidentType.Description, incidentType.Type, incidentType.Position, (int)incidentType.Prio, incidentType.Status, (double)incidentType.Probability, incidentType.Interventionplan, (DateTime)incidentType.Incidenttime, incidentType.Wbid, incidentType.Telephone, incidentType.AdditionalMedia, incidentType.MediaType, incidentType.Area, ref errorMessage, ref newThingID))
                {
                    return(BadRequest("Internal Server Error:" + errorMessage));
                }
                dynamic message = new JObject();
                message.type            = "newincident";
                message.incidentid      = newThingID;
                message.status          = incidentType.Status;
                message.incidenttype    = incidentType.Type;
                message.prio            = incidentType.Prio;
                message.timestamp       = DateTime.Now;
                message.mediatype       = incidentType.MediaType;
                message.additionalmedia = incidentType.AdditionalMedia;
                message.wbid            = incidentType.Wbid;
                string strMessage = message.ToString();
                _hubContext.Clients.All.SendAsync("Incidents", strMessage);
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error:" + e.Message));
            }


            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(GeneralResponse));

            //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(0, default(ErrorResponse));


            string exampleJson = null;

            exampleJson = "{\n  \"success\" : true,\n  \"newid\" : " + newThingID.ToString() + "\n}";

            var example = exampleJson != null
            ? JsonConvert.DeserializeObject <GeneralPostResponse>(exampleJson)
            : default(GeneralPostResponse);

            //TODO: Change the data returned
            return(new ObjectResult(example));
        }