public virtual IActionResult ZoneZoneIdDelete([FromRoute][Required] string zoneId, [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 newZoneID = 0; string errorMessage = ""; try { DatabaseInterface.DBZone dBZone = new DatabaseInterface.DBZone(); if (!dBZone.DeleteZone(zoneId, ref errorMessage)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } catch (Exception e) { return(BadRequest("Internal Server Error:" + e.Message)); } string exampleJson = null; exampleJson = "{\n \"success\" : true,\n \"description\" : \" Zone " + zoneId.ToString() + "deleted \"\n}"; var example = exampleJson != null ? JsonConvert.DeserializeObject <GeneralResponse>(exampleJson) : default(GeneralResponse); //TODO: Change the data returned return(new ObjectResult(example)); }
public virtual IActionResult ZoneZoneIdGet([FromRoute][Required] string zoneId, [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 newZoneID = 0; string errorMessage = ""; Zone result = null; try { DatabaseInterface.DBZone dBZone = new DatabaseInterface.DBZone(); if (!dBZone.FindZoneFromId(zoneId, ref errorMessage, ref result)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } catch (Exception e) { return(BadRequest("Internal Server Error:" + e.Message)); } string exampleJson = null; return(new ObjectResult(result)); }
public virtual IActionResult ZonePost([FromBody] Zone zoneName, [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 newZoneID = 0; string errorMessage = ""; try { DatabaseInterface.DBZone dBZone = new DatabaseInterface.DBZone(); string boundPolygon = "["; string comma = ""; foreach (List <decimal?> x in zoneName.BoundingPolygon) { boundPolygon += comma + "[" + x[0].ToString().ToString().Replace(",", ".") + "," + x[1].ToString().Replace(",", ".") + "]"; boundPolygon += "]"; comma = ","; } if (!dBZone.AddZone(zoneName.Name, zoneName.Type, zoneName.Description, zoneName.Metadata, boundPolygon, zoneName.Capacity, ref errorMessage, ref newZoneID)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } 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\" : " + newZoneID.ToString() + "\n}"; var example = exampleJson != null ? JsonConvert.DeserializeObject <GeneralPostResponse>(exampleJson) : default(GeneralPostResponse); //TODO: Change the data returned return(new ObjectResult(example)); }
public virtual IActionResult ZonesGet([FromQuery] string zoneType, [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)); } } bool publicAccess = true; string pubToken = "8f7d9dd9-6bbc-460c-a76c-4be72a9ea39e"; if (Authorization != settings.testToken && Authorization != pubToken) { return(BadRequest("Not allowed")); } else { if (Authorization == settings.testToken) { publicAccess = false; } } long newZoneID = 0; string errorMessage = ""; List <Zone> results = new List <Zone>(); try { DatabaseInterface.DBZone dBZone = new DatabaseInterface.DBZone(); if (zoneType != null) { if (publicAccess) { if (!dBZone.ListPublicZones(zoneType, publicAccess, ref errorMessage, ref results)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } else { if (!dBZone.ListZones(zoneType, publicAccess, ref errorMessage, ref results)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } } else { if (publicAccess) { if (!dBZone.ListAllPublicZones(publicAccess, ref errorMessage, ref results)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } else { if (!dBZone.ListAllZones(publicAccess, ref errorMessage, ref results)) { return(BadRequest("Internal Server Error:" + errorMessage)); } } //if (!dBZone.ListAllZones(publicAccess, ref errorMessage, ref results)) // return BadRequest("Internal Server Error:" + errorMessage); } } catch (Exception e) { return(BadRequest("Internal Server Error:" + e.Message)); } string exampleJson = null; return(new ObjectResult(results)); }