public string PostMethod() { if (!_request.CustomHeader.ContainsKey("Content-Type") || _request.CustomHeader["Content-Type"] != "application/json") { return("POST ERR - Request not in JSON Format"); } else if (string.IsNullOrWhiteSpace(_card.Name) || string.IsNullOrWhiteSpace(_card.Id) || string.IsNullOrWhiteSpace(_card.CardType) || _card.Damage <= 0) { return("POST ERR - No valid Card"); } else if (_card.CardType.ToLower() != "dragon" && _card.CardType.ToLower() != "elve" && _card.CardType.ToLower() != "goblin" && _card.CardType.ToLower() != "knight" && _card.CardType.ToLower() != "kraken" && _card.CardType.ToLower() != "orc" && _card.CardType.ToLower() != "wizard" && _card.CardType.ToLower() != "firespell" && _card.CardType.ToLower() != "normalspell" && _card.CardType.ToLower() != "waterspell") { return("POST ERR - Invalid card type"); } string usertoken; if (!_request.CustomHeader.TryGetValue("Authorization", out usertoken)) { return("POST ERR - No authorization header"); } usertoken = usertoken.Substring(6, usertoken.Length - 6); if (usertoken != "admin-mtcgToken") { return("POST ERR - No admin rights"); } return(_cardController.CreateCard(_card)); }
public ResponseContext Post(Dictionary <string, object> param) { RequestContext request = (RequestContext)param["request"]; if (!request.Headers.ContainsKey("Content-Type") || request.Headers["Content-Type"] != "application/json") { return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.UnsupportedMediaType, ""))); } CardDto cardDto = JsonSerializer.Deserialize <CardDto>(request.Payload); Card card; if (cardDto == null || string.IsNullOrWhiteSpace(cardDto.CardType) || string.IsNullOrWhiteSpace(cardDto.Name) || (card = cardDto.ToObject()) == null) { return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.BadRequest, "Either the card type or the name is empty or the given type or the element does not exist"))); } return(new ResponseContext(request, _cardController.CreateCard(card))); }