public virtual IActionResult Register([FromBody] FriendFinderRegister reg, [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 != authToken) { return(BadRequest("Not allowed")); } long newThingID = 0; string errorMessage = ""; try { DatabaseInterface.DBFriendFinder dBF = new DatabaseInterface.DBFriendFinder(); if (!dBF.Register(reg.WristbandId, reg.NickName)) { 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}"; var example = exampleJson != null ? JsonConvert.DeserializeObject <GeneralPostResponse>(exampleJson) : default(GeneralPostResponse); //TODO: Change the data returned return(new ObjectResult(example)); }
public virtual IActionResult TranslateNick([FromQuery][Required] string wristbandId, [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 != authToken) { return(BadRequest("Not allowed")); } long newThingID = 0; string errorMessage = ""; string friend = ""; try { DatabaseInterface.DBFriendFinder dBF = new DatabaseInterface.DBFriendFinder(); if (!dBF.TranslateNick(wristbandId, ref friend)) { 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)); return(new ObjectResult(friend)); }