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(_package.PackageId) || _package.CardIds.Count == 0) { return("POST ERR - No valid Package"); } 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(_packageController.CreatePackage(_package)); }
public virtual 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, ""))); } CardCollectionDto packageDto = JsonSerializer.Deserialize <CardCollectionDto>(request.Payload); packageDto.CardCollectionType = typeof(Package); Package package; if (packageDto == null || packageDto.CardGuids.Count != 5 || (package = packageDto.ToObject() as Package) == null) { return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.BadRequest, "Either the package does not contain 5 cards or some cards do not exist"))); } return(new ResponseContext(request, _packageController.CreatePackage(package))); }