{"action":"created","issue":{"url":"https://api.github.com/repos/ove/ove-services/issues/7","repository_url":"https://api.github.com/repos/ove/ove-services","labels_url":"https://api.github.com/repos/ove/ove-services/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/ove/ove-services/issues/7/comments","events_url":"https://api.github.com/repos/ove/ove-services/issues/7/events","html_url":"https://github.com/ove/ove-services/pull/7","id":368716677,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIxODI5NzIz","number":7,"title":"Asset Manager Service ","user":{"login":"davidbirchwork","id":11289564,"node_id":"MDQ6VXNlcjExMjg5NTY0","avatar_url":"https://avatars3.githubusercontent.com/u/11289564?v=4","gravatar_id":"","url":"https://api.github.com/users/davidbirchwork","html_url":"https://github.com/davidbirchwork","followers_url":"https://api.github.com/users/davidbirchwork/followers","following_url":"https://api.github.com/users/davidbirchwork/following{/other_user}","gists_url":"https://api.github.com/users/davidbirchwork/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbirchwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbirchwork/subscriptions","organizations_url":"https://api.github.com/users/davidbirchwork/orgs","repos_url":"https://api.github.com/users/davidbirchwork/repos","events_url":"https://api.github.com/users/davidbirchwork/events{/privacy}","received_events_url":"https://api.github.com/users/davidbirchwork/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2018-10-10T15:14:24Z","updated_at":"2018-10-11T09:47:17Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/ove/ove-services/pulls/7","html_url":"https://github.com/ove/ove-services/pull/7","diff_url":"https://github.com/ove/ove-services/pull/7.diff","patch_url":"https://github.com/ove/ove-services/pull/7.patch"},"body":"Asset Manager Service for OVE"},"comment":{"url":"https://api.github.com/repos/ove/ove-services/issues/comments/428892361","html_url":"https://github.com/ove/ove-services/pull/7#issuecomment-428892361","issue_url":"https://api.github.com/repos/ove/ove-services/issues/7","id":428892361,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODg5MjM2MQ==","user":{"login":"senakafdo","id":3415383,"node_id":"MDQ6VXNlcjM0MTUzODM=","avatar_url":"https://avatars3.githubusercontent.com/u/3415383?v=4","gravatar_id":"","url":"https://api.github.com/users/senakafdo","html_url":"https://github.com/senakafdo","followers_url":"https://api.github.com/users/senakafdo/followers","following_url":"https://api.github.com/users/senakafdo/following{/other_user}","gists_url":"https://api.github.com/users/senakafdo/gists{/gist_id}","starred_url":"https://api.github.com/users/senakafdo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/senakafdo/subscriptions","organizations_url":"https://api.github.com/users/senakafdo/orgs","repos_url":"https://api.github.com/users/senakafdo/repos","events_url":"https://api.github.com/users/senakafdo/events{/privacy}","received_events_url":"https://api.github.com/users/senakafdo/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T09:47:17Z","updated_at":"2018-10-11T09:47:17Z","author_association":"CONTRIBUTOR","body":"> @senakafdo second check is required in the case an exception is thrown and ModelState.AddModelError(\"StorageLocation\", \"Failed to upload file\"); is triggered. I think its pretty obvious that adding a model error makes the state invalid and thus requires the 2nd check. I can document this is you think necessary\r\n\r\nAlright. \r\n\r\nI think this can be avoided altogether. So, `ModelState.IsValid` is false if an error is thrown right? If so, the following should do what you want isn't it?\r\n\r\n```csharp\r\npublic async Task<ActionResult<OVEAssetModel>> Create(\r\n    [Bind(\"Project,Name,Description,Service,AssetMeta\")] OVEAssetModel oveAssetModel,\r\n    [FromForm] IFormFile upload) {\r\n\r\n    // check if we have a file\r\n    if (upload == null || upload.Length <= 0) {\r\n        _logger.LogError(\"failed to upload a file\");\r\n        ModelState.AddModelError(\"Filename\", \"Failed to upload file\");\r\n    } else if (!_serviceRepository.ValidateServiceChoice(oveAssetModel.Service, upload)) {\r\n        ModelState.AddModelError(\"Service\", \"Service does not support File Type\");\r\n    } else {\r\n        // then try and save it\r\n        try {\r\n            await _fileOperations.SaveFile(oveAssetModel, upload);\r\n\r\n            _logger.LogInformation(\"received and uploaded a file :) \" + oveAssetModel.StorageLocation);\r\n        }\r\n        catch (Exception e) {\r\n            _logger.LogError(e, \"failed to upload a file and write it to \" + oveAssetModel.StorageLocation);\r\n            ModelState.AddModelError(\"StorageLocation\", \"Failed to upload file\");\r\n        }\r\n    }\r\n\r\n    if (ModelState.IsValid) {\r\n        _context.Add(oveAssetModel);\r\n        await _context.SaveChangesAsync();\r\n        return RedirectToAction(nameof(Index));\r\n    }\r\n\r\n    return this.FormatOrView(oveAssetModel);\r\n}\r\n```"}}
{"actor":{"display_login":"senakafdo"}}